-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathAlgorithm.cpp
More file actions
72 lines (64 loc) · 2.09 KB
/
Algorithm.cpp
File metadata and controls
72 lines (64 loc) · 2.09 KB
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
#include "pch.h"
#include <kf/algorithm/Algorithm.h>
#include <kf/USimpleString.h>
#include <kf/stl/vector>
SCENARIO("Algorithm binary_search_it")
{
GIVEN("A sorted vector of USimpleString values")
{
kf::USimpleString first (L"AAA");
kf::USimpleString second(L"BBB");
kf::USimpleString third (L"CCC");
kf::USimpleString last (L"DDD");
kf::USimpleString notInVec(L"FFF");
kf::vector<kf::USimpleString, NonPagedPoolNx> vec;
vec.push_back(first);
vec.push_back(second);
vec.push_back(third);
vec.push_back(last);
WHEN("Searching for existing string")
{
THEN("Returns iterator to the element")
{
auto it = kf::binary_search_it(vec.begin(), vec.end(), second);
REQUIRE(it != vec.end());
REQUIRE(it->equals(second));
}
}
WHEN("Searching for non-existing string")
{
THEN("Returns end iterator")
{
auto it = binary_search_it(vec.begin(), vec.end(), notInVec);
REQUIRE(it == vec.end());
}
}
WHEN("Searching for the first element")
{
THEN("Returns iterator to beginning")
{
auto it = binary_search_it(vec.begin(), vec.end(), first);
REQUIRE(it == vec.begin());
REQUIRE(it->equals(first));
}
}
WHEN("Searching for the last element")
{
THEN("Returns iterator to the end - 1")
{
auto it = binary_search_it(vec.begin(), vec.end(), last);
REQUIRE(it == vec.end() - 1);
REQUIRE(it->equals(last));
}
}
WHEN("Searching in empty vector")
{
THEN("Returns iterator to the end")
{
kf::vector<kf::USimpleString, NonPagedPoolNx> empty;
auto it = binary_search_it(empty.begin(), empty.end(), third);
REQUIRE(it == empty.end());
}
}
}
}