// Step 1973: EnrichedExecutionContract // // t1: default-constructed contract is not enriched // t2: setting selectedLibrary + operationDomain makes it enriched // t3: only selectedLibrary set -> not enriched // t4: only operationDomain set -> not enriched // t5: all fields set and readable #include "EnrichedExecutionContract.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_not_enriched); ws::EnrichedExecutionContract ec; C(!ec.isEnriched(), "default not enriched"); C(ec.selectedLibrary.empty(), "selectedLibrary empty"); C(ec.operationDomain.empty(), "operationDomain empty"); C(ec.capabilityScore == 0.0f, "capabilityScore 0"); C(ec.preferredAPIs.empty(), "preferredAPIs empty"); C(ec.avoidedLibraries.empty(), "avoidedLibraries empty"); P(); } void t2() { T(enriched_after_both_fields_set); ws::EnrichedExecutionContract ec; ec.selectedLibrary = "nlohmann_json"; ec.operationDomain = "serialization.json"; C(ec.isEnriched(), "enriched after both set"); P(); } void t3() { T(not_enriched_only_library_set); ws::EnrichedExecutionContract ec; ec.selectedLibrary = "cublas"; C(!ec.isEnriched(), "not enriched without operationDomain"); P(); } void t4() { T(not_enriched_only_domain_set); ws::EnrichedExecutionContract ec; ec.operationDomain = "compute.matrix"; C(!ec.isEnriched(), "not enriched without selectedLibrary"); P(); } void t5() { T(all_fields_set_and_readable); ws::EnrichedExecutionContract ec; ec.language = "C++"; ec.stepId = "serialize"; ec.taskDescription = "implement JSON serialization"; ec.selectedLibrary = "nlohmann_json"; ec.operationDomain = "serialization.json"; ec.capabilityScore = 0.92f; ec.preferredAPIs = {"nlohmann::json::dump()", "nlohmann::json::parse()"}; ec.avoidedLibraries = {{"protobuf", "score 0.60 < selected 0.92", 0.60f}}; ec.justification = "nlohmann_json scores 0.92 vs protobuf at 0.60"; C(ec.isEnriched(), "enriched"); C(ec.language == "C++", "language"); C(ec.stepId == "serialize", "stepId"); C(ec.taskDescription == "implement JSON serialization", "taskDescription"); C(ec.capabilityScore == 0.92f, "capabilityScore"); C(ec.preferredAPIs.size() == 2, "2 preferredAPIs"); C(ec.avoidedLibraries.size() == 1, "1 avoidedLibrary"); C(ec.avoidedLibraries[0].name == "protobuf","avoidedLibrary name"); P(); } int main() { std::cout << "Step 1973: EnrichedExecutionContract\n"; t1(); t2(); t3(); t4(); t5(); std::cout << "\n" << p << "/" << (p + f) << " passed\n"; return f > 0 ? 1 : 0; }