-
Notifications
You must be signed in to change notification settings - Fork 166
/
Copy pathalgorithm_test.cc
50 lines (44 loc) · 1.22 KB
/
algorithm_test.cc
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 "test.h"
#include "itensor/detail/algs.h"
using namespace itensor;
using namespace std;
TEST_CASE("binaryFind test")
{
std::vector<int> ints = {{ 1,3,6,7,9,10,12,14 }};
SECTION("const container")
{
const auto& cints = ints;
auto res = detail::binaryFind(cints,3);
CHECK(res);
auto assignable = std::is_assignable<decltype(*res),int>::value;
CHECK(!assignable);
}
SECTION("non-const container")
{
auto res = detail::binaryFind(ints,3);
CHECK(res);
auto assignable = std::is_assignable<decltype(*res),int>::value;
CHECK(assignable);
}
SECTION("Basic Functionality")
{
for(int i = 0; i <= 30; ++i)
{
auto res = detail::binaryFind(ints,i);
//Do linear search for i to check
bool found = false;
for(const auto& el : ints)
if(el == i)
{
found = true;
break;
}
if(found)
{
CHECK(res);
CHECK(i == *res);
}
else CHECK(!res);
}
}
}