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

algos_tests.cpp « search_tests « search - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 4c7d33afceb1b28d5b52709f3dba4b6739bac359 (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
#include "testing/testing.hpp"

#include "search/algos.hpp"

#include <algorithm>
#include <iterator>
#include <vector>

using namespace std;

namespace
{
struct CompWithEqual
{
  bool Less(int i1, int i2) const { return i1 <= i2; }
  bool Greater(int i1, int i2) const { return i1 >= i2; }
};

void TestLongestSequence(int in[], size_t inSz, int eta[])
{
  vector<int> res;
  search::LongestSubsequence(vector<int>(in, in + inSz), back_inserter(res), CompWithEqual());
  reverse(res.begin(), res.end());
  TEST(equal(res.begin(), res.end(), eta), (res));
}
}  // namespace

UNIT_TEST(LS_Smoke)
{
  {
    int arr[] = { 1 };
    TestLongestSequence(arr, ARRAY_SIZE(arr), arr);
  }

  {
    int arr[] = { 1, 2 };
    TestLongestSequence(arr, ARRAY_SIZE(arr), arr);
  }

  {
    int arr[] = { 2, 1 };
    TestLongestSequence(arr, ARRAY_SIZE(arr), arr);
  }

  {
    int arr[] = { 1, 9, 2, 3, 8, 0, 7, -1, 7, -2, 7 };
    int res[] = { 1, 2, 3, 7, 7, 7 };
    TestLongestSequence(arr, ARRAY_SIZE(arr), res);
  }
}