-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_coldvector.cpp
94 lines (80 loc) · 2.09 KB
/
test_coldvector.cpp
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
85
86
87
88
89
90
91
92
93
#include "cold_vector.h"
#include "test_helpers.h"
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <catch2/generators/catch_generators_adapters.hpp>
#include <catch2/generators/catch_generators_all.hpp>
TEST_CASE("Test ColdVector", "[coldvec]") {
SECTION("Test Construction") {
ColdVector<int> t{};
CHECK(t.size() == 0);
}
SECTION("Check placement and access") {
ColdVector<int, 1> temp{};
temp.emplace_back(1);
temp.emplace_back(2);
temp.emplace_back(3);
temp.emplace_back(4);
temp.emplace_back(5);
CHECK(temp.size() == 5);
CHECK(temp[0] == 1);
CHECK(temp[1] == 2);
CHECK(temp[2] == 3);
CHECK(temp[3] == 4);
CHECK(temp[4] == 5);
}
}
TEST_CASE("Test Iterator", "[coldvec_iter]") {
std::vector<int> a{1,2,3,4,5,6,7,8,9,10};
ColdVector<int> testVec{};
for(auto const& val : a) {
testVec.emplace_back(val);
}
std::size_t idx = 0;
for(auto itr = testVec.begin(); itr < testVec.end(); itr++) {
CHECK(*itr == a[idx++]);
}
}
TEST_CASE("Test Modification and access", "[coldvec_randaccess]") {
std::vector<int> a{1,2,3,4,5,6,7,8,9,10};
ColdVector<int> testVec{};
for(auto const& val : a) {
testVec.emplace_back(val);
}
for(auto& i : testVec) {
i*=2;
}
std::vector<int> b{2,4,6,8,10,12,14,16,18,20};
std::size_t idx = 0;
for(auto const& v: b) {
CHECK(testVec[idx++] == v);
}
}
TEST_CASE("Test Iterator works", "[coldvec_iterator]") {
ColdVector<int> a{1,2,3,4,5,6,7,8,9,10};
CHECK(a.size() == 10);
std::size_t idx = 0;
for(auto const& v : a) {
CHECK(v == a[idx++]);
}
}
TEST_CASE("Test Copy Ctor works as expected", "[coldvec_copyctor]") {
ColdVector<int> a{1,2,3,4,5,6,7,8,9,10};
ColdVector<int> b{a};
CHECK(a.size() == b.size());
for(std::size_t idx = 0; idx < a.size(); idx++) {
CHECK(a[idx] == b[idx]);
}
b[2] = 4;
CHECK(a[2] != b[2]);
}
TEST_CASE("Test Insert operator works as expected", "[coldvec_insert]") {
ColdVector<int> a{1,2,3,4,5};
ColdVector<int> b{6,7,8,9,10};
a.insert(a.end(),b.begin(),b.end());
CHECK(a.size() == 10);
int val = 1;
for(auto const& v : a) {
CHECK(v == val++);
}
}