Test without external mockup.
Fills a DirectedNodeNetwork< int, CACell> to be able to apply a CA, find seeds and collect the Paths using PathCollectorRecursive:
45 {
46
47 std::array<int, 5> intArray = { { 2, 5, 3, 4, 99} };
48 std::array<int, 5> intArray2 = { { 144, 121, 33, 35, 31415} };
49 std::array<int, 5> intArray3 = { { 1440, 1210, 3, 33, 3141529} };
50 std::vector<int> onTheFlyCreatedInts;
51 onTheFlyCreatedInts.reserve(4);
52
53
55 EXPECT_EQ(0, intNetwork.
size());
56
57
58 for (unsigned int index = 1 ; index < 5; index++) {
59
60 intNetwork.
addNode(intArray.at(index - 1), intArray.at(index - 1));
61 intNetwork.
addNode(intArray.at(index), intArray.at(index));
62
63 intNetwork.
linkNodes(intArray.at(index - 1), intArray.at(index));
64 }
65
66 for (unsigned int index = 1 ; index < 5; index++) {
67 intNetwork.
addNode(intArray2.at(index - 1), intArray2.at(index - 1));
68 intNetwork.
addNode(intArray2.at(index), intArray2.at(index));
69
70 intNetwork.
linkNodes(intArray2.at(index - 1), intArray2.at(index));
71 }
72
73 for (unsigned int index = 1 ; index < 5; index++) {
74 intNetwork.
addNode(intArray3.at(index - 1), intArray3.at(index - 1));
75 intNetwork.
addNode(intArray3.at(index), intArray3.at(index));
76
77 intNetwork.
linkNodes(intArray3.at(index - 1), intArray3.at(index));
78 }
79
80 {
81 int oldOuterInt = 2;
82 onTheFlyCreatedInts.push_back(42);
83 int& newInnerInt = onTheFlyCreatedInts.back();
84 intNetwork.
addNode(newInnerInt, newInnerInt);
85 intNetwork.
linkNodes(newInnerInt, oldOuterInt);
86 }
87
88 {
89 onTheFlyCreatedInts.push_back(23);
90 int& newOuterInt = onTheFlyCreatedInts.back();
91 int& existingInt = intArray.at(1);
92 intNetwork.
addNode(newOuterInt, newOuterInt);
93 intNetwork.
linkNodes(newOuterInt, existingInt);
94 }
95
96 intNetwork.
linkNodes(intArray.at(0), intArray.at(2));
98
99 {
100 onTheFlyCreatedInts.push_back(31);
101 int& newInnerInt = onTheFlyCreatedInts.back();
102 intNetwork.
addNode(newInnerInt, newInnerInt);
104 }
105
107
108 {
109 onTheFlyCreatedInts.push_back(66);
110 int& newOuterInt = onTheFlyCreatedInts.back();
111 intNetwork.
addNode(newOuterInt, newOuterInt);
113 }
114
115 EXPECT_EQ(17, intNetwork.
size());
116
117
118
119
122
123 int nRounds = cellularAutomaton.
apply(intNetwork);
124 unsigned int nSeeds = cellularAutomaton.
findSeeds(intNetwork);
125 EXPECT_EQ(8,
126 nRounds);
127 EXPECT_EQ(13, nSeeds);
128
132 std::vector<DirectedNode<int, CACell>*>,
134
135
137 PathCollectorType pathCollector;
138
139 std::vector< PathCollectorType::Path> paths;
140 pathCollector.findPaths(intNetwork, paths, 100000000);
141
142 std::string out = PathCollectorType::printPaths(paths);
143 B2INFO(out);
144
145
146
147 EXPECT_EQ(13, paths.size());
148 unsigned int longestPath = 0;
149 for (auto& aPath : paths) {
150 if (longestPath < aPath.size()) {
151 longestPath = aPath.size();
152 }
153 }
154
155 EXPECT_EQ(7, longestPath);
156 EXPECT_EQ(nRounds, longestPath +
157 1);
158
159
160 paths.clear();
161 bool test = pathCollector.findPaths(intNetwork, paths, 50, true);
162 EXPECT_EQ(44, paths.size());
163 EXPECT_EQ(true, test);
164
165
166 paths.clear();
167 test = pathCollector.findPaths(intNetwork, paths, 10);
168 EXPECT_EQ(false, test);
169 }
The CellularAutomaton class This class serves as a functor for the algorithm itself.
int apply(ContainerType &aNetworkContainer) override final
actual algorithm of Cellular Automaton, returns number of rounds needed to finish or -1 if CA was abo...
unsigned int findSeeds(ContainerType &aNetworkContainer, bool strictSeeding=false) override final
checks network given for seeds, returns number of seeds found (if strictSeeding is set to true,...
Network of directed nodes of the type EntryType.
bool addInnerToLastOuterNode(NodeID innerNodeID)
to the last outerNode added, another innerNode will be attached
unsigned int size() const
Returns number of nodes to be found in the network.
bool linkNodes(NodeID outerNodeID, NodeID innerNodeID)
takes two entry IDs and weaves them into the network
bool addNode(NodeID nodeID, EntryType &newEntry)
************************* PUBLIC MEMBER FUNCTIONS *************************
bool addOuterToLastInnerNode(NodeID outerNodeID)
to the last innerNode added, another outerNode will be attached
Path finder for generic ContainerType.
validation tool for CA algorithm
simple NodeCompatibilityChecker, which checks for compatible Neighboring states of passed nodes (does...