| 30 | }; |
| 31 | |
| 32 | UNIT_CLASS_TEST(SearchUtilsTest, Utils) |
| 33 | { |
| 34 | string const kCountryName = "FoodLand"; |
| 35 | auto file = platform::LocalCountryFile::MakeForTesting(kCountryName); |
| 36 | |
| 37 | TestPOI cafe(m2::PointD(0.0, 0.0), "cafe", "en"); |
| 38 | cafe.SetTypes({{"amenity", "cafe"}}); |
| 39 | |
| 40 | TestPOI restaurant(m2::PointD(0.0, 0.0), "restaurant", "en"); |
| 41 | restaurant.SetTypes({{"amenity", "restaurant"}}); |
| 42 | |
| 43 | TestPOI bar(m2::PointD(0.0, 0.0), "bar", "en"); |
| 44 | bar.SetTypes({{"amenity", "bar"}}); |
| 45 | |
| 46 | auto id = BuildCountry(kCountryName, [&](TestMwmBuilder & builder) |
| 47 | { |
| 48 | builder.Add(cafe); |
| 49 | builder.Add(restaurant); |
| 50 | builder.Add(bar); |
| 51 | }); |
| 52 | |
| 53 | auto const & categories = GetDefaultCategories(); |
| 54 | auto const typesPost = GetCategoryTypes("Oficina de correos", "es", categories); |
| 55 | auto const typesCafe = GetCategoryTypes("Cafe", "en", categories); |
| 56 | auto const typesRestaurant = GetCategoryTypes("Restaurant", "en", categories); |
| 57 | auto const typesBar = GetCategoryTypes("Bar", "en", categories); |
| 58 | auto const typesFood = GetCategoryTypes("Eat", "en", categories); |
| 59 | |
| 60 | // GetCategoryTypes must return sorted vector of types. |
| 61 | TEST(is_sorted(typesPost.begin(), typesPost.end()), ()); |
| 62 | TEST(is_sorted(typesCafe.begin(), typesCafe.end()), ()); |
| 63 | TEST(is_sorted(typesRestaurant.begin(), typesRestaurant.end()), ()); |
| 64 | TEST(is_sorted(typesBar.begin(), typesBar.end()), ()); |
| 65 | TEST(is_sorted(typesFood.begin(), typesFood.end()), ()); |
| 66 | |
| 67 | for (char const * s : {"post_office", "post_box", "parcel_locker"}) |
| 68 | TEST(binary_search(typesPost.begin(), typesPost.end(), classif().GetTypeByPath({"amenity", s})), (s)); |
| 69 | |
| 70 | // Now "Cafe" and "Restaurant" are synonyms in categories. |
| 71 | TEST_EQUAL(typesCafe, typesRestaurant, ()); |
| 72 | TEST_NOT_EQUAL(typesCafe, typesBar, ()); |
| 73 | |
| 74 | for (auto const t : typesCafe) |
| 75 | TEST(binary_search(typesFood.begin(), typesFood.end(), t), ()); |
| 76 | |
| 77 | for (auto const t : typesBar) |
| 78 | TEST(binary_search(typesFood.begin(), typesFood.end(), t), ()); |
| 79 | |
| 80 | auto const & dataSource = GetDataSource(); |
| 81 | auto const rect = m2::RectD(m2::PointD(-0.5, -0.5), m2::PointD(0.5, 0.5)); |
| 82 | |
| 83 | auto const testTypes = [&](vector<uint32_t> const & types, size_t expectedCount) |
| 84 | { |
| 85 | vector<FeatureID> features; |
| 86 | ForEachOfTypesInRect(dataSource, types, rect, [&features](FeatureID const & f) { features.push_back(f); }); |
| 87 | TEST_EQUAL(features.size(), expectedCount, ()); |
| 88 | }; |
| 89 |
nothing calls this directly
no test coverage detected