95 lines
3.0 KiB
C++
95 lines
3.0 KiB
C++
|
|
// Step 1939: BehavioralParityChecker
|
||
|
|
//
|
||
|
|
// t1: check — all match → allMatch=true, empty divergentLanguages
|
||
|
|
// t2: check — one diverges → allMatch=false, divergentLanguages lists it
|
||
|
|
// t3: checkAgainstReference uses named language as reference
|
||
|
|
// t4: allPass — true when all ran+match; false when one doesn't run
|
||
|
|
// t5: failingLanguages returns divergent set
|
||
|
|
|
||
|
|
#include "BehavioralParityChecker.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;}
|
||
|
|
|
||
|
|
static std::vector<ws::RunResult> matching() {
|
||
|
|
return {{"Python","1 2 3\n",0,true},{"Rust","1 2 3\n",0,true},{"Go","1 2 3\n",0,true}};
|
||
|
|
}
|
||
|
|
|
||
|
|
void t1(){
|
||
|
|
T(check_all_match);
|
||
|
|
ws::BehavioralParityChecker c;
|
||
|
|
auto r = c.check(matching());
|
||
|
|
C(r.allMatch, "allMatch true");
|
||
|
|
C(r.divergentLanguages.empty(), "no divergents");
|
||
|
|
C(r.referenceLanguage == "Python","reference is Python (first)");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t2(){
|
||
|
|
T(check_one_diverges);
|
||
|
|
ws::BehavioralParityChecker c;
|
||
|
|
auto results = matching();
|
||
|
|
results[2].output = "3 2 1\n"; // Go diverges
|
||
|
|
auto r = c.check(results);
|
||
|
|
C(!r.allMatch, "not allMatch");
|
||
|
|
C(r.divergentLanguages.size()==1,"one divergent");
|
||
|
|
C(r.divergentLanguages[0]=="Go", "Go divergent");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t3(){
|
||
|
|
T(checkAgainstReference_named_language);
|
||
|
|
ws::BehavioralParityChecker c;
|
||
|
|
std::vector<ws::RunResult> results = {
|
||
|
|
{"Python","A\n",0,true},
|
||
|
|
{"Rust", "B\n",0,true},
|
||
|
|
{"Go", "A\n",0,true}
|
||
|
|
};
|
||
|
|
// Reference = Python ("A\n"); Rust diverges
|
||
|
|
auto r = c.checkAgainstReference(results,"Python");
|
||
|
|
C(!r.allMatch, "not allMatch");
|
||
|
|
C(r.referenceOutput == "A\n", "reference output");
|
||
|
|
C(r.divergentLanguages.size()==1, "one divergent");
|
||
|
|
C(r.divergentLanguages[0]=="Rust","Rust diverges");
|
||
|
|
// Reference = Rust ("B\n"); Python and Go diverge
|
||
|
|
auto r2 = c.checkAgainstReference(results,"Rust");
|
||
|
|
C(r2.divergentLanguages.size()==2,"two diverge vs Rust");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t4(){
|
||
|
|
T(allPass_true_and_false);
|
||
|
|
ws::BehavioralParityChecker c;
|
||
|
|
C(c.allPass(matching()), "matching all pass");
|
||
|
|
auto withFail = matching();
|
||
|
|
withFail[1].ran = false;
|
||
|
|
C(!c.allPass(withFail), "not all pass when one didn't run");
|
||
|
|
auto diverged = matching();
|
||
|
|
diverged[2].output = "wrong";
|
||
|
|
C(!c.allPass(diverged), "not all pass when output diverges");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
void t5(){
|
||
|
|
T(failingLanguages_returns_divergent_set);
|
||
|
|
ws::BehavioralParityChecker c;
|
||
|
|
auto results = matching();
|
||
|
|
results[1].output = "X\n";
|
||
|
|
results[2].output = "Y\n";
|
||
|
|
auto fl = c.failingLanguages(results);
|
||
|
|
C(fl.size() == 2, "two failing");
|
||
|
|
P();
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(){
|
||
|
|
std::cout << "Step 1939: BehavioralParityChecker\n";
|
||
|
|
t1(); t2(); t3(); t4(); t5();
|
||
|
|
std::cout << "\n" << p << "/" << (p+f) << " passed\n";
|
||
|
|
return f > 0 ? 1 : 0;
|
||
|
|
}
|