Browse Source

move test code into executeTests function

main
Steven 1 year ago
parent
commit
8a32a63db7
  1. 134
      test.js

134
test.js

@ -178,68 +178,36 @@ function Assert(testName, thingsToCheck) {
return output; return output;
} }
//All the scenarios we could run into function executeTests(scenarios, expectations, verboseLevel) {
function getScenarios(){ ///////////////////////////////////////////////////////////////////////////////
let useCases = []; //[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]; //Run thru the scenarios
useCases[0] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Win, !RowCapIsEnabled, null, 500, 350]; const scenariosCount = scenarios.length;
useCases[1] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Win, RowCapIsEnabled, 450 , 500, 350]; console.log("VerboseLevel: "+ verboseLevel);
useCases[2] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, !RowCapIsEnabled, null, 500, 350]; console.log("Generating Scenarios... \t[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]");
useCases[3] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, RowCapIsEnabled, 450 , 500, 350]; console.log("Generating ExpectedValues...\t[shouldApplyCap, reason, trueCap, capSource, myBid]");
return useCases; if(verboseLevel >= 2) { console.log("Test \tScenarioValues -> ExpectedValues"); }
} console.log("--------------------------------------------------------");
let scenarioReasons = [];
//And what we expect from each scenario for(let i = 0; i < scenariosCount; i++ ){
function getExpectations(){
let expectedOutcomes = []; //[shouldApplyCap, reason, trueCap, capSource, myBid]);
expectedOutcomes[0] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300];
expectedOutcomes[1] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300];
expectedOutcomes[2] = [GeneralCapIsEnabled, 3, 300, Capsource.General, 300];
expectedOutcomes[3] = [GeneralCapIsEnabled, 4, 300, Capsource.General, 300];
return expectedOutcomes;
}
function getTest(testId) {
//TODO: THIS CODE IS AN IDEA AND IS NOT USED YET
let assertion = {};
assertion.id = testId;
assertion.given = useCases[testId];
assertion.expect = expectedCoutomes[testId];
}
//Setup our scenarios and expected values
let scenarios = getScenarios();
let expectations = getExpectations();
let verboseLevel = 1;
///////////////////////////////////////////////////////////////////////////////
//Run thru the scenarios
const scenariosCount = scenarios.length;
console.log("VerboseLevel: "+ verboseLevel);
console.log("Generating Scenarios... \t[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]");
console.log("Generating ExpectedValues...\t[shouldApplyCap, reason, trueCap, capSource, myBid]");
if(verboseLevel >= 2) { console.log("Test \tScenarioValues -> ExpectedValues"); }
console.log("--------------------------------------------------------");
let scenarioReasons = [];
for(let i = 0; i < scenariosCount; i++ ){
if(verboseLevel >= 2) { console.log(i+"\t["+ scenarios[i]+"] -> "+ "["+expectations[i]+"]");} if(verboseLevel >= 2) { console.log(i+"\t["+ scenarios[i]+"] -> "+ "["+expectations[i]+"]");}
let reason = getBidCapReasonForScenario(scenarios[i]); let reason = getBidCapReasonForScenario(scenarios[i]);
scenarioReasons.push(reason); scenarioReasons.push(reason);
} }
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
//Do the actual assertions/tests to confirm we got the results we were expecting //Do the actual assertions/tests to confirm we got the results we were expecting
const reasonsCount = scenarioReasons.length; const reasonsCount = scenarioReasons.length;
console.log(""); console.log("");
console.log("Running tests on each scenario..."); console.log("Running tests on each scenario...");
if(verboseLevel >= 1){ if(verboseLevel >= 1){
console.log("Test\tOutome\t||apply\t|reason\t|truCap\t|capSrc\t|myBid\t|| ScenarioValues -> ExpectedValues"); console.log("Test\tOutome\t||apply\t|reason\t|truCap\t|capSrc\t|myBid\t|| ScenarioValues -> ExpectedValues");
} else { } else {
console.log("Test\tOutome\t|| ScenarioValues -> ExpectedValues"); console.log("Test\tOutome\t|| ScenarioValues -> ExpectedValues");
} }
console.log("-----------------------------------------------------------------"); console.log("-----------------------------------------------------------------");
let allTestsPassed = true; let allTestsPassed = true;
let failCount = 0; let failCount = 0;
for(let i = 0; i < reasonsCount; i++ ){ for(let i = 0; i < reasonsCount; i++ ){
//console.log(JSON.stringify(scenarioReasons[i])); //console.log(JSON.stringify(scenarioReasons[i]));
let assertions = [ let assertions = [
(scenarioReasons[i].shouldApplyCap == expectations[i][0]), (scenarioReasons[i].shouldApplyCap == expectations[i][0]),
@ -279,11 +247,55 @@ for(let i = 0; i < reasonsCount; i++ ){
allTestsPassed = false; allTestsPassed = false;
failCount++; failCount++;
} }
} }
console.log("====================================================================="); console.log("=====================================================================");
if(allTestsPassed){ if(allTestsPassed){
console.log("All "+reasonsCount +" tests passed"); console.log("All "+reasonsCount +" tests passed");
} else { } else {
console.log(failCount+"/"+reasonsCount+" tests failed"); console.log(failCount+"/"+reasonsCount+" tests failed");
}
console.log("");
return allTestsPassed;
}
function getTest(testId) {
//TODO: THIS CODE IS AN IDEA AND IS NOT USED YET
let test = {};
test.id = testId;
test.given = getUseCases()[testId];
test.expect = getExpectedOutcomes()[testId];
return test;
}
//All the scenarios we could run into
function getUseCases(){
let useCases = []; //[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid];
useCases[0] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Win, !RowCapIsEnabled, null, 500, 350];
useCases[1] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Win, RowCapIsEnabled, 450 , 500, 350];
useCases[2] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, !RowCapIsEnabled, null, 500, 350];
useCases[3] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, RowCapIsEnabled, 450 , 500, 350];
return useCases;
}
//And what we expect from each scenario
function getExpectedOutcomes(){
let expectedOutcomes = []; //[shouldApplyCap, reason, trueCap, capSource, myBid]);
expectedOutcomes[0] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300];
expectedOutcomes[1] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300];
expectedOutcomes[2] = [GeneralCapIsEnabled, 3, 300, Capsource.General, 300];
expectedOutcomes[3] = [GeneralCapIsEnabled, 4, 300, Capsource.General, 300];
return expectedOutcomes;
} }
console.log("");
//Setup our scenarios and expected values
const useCases = getUseCases();
const expectedOutcomes = getExpectedOutcomes();
const verboseLevel = 1;
const testResults = executeTests(useCases, expectedOutcomes, verboseLevel);

Loading…
Cancel
Save