Skip to content

Commit bf56e1b

Browse files
KellesiVlada KanivetsSergiusTheBest
authored
KF-26 add tests for Algorithm (#56)
* add tests for Algorithm * refactoring * refactoring * refactoring --------- Co-authored-by: Vlada Kanivets <vlada.kanivets@apriorit.com> Co-authored-by: Sergey Podobry <sergius@apriorit.com>
1 parent 36954ad commit bf56e1b

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed
File renamed without changes.

test/AlgorithmTest.cpp

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#include "pch.h"
2+
#include <kf/algorithm/Algorithm.h>
3+
4+
SCENARIO("Algorithm kf::binary_search_it")
5+
{
6+
GIVEN("A sorted array of int values")
7+
{
8+
constexpr std::array kArr = { 111, 222, 333, 444 };
9+
10+
WHEN("Searching for existing value")
11+
{
12+
THEN("Returns iterator to the element")
13+
{
14+
auto it = kf::binary_search_it(kArr.begin(), kArr.end(), kArr[1]);
15+
REQUIRE(it != kArr.end());
16+
REQUIRE(*it == kArr[1]);
17+
}
18+
}
19+
20+
WHEN("Searching for non-existing value")
21+
{
22+
constexpr int kNotInArray = 555;
23+
24+
THEN("Returns end iterator")
25+
{
26+
auto it = kf::binary_search_it(kArr.begin(), kArr.end(), kNotInArray);
27+
REQUIRE(it == kArr.end());
28+
}
29+
}
30+
31+
WHEN("Searching for the first element")
32+
{
33+
THEN("Returns iterator to beginning")
34+
{
35+
auto it = kf::binary_search_it(kArr.begin(), kArr.end(), kArr[0]);
36+
REQUIRE(it == kArr.begin());
37+
REQUIRE(*it == kArr[0]);
38+
}
39+
}
40+
41+
WHEN("Searching for the last element")
42+
{
43+
THEN("Returns iterator to the end - 1")
44+
{
45+
auto it = kf::binary_search_it(kArr.begin(), kArr.end(), kArr.back());
46+
REQUIRE(it == kArr.end() - 1);
47+
REQUIRE(*it == kArr.back());
48+
}
49+
}
50+
51+
WHEN("Searching in empty vector")
52+
{
53+
THEN("Returns iterator to the end")
54+
{
55+
constexpr std::array<int, 0> kEmpty;
56+
auto it = kf::binary_search_it(kEmpty.begin(), kEmpty.end(), kArr[2]);
57+
REQUIRE(it == kEmpty.end());
58+
}
59+
}
60+
}
61+
}

test/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ wdk_add_driver(kf-test WINVER NTDDI_WIN10 STL
5555
VariableSizeStructTest.cpp
5656
ScopeFailureTest.cpp
5757
Base64Test.cpp
58+
AlgorithmTest.cpp
5859
AutoSpinLockTest.cpp
5960
EResourceSharedLockTest.cpp
6061
RecursiveAutoSpinLockTest.cpp

0 commit comments

Comments
 (0)