forked from andreacasalino/Easy-Factor-Graph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTest01-Range.cpp
72 lines (62 loc) · 2.53 KB
/
Test01-Range.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
#include <catch2/catch_test_macros.hpp>
#include <catch2/generators/catch_generators.hpp>
#include <EasyFactorGraph/categoric/GroupRange.h>
using namespace EFG;
using namespace EFG::categoric;
#include <algorithm>
#include <list>
TEST_CASE("testing for_each", "[range]") {
VariablePtr A = make_variable(2, "A");
VariablePtr B = make_variable(2, "B");
std::list<std::vector<std::size_t>> expected = {
{0, 0}, {0, 1}, {1, 0}, {1, 1}};
std::list<std::vector<std::size_t>> got;
std::for_each(GroupRange{{A, B}}, RANGE_END, [&got](const Combination &comb) {
got.emplace_back(comb.data());
});
CHECK(got == expected);
}
namespace {
std::list<std::vector<std::size_t>>
all_combinations_in_range(GroupRange &range) {
std::list<std::vector<std::size_t>> got;
for_each_combination(range, [&got](const Combination &comb) {
got.emplace_back(comb.data());
});
return got;
}
} // namespace
TEST_CASE("testing for_each_combination", "[range]") {
SECTION("small binary group") {
GroupRange rangeAB({make_variable(2, "A"), make_variable(2, "B")});
CHECK(all_combinations_in_range(rangeAB) ==
std::list<std::vector<std::size_t>>{{0, 0}, {0, 1}, {1, 0}, {1, 1}});
}
SECTION("big binary group") {
GroupRange rangeAB({make_variable(3, "A"), make_variable(4, "B")});
CHECK(all_combinations_in_range(rangeAB) ==
std::list<std::vector<std::size_t>>{{0, 0},
{0, 1},
{0, 2},
{0, 3},
{1, 0},
{1, 1},
{1, 2},
{1, 3},
{2, 0},
{2, 1},
{2, 2},
{2, 3}});
}
SECTION("ternary group") {
GroupRange rangeAB(
{make_variable(3, "A"), make_variable(4, "B"), make_variable(2, "C")});
CHECK(all_combinations_in_range(rangeAB) ==
std::list<std::vector<std::size_t>>{
{0, 0, 0}, {0, 0, 1}, {0, 1, 0}, {0, 1, 1}, {0, 2, 0},
{0, 2, 1}, {0, 3, 0}, {0, 3, 1}, {1, 0, 0}, {1, 0, 1},
{1, 1, 0}, {1, 1, 1}, {1, 2, 0}, {1, 2, 1}, {1, 3, 0},
{1, 3, 1}, {2, 0, 0}, {2, 0, 1}, {2, 1, 0}, {2, 1, 1},
{2, 2, 0}, {2, 2, 1}, {2, 3, 0}, {2, 3, 1}});
}
}