|
|
@ -178,8 +178,98 @@ function Assert(testName, thingsToCheck) { |
|
|
|
return output; |
|
|
|
} |
|
|
|
|
|
|
|
function executeTests(scenarios, expectations, verboseLevel) { |
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
//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]+"]");} |
|
|
|
let reason = getBidCapReasonForScenario(scenarios[i]); |
|
|
|
scenarioReasons.push(reason); |
|
|
|
} |
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Do the actual assertions/tests to confirm we got the results we were expecting
|
|
|
|
const reasonsCount = scenarioReasons.length; |
|
|
|
console.log(""); |
|
|
|
console.log("Running tests on each scenario..."); |
|
|
|
if(verboseLevel >= 1){ |
|
|
|
console.log("Test\tOutome\t||apply\t|reason\t|truCap\t|capSrc\t|myBid\t|| ScenarioValues -> ExpectedValues"); |
|
|
|
} else { |
|
|
|
console.log("Test\tOutome\t|| ScenarioValues -> ExpectedValues"); |
|
|
|
} |
|
|
|
console.log("-----------------------------------------------------------------"); |
|
|
|
let allTestsPassed = true; |
|
|
|
let failCount = 0; |
|
|
|
for(let i = 0; i < reasonsCount; i++ ){ |
|
|
|
//console.log(JSON.stringify(scenarioReasons[i]));
|
|
|
|
let assertions = [ |
|
|
|
(scenarioReasons[i].shouldApplyCap == expectations[i][0]), |
|
|
|
(scenarioReasons[i].reason == expectations[i][1]), |
|
|
|
(scenarioReasons[i].trueCap == expectations[i][2]), |
|
|
|
(scenarioReasons[i].capSource == expectations[i][3]), |
|
|
|
(scenarioReasons[i].myBid == expectations[i][4]) |
|
|
|
]; |
|
|
|
let testResult = Assert(i, assertions); |
|
|
|
if(verboseLevel >= 1){ |
|
|
|
let individualResults = testResult.individualResults.toString().replaceAll(",","\t| "); |
|
|
|
console.log(testResult.testName + "\t"+ testResult.result + "\t||"+ individualResults +"\t|| ["+scenarios[i]+"]\t-> ["+ expectations[i] +"]"); |
|
|
|
} else { |
|
|
|
console.log(testResult.testName + "\t"+ testResult.result + "\t|| ["+scenarios[i]+"]\t-> ["+ expectations[i] +"]"); |
|
|
|
} |
|
|
|
|
|
|
|
if(verboseLevel >= 2) { |
|
|
|
const ePad =" \t |"; |
|
|
|
const TestResult_ShouldApplyCap = (assertions[0] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_Reason = (assertions[1] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_TrueCap = (assertions[2] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_CapSource = (assertions[3] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_MyBid = (assertions[4] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
console.log(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
|
|
|
console.log(ePad +" ITEM RESULT \t| ACTUAL \t| EXPECTED"); |
|
|
|
console.log(" +---------------------------------------------------"); |
|
|
|
console.log(ePad +"shouldApplyCap: "+ TestResult_ShouldApplyCap +" \t| "+ scenarioReasons[i].shouldApplyCap +" \t| "+ expectations[i][0]); |
|
|
|
console.log(ePad +"reason: "+ TestResult_Reason +"\t| "+ scenarioReasons[i].reason +" \t| "+ expectations[i][1]); |
|
|
|
console.log(ePad +"trueCap: "+ TestResult_TrueCap +"\t| "+ scenarioReasons[i].trueCap +" \t| "+ expectations[i][2]); |
|
|
|
console.log(ePad +"capSource: "+ TestResult_CapSource+"\t| "+ scenarioReasons[i].capSource +"\t| "+ expectations[i][3]); |
|
|
|
console.log(ePad +"myBid: "+ TestResult_MyBid +"\t| "+ scenarioReasons[i].myBid +" \t| "+ expectations[i][4]); |
|
|
|
console.log(" +---------------------------------------------------"); |
|
|
|
console.log("---------------------------------------------------------------------"); |
|
|
|
} |
|
|
|
|
|
|
|
if(testResult.result != TestResult.Pass){ |
|
|
|
allTestsPassed = false; |
|
|
|
failCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("====================================================================="); |
|
|
|
if(allTestsPassed){ |
|
|
|
console.log("All "+reasonsCount +" tests passed"); |
|
|
|
} else { |
|
|
|
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 getScenarios(){ |
|
|
|
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]; |
|
|
@ -189,7 +279,7 @@ function getScenarios(){ |
|
|
|
} |
|
|
|
|
|
|
|
//And what we expect from each scenario
|
|
|
|
function getExpectations(){ |
|
|
|
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]; |
|
|
@ -198,92 +288,14 @@ function getExpectations(){ |
|
|
|
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]+"]");} |
|
|
|
let reason = getBidCapReasonForScenario(scenarios[i]); |
|
|
|
scenarioReasons.push(reason); |
|
|
|
} |
|
|
|
const useCases = getUseCases(); |
|
|
|
const expectedOutcomes = getExpectedOutcomes(); |
|
|
|
const verboseLevel = 1; |
|
|
|
|
|
|
|
const testResults = executeTests(useCases, expectedOutcomes, verboseLevel); |
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
//Do the actual assertions/tests to confirm we got the results we were expecting
|
|
|
|
const reasonsCount = scenarioReasons.length; |
|
|
|
console.log(""); |
|
|
|
console.log("Running tests on each scenario..."); |
|
|
|
if(verboseLevel >= 1){ |
|
|
|
console.log("Test\tOutome\t||apply\t|reason\t|truCap\t|capSrc\t|myBid\t|| ScenarioValues -> ExpectedValues"); |
|
|
|
} else { |
|
|
|
console.log("Test\tOutome\t|| ScenarioValues -> ExpectedValues"); |
|
|
|
} |
|
|
|
console.log("-----------------------------------------------------------------"); |
|
|
|
let allTestsPassed = true; |
|
|
|
let failCount = 0; |
|
|
|
for(let i = 0; i < reasonsCount; i++ ){ |
|
|
|
//console.log(JSON.stringify(scenarioReasons[i]));
|
|
|
|
let assertions = [ |
|
|
|
(scenarioReasons[i].shouldApplyCap == expectations[i][0]), |
|
|
|
(scenarioReasons[i].reason == expectations[i][1]), |
|
|
|
(scenarioReasons[i].trueCap == expectations[i][2]), |
|
|
|
(scenarioReasons[i].capSource == expectations[i][3]), |
|
|
|
(scenarioReasons[i].myBid == expectations[i][4]) |
|
|
|
]; |
|
|
|
let testResult = Assert(i, assertions); |
|
|
|
if(verboseLevel >= 1){ |
|
|
|
let individualResults = testResult.individualResults.toString().replaceAll(",","\t| "); |
|
|
|
console.log(testResult.testName + "\t"+ testResult.result + "\t||"+ individualResults +"\t|| ["+scenarios[i]+"]\t-> ["+ expectations[i] +"]"); |
|
|
|
} else { |
|
|
|
console.log(testResult.testName + "\t"+ testResult.result + "\t|| ["+scenarios[i]+"]\t-> ["+ expectations[i] +"]"); |
|
|
|
} |
|
|
|
|
|
|
|
if(verboseLevel >= 2) { |
|
|
|
const ePad =" \t |"; |
|
|
|
const TestResult_ShouldApplyCap = (assertions[0] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_Reason = (assertions[1] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_TrueCap = (assertions[2] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_CapSource = (assertions[3] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
const TestResult_MyBid = (assertions[4] == true)? TestResult.Pass : TestResult.Fail; |
|
|
|
console.log(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); |
|
|
|
console.log(ePad +" ITEM RESULT \t| ACTUAL \t| EXPECTED"); |
|
|
|
console.log(" +---------------------------------------------------"); |
|
|
|
console.log(ePad +"shouldApplyCap: "+ TestResult_ShouldApplyCap +" \t| "+ scenarioReasons[i].shouldApplyCap +" \t| "+ expectations[i][0]); |
|
|
|
console.log(ePad +"reason: "+ TestResult_Reason +"\t| "+ scenarioReasons[i].reason +" \t| "+ expectations[i][1]); |
|
|
|
console.log(ePad +"trueCap: "+ TestResult_TrueCap +"\t| "+ scenarioReasons[i].trueCap +" \t| "+ expectations[i][2]); |
|
|
|
console.log(ePad +"capSource: "+ TestResult_CapSource+"\t| "+ scenarioReasons[i].capSource +"\t| "+ expectations[i][3]); |
|
|
|
console.log(ePad +"myBid: "+ TestResult_MyBid +"\t| "+ scenarioReasons[i].myBid +" \t| "+ expectations[i][4]); |
|
|
|
console.log(" +---------------------------------------------------"); |
|
|
|
console.log("---------------------------------------------------------------------"); |
|
|
|
} |
|
|
|
|
|
|
|
if(testResult.result != TestResult.Pass){ |
|
|
|
allTestsPassed = false; |
|
|
|
failCount++; |
|
|
|
} |
|
|
|
} |
|
|
|
console.log("====================================================================="); |
|
|
|
if(allTestsPassed){ |
|
|
|
console.log("All "+reasonsCount +" tests passed"); |
|
|
|
} else { |
|
|
|
console.log(failCount+"/"+reasonsCount+" tests failed"); |
|
|
|
} |
|
|
|
console.log(""); |
|
|
|