-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathtest_bencode_type.cpp
More file actions
76 lines (62 loc) · 1.91 KB
/
Copy pathtest_bencode_type.cpp
File metadata and controls
76 lines (62 loc) · 1.91 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
73
74
75
76
//
// Created by fbdtemme on 03/06/19.
//
#include <catch2/catch_all.hpp>
#include <sstream>
#include <bencode/detail/bencode_type.hpp>
//#include "../bencode/operators.hpp"
using namespace Catch;
using namespace Catch::Generators;
using bencode::bencode_type;
TEST_CASE("test string conversion", "[type]")
{
auto [input, expected] = GENERATE(table<bencode::bencode_type, std::string>({
{bencode_type::uninitialized, "uninitialized"},
{bencode_type::integer, "integer"},
{bencode_type::string, "string"},
{bencode_type::list, "list"},
{bencode_type::dict, "dict"}
}));
SECTION("to_string") {
CHECK(bencode::to_string(input) == expected);
}
SECTION("operator<<") {
std::stringstream s {};
s << input;
CHECK(s.str() == expected);
}
}
TEST_CASE("check comparison operators", "[type]")
{
static std::array types = {
bencode_type::uninitialized,
bencode_type::integer,
bencode_type::string,
bencode_type::list, bencode_type::dict
};
auto i = GENERATE(range(0, 4));
int j = 0;
for (; j < i; ++j) {
CHECK(types[j] != types[i]);
CHECK_FALSE(types[j] == types[i]);
CHECK(types[j] < types[i]);
CHECK(types[j] <= types[i]);
CHECK_FALSE(types[j] >= types[i]);
CHECK_FALSE(types[j] > types[i]);
}
CHECK_FALSE(types[j] != types[i]);
CHECK(types[j] == types[i]);
CHECK_FALSE(types[j] < types[i]);
CHECK(types[j] <= types[i]);
CHECK(types[j] >= types[i]);
CHECK_FALSE(types[j] > types[i]);
j++;
for (; j < std::size(types); ++j) {
CHECK(types[j] != types[i]);
CHECK_FALSE(types[j] == types[i]);
CHECK_FALSE(types[j] < types[i]);
CHECK_FALSE(types[j] <= types[i]);
CHECK(types[j] >= types[i]);
CHECK(types[j] > types[i]);
}
}