Chain-Load: verify simple linear hash-chain
by default, a linear chain without any forking is generated, and the result hash is computed by hash-chaining from the seed. Verify proper connections and validate computed hash
This commit is contained in:
parent
1f2a635973
commit
960c461bb4
3 changed files with 74 additions and 26 deletions
|
|
@ -163,21 +163,54 @@ namespace test {
|
|||
|
||||
|
||||
|
||||
/** @test TODO build topology by connecting the nodes
|
||||
* @todo WIP 11/23 🔁 define ⟶ implement
|
||||
/** @test build topology by connecting the nodes
|
||||
* - pre-allocate a block with 32 nodes and then
|
||||
* build a topology to connect these, using default rules
|
||||
* - in the default case, nodes are linearly chained
|
||||
* - hash is also computed by chaining with predecessor hash
|
||||
* - hash computations can be reproduced
|
||||
* @todo WIP 11/23 ✔ define ⟶ ✔ implement
|
||||
*/
|
||||
void
|
||||
verify_Topology()
|
||||
{
|
||||
auto graph = TestChainLoad<32>{}
|
||||
.expansionRule([](size_t hash, double){ return Cap{5, hash % 10, 9}; })
|
||||
.buildToplolgy()
|
||||
.printTopologyDOT();
|
||||
.buildToplolgy();
|
||||
|
||||
CHECK (31 == graph.topLevel());
|
||||
CHECK (0 == graph.getSeed());
|
||||
CHECK (0 == graph.getHash());
|
||||
}
|
||||
CHECK (graph.topLevel() == 31);
|
||||
CHECK (graph.getSeed() == 0);
|
||||
CHECK (graph.getHash() == 6692160254289221734u);
|
||||
|
||||
auto* node = & *graph.allNodes();
|
||||
CHECK (node->hash == graph.getSeed());
|
||||
CHECK (node->succ.size() == 1);
|
||||
CHECK (isSameObject(*node, *node->succ[0]->pred[0]));
|
||||
|
||||
size_t steps{0};
|
||||
while (not isnil(node->succ))
|
||||
{// verify node connectivity
|
||||
++steps;
|
||||
node = node->succ[0];
|
||||
CHECK (steps == node->level);
|
||||
CHECK (1 == node->pred.size());
|
||||
size_t exHash = node->hash;
|
||||
|
||||
// recompute the hash -> reproducible
|
||||
node->hash = 0;
|
||||
node->calculate();
|
||||
CHECK (exHash == node->hash);
|
||||
|
||||
// explicitly compute the hash using boost::hash
|
||||
node->hash = 0;
|
||||
boost::hash_combine (node->hash, node->pred[0]->hash);
|
||||
CHECK (exHash == node->hash);
|
||||
}
|
||||
// got a complete chain using all allocated nodes
|
||||
CHECK (steps == 31);
|
||||
CHECK (steps == graph.topLevel());
|
||||
CHECK (node->hash == graph.getHash());
|
||||
CHECK (node->hash == 6692160254289221734u);
|
||||
} // hash of the graph is hash of last node
|
||||
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -331,7 +331,7 @@ namespace test {
|
|||
*next{&b}; // the next set of nodes connected to current
|
||||
Node* node = &nodes_->front();
|
||||
size_t level{0};
|
||||
size_t expectedLevel = max (1u, numNodes/maxFan);
|
||||
size_t expectedLevel = max (1u, numNodes/maxFan); // guess, typically too low
|
||||
|
||||
// prepare building blocks for the topology generation...
|
||||
auto moreNext = [&]{ return next->size() < maxFan; };
|
||||
|
|
@ -403,12 +403,17 @@ namespace test {
|
|||
node->clear();
|
||||
node->level = ++level;
|
||||
for (Node* o : *next)
|
||||
node->addPred(o);
|
||||
{
|
||||
o->calculate();
|
||||
node->addPred(o);
|
||||
}
|
||||
node->calculate();
|
||||
//
|
||||
return move(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* ===== Operators ===== */
|
||||
|
||||
std::string
|
||||
|
|
|
|||
|
|
@ -95838,19 +95838,20 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699804864545" ID="ID_73838770" MODIFIED="1699827764136" TEXT="verify_Topology">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699805908357" ID="ID_955671536" MODIFIED="1699813655109" TEXT="einfachster Verlinkungs-Durchlauf">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1699804864545" ID="ID_73838770" MODIFIED="1700183506342" TEXT="verify_Topology">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1699805908357" ID="ID_955671536" MODIFIED="1700183502732" TEXT="einfachster Verlinkungs-Durchlauf">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699827742164" ID="ID_1812083819" MODIFIED="1699827750460" TEXT="prüfen: hat lineare Kette erzeugt">
|
||||
<node COLOR="#338800" CREATED="1699827742164" ID="ID_1812083819" MODIFIED="1700183503902" TEXT="prüfen: hat lineare Kette erzeugt">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1699827751499" ID="ID_1702632260" MODIFIED="1700183505282" TEXT="prüfen: Hash ist reproduzierbar">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1700100288256" ID="ID_844700164" MODIFIED="1700183508507" TEXT="control_Topology">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699827751499" ID="ID_1702632260" MODIFIED="1699827760690" TEXT="prüfen: Hash ist reproduzierbar">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1700100288256" ID="ID_844700164" MODIFIED="1700100289765" TEXT="control_Topology">
|
||||
<node COLOR="#338800" CREATED="1700100290904" ID="ID_1991398605" MODIFIED="1700156439824" TEXT="brauche Hilfsmittel zur Visualisierung">
|
||||
<arrowlink COLOR="#62819c" DESTINATION="ID_1464042796" ENDARROW="Default" ENDINCLINATION="21;-256;" ID="Arrow_ID_596151514" STARTARROW="None" STARTINCLINATION="787;55;"/>
|
||||
<icon BUILTIN="button_ok"/>
|
||||
|
|
@ -95866,6 +95867,9 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<node COLOR="#338800" CREATED="1700179604933" ID="ID_860192719" MODIFIED="1700179617983" TEXT="erstes Beispiel mit Expansion funktioniert">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#fdfdcf" COLOR="#ff0000" CREATED="1700183517106" ID="ID_687886895" MODIFIED="1700183524969" TEXT="elaboriertere Beispiele ausknobeln">
|
||||
<icon BUILTIN="flag-pink"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
@ -95882,8 +95886,14 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699746814207" ID="ID_1830964354" MODIFIED="1699758515002" TEXT="Node">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1699746814207" ID="ID_1830964354" MODIFIED="1700183583735" TEXT="Node">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1700183552429" ID="ID_1163563775" MODIFIED="1700183582825" TEXT="predecessor / successor tables">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1700183574687" ID="ID_860112465" MODIFIED="1700183581827" TEXT="Storage structure">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1699746817756" ID="ID_490992503" MODIFIED="1699746834411" TEXT="Generator">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
|
|
@ -95968,8 +95978,8 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eef0c5" COLOR="#990000" CREATED="1699758530360" ID="ID_1331344948" MODIFIED="1699758538983" TEXT="Verlinkung">
|
||||
<icon BUILTIN="pencil"/>
|
||||
<node COLOR="#338800" CREATED="1699758530360" ID="ID_1331344948" MODIFIED="1700183601409" TEXT="Verlinkung">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#5b280f" CREATED="1699758540245" ID="ID_1948581542" MODIFIED="1699803614293" TEXT="Zahl der Verbindungen implizit codiert">
|
||||
<icon BUILTIN="help"/>
|
||||
<icon BUILTIN="button_cancel"/>
|
||||
|
|
|
|||
Loading…
Reference in a new issue