-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathtest.cpp
77 lines (61 loc) · 1.82 KB
/
test.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
// Catch2 is a unit testing library
// Here we let it create a main() function for us
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include "vector_ex.hpp"
#include "map_ex.hpp"
#include <sstream>
// type alias
using IV = std::vector<int>;
IV IntRange(int n) {
auto ans = IV(n);
for (int i = 0; i < n; ++i)
ans[i] = i;
return ans;
}
TEST_CASE("Vector Even") {
IV const empty;
REQUIRE(empty == GetEven(empty));
auto const zero = IntRange(1);
// Test the testing code!
REQUIRE(zero.size() == 1);
REQUIRE(zero[0] == 0);
REQUIRE(zero == GetEven(zero));
auto const zero_one = IntRange(2);
// Test the testing code!
REQUIRE(zero_one.size() == 2);
REQUIRE(zero_one[0] == 0);
REQUIRE(zero_one[1] == 1);
REQUIRE(zero == GetEven(zero_one));
// edited toddler random numbers
auto const random = IV{8, 127356, 1, 29, 4376, 263478, 1537};
auto const random_even = IV{ 8, 127356, 4376, 263478};
REQUIRE(GetEven(random) == random_even);
}
std::string STR(IV const& v) {
std::stringstream ss;
PrintVectorOfInt(ss, v);
return ss.str();
}
TEST_CASE("Vector Print") {
REQUIRE(STR(IV{}) == "[ ]");
REQUIRE(STR(IntRange(1)) == "[ 0]");
REQUIRE(STR(IntRange(2)) == "[ 0, 1]");
// edited toddler random numbers
REQUIRE(STR(IV{8, 127356, 1, 29, 4376, 263478, 1537}) == "[ 8, 127356, 1, 29, 4376, 263478, 1537]");
}
using Word2Len = std::map<std::string, int>;
TEST_CASE("Map adding") {
Word2Len wlens;
SECTION( "Adding a word works") {
bool did_insert = AddWord(wlens, "test");
REQUIRE(did_insert);
REQUIRE(wlens.size() == 1);
REQUIRE(wlens.find("test") != wlens.end());
// Second time must return false
bool did_insert_second_time = AddWord(wlens, "test");
REQUIRE(!did_insert_second_time);
REQUIRE(wlens.size() == 1);
REQUIRE(wlens.find("test") != wlens.end());
}
}