-
Notifications
You must be signed in to change notification settings - Fork 19
/
test_paths.cpp
100 lines (85 loc) · 2.15 KB
/
test_paths.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
94
95
96
97
98
99
100
#include <paths.hpp>
#include "gtest/gtest.h"
TEST(Paths, basic)
{
Grid G("8x8.map");
Node* v = G.getNode(0);
Node* u = G.getNode(1);
Node* w = G.getNode(2);
// format
Paths paths(2);
paths.insert(0, {v});
ASSERT_EQ(paths.get(0).size(), 1);
ASSERT_TRUE(paths.empty(1));
paths.insert(1, {u, w});
ASSERT_EQ(paths.get(0).size(), 2);
ASSERT_EQ(paths.get(1).size(), 2);
ASSERT_EQ(paths.getMakespan(), 1);
ASSERT_EQ(paths.getSOC(), 1);
ASSERT_EQ(paths.get(0, 0), v);
ASSERT_EQ(paths.get(0, 1), v);
ASSERT_EQ(paths.get(1, 0), u);
ASSERT_EQ(paths.get(1, 1), w);
ASSERT_FALSE(paths.empty(1));
// shrink
paths.insert(1, {u});
ASSERT_EQ(paths.get(0).size(), 1);
ASSERT_EQ(paths.getMakespan(), 0);
ASSERT_EQ(paths.getSOC(), 0);
}
TEST(Paths, add)
{
Grid G("8x8.map");
Node* v = G.getNode(0);
Node* u = G.getNode(1);
Node* w = G.getNode(2);
Node* x = G.getNode(3);
Path path_1_0 = {v, u};
Path path_1_1 = {u, w};
Path path_2_0 = {u, w};
Path path_2_1 = {w, x};
Paths paths1(2);
paths1.insert(0, path_1_0);
paths1.insert(1, path_1_1);
Paths paths2(2);
paths2.insert(0, path_2_0);
paths2.insert(1, path_2_1);
ASSERT_EQ(paths1.getMakespan(), 1);
paths1 += paths2;
ASSERT_EQ(paths1.getMakespan(), 2);
}
TEST(Paths, conflict)
{
Grid G("8x8.map");
Node* v = G.getNode(0);
Node* u = G.getNode(1);
Node* w = G.getNode(2);
Node* x = G.getNode(3);
// no conflict
Paths paths0(2);
paths0.insert(0, {v, u, w});
paths0.insert(1, {u, w, x});
ASSERT_EQ(paths0.countConflict(), 0);
// vertex conflict
Paths paths1(2);
paths1.insert(0, {v, u, u});
paths1.insert(1, {u, u, w});
ASSERT_EQ(paths1.countConflict(), 1);
// swap conflict
Paths paths2(2);
paths2.insert(0, {v, u});
paths2.insert(1, {u, v});
ASSERT_EQ(paths2.countConflict(), 1);
// three agents
Paths paths3(3);
paths3.insert(0, {v, u, w});
paths3.insert(1, {u, v, v});
paths3.insert(2, {w, w, w});
ASSERT_EQ(paths3.countConflict(), 2);
// insert agents
Paths paths4(3);
paths4.insert(0, {v, u, w});
paths4.insert(1, {u, v, v});
paths4.insert(2, {w, w, w});
ASSERT_EQ(paths4.countConflict(2, {w, w, u}), 1);
}