Phase 6 Library Dispatch foundation. Five new headers: - OperationDomain: dot-key hierarchy with parent traversal - LibraryCapabilityRecord: score/APIs/weaknesses + validator - LibraryCapabilityLedger: (library, domain) -> record registry - OperationTaxonomy: 40+ domain tree, keyword-based classify() - Sprint286IntegrationSummary: 8-library seed ledger + verified lookups 25/25 tests passing. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
90 lines
3.5 KiB
C++
90 lines
3.5 KiB
C++
// Step 1958: OperationDomain
|
|
//
|
|
// t1: key, displayName, parent() correct for "serialization.json"
|
|
// t2: parent() for top-level "serialization" is ""
|
|
// t3: isTopLevel() and depth()
|
|
// t4: OperationDomainRegistry register, lookup, has, size
|
|
// t5: children() returns only direct children, not grandchildren
|
|
|
|
#include "OperationDomain.h"
|
|
#include <iostream>
|
|
|
|
namespace ws = whetstone;
|
|
static int p = 0, f = 0;
|
|
#define T(n) { std::cout << " " << #n << "... "; }
|
|
#define P() { std::cout << "PASS\n"; ++p; }
|
|
#define F(m) { std::cout << "FAIL: " << m << "\n"; ++f; }
|
|
#define C(c, m) if (!(c)) { F(m); return; }
|
|
|
|
void t1() {
|
|
T(operation_domain_key_and_parent);
|
|
ws::OperationDomain d = ws::OperationDomain::fromKey("serialization.json", "JSON Serialization");
|
|
C(d.key == "serialization.json", "key");
|
|
C(d.displayName == "JSON Serialization", "displayName");
|
|
C(d.parent() == "serialization", "parent");
|
|
C(d.depth() == 1, "depth=1");
|
|
P();
|
|
}
|
|
|
|
void t2() {
|
|
T(top_level_domain_has_empty_parent);
|
|
ws::OperationDomain d = ws::OperationDomain::fromKey("serialization");
|
|
C(d.parent() == "", "parent of top-level is empty");
|
|
C(d.isTopLevel(), "isTopLevel");
|
|
C(d.depth() == 0, "depth=0");
|
|
P();
|
|
}
|
|
|
|
void t3() {
|
|
T(deep_domain_depth_and_parent_chain);
|
|
ws::OperationDomain d = ws::OperationDomain::fromKey("compute.ml.training");
|
|
C(d.depth() == 2, "depth=2");
|
|
C(!d.isTopLevel(), "not top-level");
|
|
C(d.parent() == "compute.ml", "parent is compute.ml");
|
|
ws::OperationDomain mid = ws::OperationDomain::fromKey(d.parent());
|
|
C(mid.parent() == "compute", "grandparent is compute");
|
|
P();
|
|
}
|
|
|
|
void t4() {
|
|
T(domain_registry_register_lookup_has_size);
|
|
ws::OperationDomainRegistry reg;
|
|
reg.registerDomain({"serialization.json", "JSON"});
|
|
reg.registerDomain({"serialization.binary", "Binary"});
|
|
reg.registerDomain({"compute.matrix", "Matrix"});
|
|
C(reg.size() == 3, "size=3");
|
|
C(reg.has("serialization.json"), "has json");
|
|
C(!reg.has("unknown"), "no unknown");
|
|
auto d = reg.lookup("compute.matrix");
|
|
C(d.has_value(), "lookup found");
|
|
C(d->key == "compute.matrix", "lookup key");
|
|
auto none = reg.lookup("missing");
|
|
C(!none.has_value(), "lookup missing returns nullopt");
|
|
P();
|
|
}
|
|
|
|
void t5() {
|
|
T(children_returns_only_direct_children);
|
|
ws::OperationDomainRegistry reg;
|
|
reg.registerDomain({"serialization", "S"});
|
|
reg.registerDomain({"serialization.json", "SJ"});
|
|
reg.registerDomain({"serialization.binary", "SB"});
|
|
reg.registerDomain({"serialization.xml", "SX"});
|
|
reg.registerDomain({"compute.matrix", "CM"}); // not a child of serialization
|
|
auto kids = reg.children("serialization");
|
|
C(kids.size() == 3, "three direct children");
|
|
C(kids[0].key == "serialization.binary", "sorted: binary first");
|
|
C(kids[1].key == "serialization.json", "json second");
|
|
C(kids[2].key == "serialization.xml", "xml third");
|
|
auto none = reg.children("nonexistent_parent");
|
|
C(none.empty(), "unregistered parent has no children");
|
|
P();
|
|
}
|
|
|
|
int main() {
|
|
std::cout << "Step 1958: OperationDomain\n";
|
|
t1(); t2(); t3(); t4(); t5();
|
|
std::cout << "\n" << p << "/" << (p + f) << " passed\n";
|
|
return f > 0 ? 1 : 0;
|
|
}
|