<commit_before>#include "testing/testing.hpp"

#include "indexer/index.hpp"
#include "indexer/classificator_loader.hpp"

#include "routing/features_road_graph.hpp"
#include "routing/road_graph_router.hpp"
#include "routing/route.hpp"
#include "routing/pedestrian_model.hpp"
#include "routing/router_delegate.hpp"

#include "storage/country_info_getter.hpp"

#include "platform/platform.hpp"

#include "base/logging.hpp"
#include "base/macros.hpp"
#include "base/timer.hpp"

#include "std/set.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"

#include "defines.hpp"

using platform::CountryFile;
using platform::LocalCountryFile;

namespace
{

// Test preconditions:
// Files from the kMapFiles set with '.mwm' extension must be placed in ./omim/data folder

set<string> const kMapFiles =
{
  "UK_England_East Midlands",
  "UK_England_East of England_Essex",
  "UK_England_East of England_Norfolk",
  "UK_England_Greater London",
  "UK_England_North East England",
  "UK_England_North West England_Lancaster",
  "UK_England_North West England_Manchester",
  "UK_England_South East_Brighton",
  "UK_England_South East_Oxford",
  "UK_England_South West England_Bristol",
  "UK_England_South West England_Cornwall",
  "UK_England_West Midlands",
  "UK_England_Yorkshire and the Humber"
};

// Since for test purposes we compare routes lengths to check algorithms consistency,
// we should use simplified pedestrian model, where all available edges have max speed
class SimplifiedPedestrianModel : public routing::PedestrianModel
{
public:
  // IVehicleModel override:
  // PedestrianModel::GetSpeed filters features and returns zero speed if feature
  // is not allowed for pedestrians or otherwise some speed depending of road type (0 <= speed <= maxSpeed).
  // For tests purposes for all allowed features speed must be the same as maxSpeed.
  virtual double GetSpeed(FeatureType const & f) const override
  {
    double const speed = routing::PedestrianModel::GetSpeed(f);
    if (speed <= 0.0)
      return 0.0;
    return routing::PedestrianModel::GetMaxSpeed();
  }
};

class SimplifiedPedestrianModelFactory : public routing::IVehicleModelFactory
{
public:
  SimplifiedPedestrianModelFactory()
    : m_model(make_shared<SimplifiedPedestrianModel>())
  {}

  // IVehicleModelFactory overrides:
  shared_ptr<routing::IVehicleModel> GetVehicleModel() const override { return m_model; }
  shared_ptr<routing::IVehicleModel> GetVehicleModelForCountry(string const & /*country*/) const override { return m_model; }

private:
  shared_ptr<routing::IVehicleModel> const m_model;
};

unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter()
{
  Platform & platform = GetPlatform();
  return storage::CountryInfoReader::CreateCountryInfoReader(platform);
}

unique_ptr<routing::IRouter> CreatePedestrianAStarTestRouter(Index & index, storage::CountryInfoGetter & cig)
{
  auto UKGetter = [&](m2::PointD const & pt) { return cig.GetRegionCountryId(pt); };
  unique_ptr<routing::IVehicleModelFactory> vehicleModelFactory(new SimplifiedPedestrianModelFactory());
  unique_ptr<routing::IRoutingAlgorithm> algorithm(new routing::AStarRoutingAlgorithm());
  unique_ptr<routing::IRouter> router(new routing::RoadGraphRouter(
      "test-astar-pedestrian", index, UKGetter, routing::IRoadGraph::Mode::IgnoreOnewayTag,
      move(vehicleModelFactory), move(algorithm), nullptr));
  return router;
}

unique_ptr<routing::IRouter> CreatePedestrianAStarBidirectionalTestRouter(Index & index, storage::CountryInfoGetter & cig)
{
  auto UKGetter = [&](m2::PointD const & pt) { return cig.GetRegionCountryId(pt); };
  unique_ptr<routing::IVehicleModelFactory> vehicleModelFactory(new SimplifiedPedestrianModelFactory());
  unique_ptr<routing::IRoutingAlgorithm> algorithm(new routing::AStarBidirectionalRoutingAlgorithm());
  unique_ptr<routing::IRouter> router(new routing::RoadGraphRouter(
      "test-astar-bidirectional-pedestrian", index, UKGetter, routing::IRoadGraph::Mode::IgnoreOnewayTag,
      move(vehicleModelFactory), move(algorithm), nullptr));
  return router;
}

m2::PointD GetPointOnEdge(routing::Edge & e, double posAlong)<commit_msg>[routing][tests] Fixing pedestrian_routing_test after fixing an issue on UI crash on long routing planning completion.<commit_after>#include "testing/testing.hpp"

#include "indexer/index.hpp"
#include "indexer/classificator_loader.hpp"

#include "routing/features_road_graph.hpp"
#include "routing/road_graph_router.hpp"
#include "routing/route.hpp"
#include "routing/pedestrian_directions.hpp"
#include "routing/pedestrian_model.hpp"
#include "routing/router_delegate.hpp"

#include "storage/country_info_getter.hpp"

#include "platform/platform.hpp"

#include "base/logging.hpp"
#include "base/macros.hpp"
#include "base/timer.hpp"

#include "std/set.hpp"
#include "std/string.hpp"
#include "std/utility.hpp"
#include "std/vector.hpp"

#include "defines.hpp"

using platform::CountryFile;
using platform::LocalCountryFile;

namespace
{

// Test preconditions:
// Files from the kMapFiles set with '.mwm' extension must be placed in ./omim/data folder

set<string> const kMapFiles =
{
  "UK_England_East Midlands",
  "UK_England_East of England_Essex",
  "UK_England_East of England_Norfolk",
  "UK_England_Greater London",
  "UK_England_North East England",
  "UK_England_North West England_Lancaster",
  "UK_England_North West England_Manchester",
  "UK_England_South East_Brighton",
  "UK_England_South East_Oxford",
  "UK_England_South West England_Bristol",
  "UK_England_South West England_Cornwall",
  "UK_England_West Midlands",
  "UK_England_Yorkshire and the Humber"
};

// Since for test purposes we compare routes lengths to check algorithms consistency,
// we should use simplified pedestrian model, where all available edges have max speed
class SimplifiedPedestrianModel : public routing::PedestrianModel
{
public:
  // IVehicleModel override:
  // PedestrianModel::GetSpeed filters features and returns zero speed if feature
  // is not allowed for pedestrians or otherwise some speed depending of road type (0 <= speed <= maxSpeed).
  // For tests purposes for all allowed features speed must be the same as maxSpeed.
  virtual double GetSpeed(FeatureType const & f) const override
  {
    double const speed = routing::PedestrianModel::GetSpeed(f);
    if (speed <= 0.0)
      return 0.0;
    return routing::PedestrianModel::GetMaxSpeed();
  }
};

class SimplifiedPedestrianModelFactory : public routing::IVehicleModelFactory
{
public:
  SimplifiedPedestrianModelFactory()
    : m_model(make_shared<SimplifiedPedestrianModel>())
  {}

  // IVehicleModelFactory overrides:
  shared_ptr<routing::IVehicleModel> GetVehicleModel() const override { return m_model; }
  shared_ptr<routing::IVehicleModel> GetVehicleModelForCountry(string const & /*country*/) const override { return m_model; }

private:
  shared_ptr<routing::IVehicleModel> const m_model;
};

unique_ptr<storage::CountryInfoGetter> CreateCountryInfoGetter()
{
  Platform & platform = GetPlatform();
  return storage::CountryInfoReader::CreateCountryInfoReader(platform);
}

unique_ptr<routing::IRouter> CreatePedestrianAStarTestRouter(Index & index, storage::CountryInfoGetter & cig)
{
  auto UKGetter = [&](m2::PointD const & pt) { return cig.GetRegionCountryId(pt); };
  unique_ptr<routing::IVehicleModelFactory> vehicleModelFactory(new SimplifiedPedestrianModelFactory());
  unique_ptr<routing::IRoutingAlgorithm> algorithm(new routing::AStarRoutingAlgorithm());
  unique_ptr<routing::IDirectionsEngine> directionsEngine(new routing::PedestrianDirectionsEngine());
  unique_ptr<routing::IRouter> router(new routing::RoadGraphRouter(
      "test-astar-pedestrian", index, UKGetter, routing::IRoadGraph::Mode::IgnoreOnewayTag,
      move(vehicleModelFactory), move(algorithm), move(directionsEngine)));
  return router;
}

unique_ptr<routing::IRouter> CreatePedestrianAStarBidirectionalTestRouter(Index & index, storage::CountryInfoGetter & cig)
{
  auto UKGetter = [&](m2::PointD const & pt) { return cig.GetRegionCountryId(pt); };
  unique_ptr<routing::IVehicleModelFactory> vehicleModelFactory(new SimplifiedPedestrianModelFactory());
  unique_ptr<routing::IRoutingAlgorithm> algorithm(new routing::AStarBidirectionalRoutingAlgorithm());
  unique_ptr<routing::IDirectionsEngine> directionsEngine(new routing::PedestrianDirectionsEngine());
  unique_ptr<routing::IRouter> router(new routing::RoadGraphRouter(
      "test-astar-bidirectional-pedestrian", index, UKGetter, routing::IRoadGraph::Mode::IgnoreOnewayTag,
      move(vehicleModelFactory), move(algorithm), move(directionsEngine)));
  return router;
}

m2::PointD GetPointOnEdge(routing::Edge & e, double posAlong)
{'fraction_non_alphanumeric': 0.10813287514318443, 'fraction_numerical': 0.0018327605956471936, 'mean_word_length': 6.76779359430605, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4622540', 'n_tokens_mistral': 2731, 'n_tokens_neox': 2671, 'n_words': 587}