// Step 1959: LibraryCapabilityRecord // // t1: default field values are sane // t2: validator rejects score < 0.0 // t3: validator rejects score > 1.0 // t4: validator rejects empty libraryId or empty operationDomain // t5: validator rejects notApplicable=true with score > 0.0; accepts valid records #include "LibraryCapabilityRecord.h" #include 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(default_record_fields); ws::LibraryCapabilityRecord r; C(r.libraryId.empty(), "empty libraryId by default"); C(r.operationDomain.empty(), "empty operationDomain by default"); C(r.score == 0.0f, "score defaults to 0.0"); C(!r.notApplicable, "notApplicable defaults to false"); C(r.preferredAPIs.empty(), "no APIs by default"); P(); } void t2() { T(validator_rejects_negative_score); ws::LibraryCapabilityRecordValidator v; ws::LibraryCapabilityRecord r{"mylib", "serialization.json", -0.1f}; auto res = v.validate(r); C(!res.valid, "invalid"); C(!res.error.empty(), "error message set"); P(); } void t3() { T(validator_rejects_score_over_1); ws::LibraryCapabilityRecordValidator v; ws::LibraryCapabilityRecord r{"mylib", "serialization.json", 1.01f}; auto res = v.validate(r); C(!res.valid, "invalid for score 1.01"); // Score exactly 1.0 must pass r.score = 1.0f; auto ok = v.validate(r); C(ok.valid, "score 1.0 is valid"); // Score exactly 0.0 must pass r.score = 0.0f; auto ok2 = v.validate(r); C(ok2.valid, "score 0.0 is valid"); P(); } void t4() { T(validator_rejects_empty_ids); ws::LibraryCapabilityRecordValidator v; ws::LibraryCapabilityRecord r{"", "serialization.json", 0.9f}; C(!v.validate(r).valid, "empty libraryId invalid"); r.libraryId = "mylib"; r.operationDomain = ""; C(!v.validate(r).valid, "empty operationDomain invalid"); r.operationDomain = "serialization.json"; C(v.validate(r).valid, "fully populated record is valid"); P(); } void t5() { T(validator_rejects_notApplicable_with_nonzero_score); ws::LibraryCapabilityRecordValidator v; ws::LibraryCapabilityRecord r{"mylib", "compute.matrix", 0.5f}; r.notApplicable = true; auto bad = v.validate(r); C(!bad.valid, "notApplicable=true with score=0.5 is invalid"); // notApplicable=true with score=0.0 is fine r.score = 0.0f; auto ok = v.validate(r); C(ok.valid, "notApplicable=true with score=0.0 is valid"); // notApplicable=false with any valid score is fine r.notApplicable = false; r.score = 0.95f; C(v.validate(r).valid, "notApplicable=false score=0.95 valid"); P(); } int main() { std::cout << "Step 1959: LibraryCapabilityRecord\n"; t1(); t2(); t3(); t4(); t5(); std::cout << "\n" << p << "/" << (p + f) << " passed\n"; return f > 0 ? 1 : 0; }