Welcome to mirror list, hosted at ThFree Co, Russian Federation.

classificator_tests.cpp « indexer_tests « indexer - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 0a7e881744f12603880f5cc99b6def144a720f68 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "testing/testing.hpp"

#include "indexer/classificator.hpp"

#include "generator/generator_tests_support/test_with_classificator.hpp"

#include <algorithm>
#include <cstdint>
#include <string>
#include <vector>

using namespace generator::tests_support;
using namespace std;

UNIT_CLASS_TEST(TestWithClassificator, Classificator_GetType)
{
  Classificator const & c = classif();

  uint32_t const type1 = c.GetTypeByPath({"natural", "coastline"});
  TEST_NOT_EQUAL(0, type1, ());
  TEST(c.IsTypeValid(type1), ());
  TEST_EQUAL(type1, c.GetTypeByReadableObjectName("natural-coastline"), ());

  uint32_t const type2 = c.GetTypeByPath({"amenity", "parking", "private"});
  TEST_NOT_EQUAL(0, type2, ());
  TEST(c.IsTypeValid(type2), ());
  TEST_EQUAL(type2, c.GetTypeByReadableObjectName("amenity-parking-private"), ());

  TEST_EQUAL(0, c.GetTypeByPathSafe({"nonexisting", "type"}), ());
  TEST_EQUAL(0, c.GetTypeByReadableObjectName("nonexisting-type"), ());
  TEST(!c.IsTypeValid(0), ());
}

UNIT_CLASS_TEST(TestWithClassificator, Classificator_CoastlineType)
{
  Classificator const & c = classif();

  uint32_t const type = c.GetTypeByPath({"natural", "coastline"});
  TEST(c.IsTypeValid(type), ());
  TEST_EQUAL(type, c.GetCoastType(), ());
}

UNIT_CLASS_TEST(TestWithClassificator, Classificator_GetIndex)
{
  Classificator const & c = classif();

  uint32_t const type = c.GetTypeByPath({"railway", "station", "subway"});
  uint32_t const index = c.GetIndexForType(type);
  TEST(c.IsTypeValid(type), ());
  TEST_EQUAL(type, c.GetTypeForIndex(index), ());
}

UNIT_CLASS_TEST(TestWithClassificator, Classificator_Subtree)
{
  Classificator const & c = classif();

  uint32_t const cityType = c.GetTypeByPath({"place", "city"});

  vector<vector<string>> const expectedPaths = {
      {"place", "city"},
      {"place", "city", "capital"},
      {"place", "city", "capital", "2"},
      {"place", "city", "capital", "3"},
      {"place", "city", "capital", "4"},
      {"place", "city", "capital", "5"},
      {"place", "city", "capital", "6"},
      {"place", "city", "capital", "7"},
      {"place", "city", "capital", "8"},
      {"place", "city", "capital", "9"},
      {"place", "city", "capital", "10"},
      {"place", "city", "capital", "11"},
  };

  vector<uint32_t> expectedTypes;
  for (auto const & path : expectedPaths)
    expectedTypes.push_back(classif().GetTypeByPath(path));
  sort(expectedTypes.begin(), expectedTypes.end());

  vector<uint32_t> subtreeTypes;
  c.ForEachInSubtree([&subtreeTypes](uint32_t type) { subtreeTypes.push_back(type); }, cityType);
  sort(subtreeTypes.begin(), subtreeTypes.end());

  TEST_EQUAL(expectedTypes, subtreeTypes, ());
}