diff --git a/tests/vault/gear/test-chain-load-test.cpp b/tests/vault/gear/test-chain-load-test.cpp index 12a05af8c..7a6722c41 100644 --- a/tests/vault/gear/test-chain-load-test.cpp +++ b/tests/vault/gear/test-chain-load-test.cpp @@ -62,6 +62,7 @@ namespace test { { simpleUsage(); verify_Node(); + verify_Topology(); witch_gate(); } @@ -78,8 +79,8 @@ namespace test { - /** @test TODO diagnostic blah - * @todo WIP 11/23 🔁 define ⟶ implement + /** @test data structure to represent a computation Node + * @todo WIP 11/23 ✔ define ⟶ ✔ implement */ void verify_Node() @@ -88,6 +89,8 @@ namespace test { Node n0; // Default-created empty Node CHECK (n0.hash == 0); + CHECK (n0.level == 0); + CHECK (n0.repeat == 0); CHECK (n0.pred.size() == 0 ); CHECK (n0.succ.size() == 0 ); CHECK (n0.pred == Node::Tab{0}); @@ -105,17 +108,17 @@ namespace test { CHECK (55 == n2.hash); n0.addPred(n1); // establish bidirectional link between Nodes - CHECK (isSameObject(*n0.pred[0], n1)); - CHECK (isSameObject(*n1.succ[0], n0)); + CHECK (isSameObject (*n0.pred[0], n1)); + CHECK (isSameObject (*n1.succ[0], n0)); CHECK (not n0.pred[1]); CHECK (not n1.succ[1]); CHECK (n2.pred == Node::Tab{0}); CHECK (n2.succ == Node::Tab{0}); n2.addSucc(n0); // works likewise in the other direction - CHECK (isSameObject(*n0.pred[0], n1)); - CHECK (isSameObject(*n0.pred[1], n2)); // next link added into next free slot - CHECK (isSameObject(*n2.succ[0], n0)); + CHECK (isSameObject (*n0.pred[0], n1)); + CHECK (isSameObject (*n0.pred[1], n2)); // next link added into next free slot + CHECK (isSameObject (*n2.succ[0], n0)); CHECK (not n0.pred[2]); CHECK (not n2.succ[1]); @@ -132,20 +135,20 @@ namespace test { CHECK (n00.hash == 17052526497278249714u); CHECK (n0.hash == 6050854883719206282u); - CHECK (isSameObject(*n1.succ[0], n0)); - CHECK (isSameObject(*n1.succ[1], n00)); - CHECK (isSameObject(*n2.succ[0], n0)); - CHECK (isSameObject(*n2.succ[1], n00)); - CHECK (isSameObject(*n00.pred[0], n2)); - CHECK (isSameObject(*n00.pred[1], n1)); - CHECK (isSameObject(*n0.pred[0], n1)); - CHECK (isSameObject(*n0.pred[1], n2)); + CHECK (isSameObject (*n1.succ[0], n0)); + CHECK (isSameObject (*n1.succ[1], n00)); + CHECK (isSameObject (*n2.succ[0], n0)); + CHECK (isSameObject (*n2.succ[1], n00)); + CHECK (isSameObject (*n00.pred[0], n2)); + CHECK (isSameObject (*n00.pred[1], n1)); + CHECK (isSameObject (*n0.pred[0], n1)); + CHECK (isSameObject (*n0.pred[1], n2)); CHECK (n00.hash == 17052526497278249714u); n00.calculate(); // calculation is NOT idempotent (inherently statefull) CHECK (n00.hash == 13151338213516862912u); - CHECK (isnil (n0.succ)); + CHECK (isnil (n0.succ)); // number of predecessors or successors properly accounted for CHECK (isnil (n00.succ)); CHECK (n00.succ.empty()); CHECK (0 == n00.succ.size()); @@ -159,6 +162,22 @@ namespace test { + /** @test TODO build topology by connecting the nodes + * @todo WIP 11/23 🔁 define ⟶ implement + */ + void + verify_Topology() + { + auto graph = TestChainLoad<32>{} + .buildToplolgy(); + + CHECK (31 == graph.topLevel()); + CHECK (0 == graph.getSeed()); + CHECK (0 == graph.getHash()); + } + + + /** @test TODO diagnostic blah * @todo WIP 11/23 🔁 define ⟶ implement */ diff --git a/tests/vault/gear/test-chain-load.hpp b/tests/vault/gear/test-chain-load.hpp index a6836bc1e..2664b35b1 100644 --- a/tests/vault/gear/test-chain-load.hpp +++ b/tests/vault/gear/test-chain-load.hpp @@ -60,10 +60,10 @@ #include //#include -//#include +#include //#include //#include -#include +//#include #include #include @@ -82,7 +82,8 @@ namespace test { // using util::isnil; using util::unConst; // using std::forward; -// using std::move; + using std::swap; + using std::move; using boost::hash_combine; @@ -104,7 +105,7 @@ namespace test { */ template class TestChainLoad - : util::NonCopyable + : util::MoveOnly { public: @@ -121,46 +122,51 @@ namespace test { Iter end() { return after; } friend Iter end(Tab& tab) { return tab.end(); } + void clear() { after = _Arr::begin(); } ///< @warning pointer data in array not cleared + size_t size() const { return unConst(this)->end()-_Arr::begin(); } bool empty() const { return 0 == size(); } Iter - add(Node& n) + add(Node* n) { if (after != _Arr::end()) { - *after = &n; + *after = n; return after++; } NOTREACHED ("excess node linkage"); } + }; size_t hash; - Tab pred; - Tab succ; + size_t level{0}, repeat{0}; + Tab pred{0}, succ{0}; Node(size_t seed =0) : hash{seed} - , pred{0} - , succ{0} { } Node& - addPred (Node& other) + addPred (Node* other) { - pred.add(other); - other.succ.add(*this); - NOTREACHED ("excess node linkage"); + REQUIRE (other); + pred.add (other); + other->succ.add (this); + return *this; } Node& - addSucc (Node& other) + addSucc (Node* other) { - pred.add(other); - other.pred.add(*this); - NOTREACHED ("excess node linkage"); + REQUIRE (other); + succ.add (other); + other->pred.add (this); + return *this; } + Node& addPred(Node& other) { return addPred(&other); } + Node& addSucc(Node& other) { return addSucc(&other); } size_t calculate() @@ -173,6 +179,7 @@ namespace test { }; private: + using NodeTab = typename Node::Tab; using NodeStorage = std::array; std::unique_ptr nodes_; @@ -181,7 +188,45 @@ namespace test { TestChainLoad() : nodes_{new NodeStorage} { } + + + size_t size() const { return nodes_->size(); } + size_t topLevel() const { return nodes_->back().level; } + size_t getSeed() const { return nodes_->front().hash; } + size_t getHash() const { return nodes_->back().hash; } + + + /* ===== topology control ===== */ + + /** + * Use current configuration and seed to (re)build Node connectivity. + */ + TestChainLoad + buildToplolgy() + { + NodeTab a,b, + *curr{&a}, *next{&b}; + Node* node = &nodes_->front(); + size_t level{0}; + curr->add (node++); + ++level; + while (node < &nodes_->back()) + { + Node* n = (*curr)[0]; + next->add (node++); + (*next)[0]->level = level; + (*next)[0]->addPred(n); + swap (next, curr); + next->clear(); + ++level; + } + ENSURE (node == &nodes_->back()); + node->level = level; + node->addPred ((*curr)[0]); + return move(*this); + } + private: }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 720f24816..f35992ef7 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -95829,24 +95829,40 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- - + + + + + + + + + - - + + - - + + - + + + + + + + + + + @@ -95857,12 +95873,21 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + +
@@ -95883,11 +95908,15 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + + + @@ -95901,6 +95930,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + @@ -95952,6 +95985,20 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + +