Browse Source

renamed variable for easier reading

main
Steven 1 year ago
parent
commit
9946e7b8a2
  1. 114
      test.js

114
test.js

@ -31,16 +31,16 @@ const TestResult = Object.freeze({
}) })
//Declare some readability constants //Declare some readability constants
const ShouldApplyCap = true; const CapIsTriggered = true; //myBid is over the targetCap the cap is enabled in some way for the row)
const GeneralCapIsEnabled = true; const GeneralCapIsEnabled = true; //The generalCap checkbox is checked
const RowCapIsEnabled = true; const RowCapIsEnabled = true; //The rowCap checkBox is checked for the county
function newResult(shouldApplyCap, reasonNum, trueCap, capSource, myBidNum) { function newResult(capIsTriggered, reasonNum, trueCapNum, capSource, myBidNum) {
let result = {}; let result = {};
result.shouldApplyCap = shouldApplyCap; result.capIsTriggered = capIsTriggered;
result.reason = reasonNum; result.reason = reasonNum;
result.trueCap = trueCap; result.trueCap = trueCapNum;
result.capSource = capSource; result.capSource = capSource;
result.myBid = myBidNum; result.myBid = myBidNum;
return result; return result;
@ -75,7 +75,7 @@ function executeTests(scenarios, expectations, verboseLevel) {
const scenariosCount = scenarios.length; const scenariosCount = scenarios.length;
console.log("VerboseLevel: "+ verboseLevel); console.log("VerboseLevel: "+ verboseLevel);
console.log("Generating Scenarios... \t[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]"); console.log("Generating Scenarios... \t[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]");
console.log("Generating ExpectedValues...\t[shouldApplyCap, reason, trueCap, capSource, myBid]"); console.log("Generating ExpectedValues...\t[capIsTriggered, reason, trueCap, capSource, myBid]");
if(verboseLevel >= 2) { console.log("Test \tScenarioValues -> ExpectedValues"); } if(verboseLevel >= 2) { console.log("Test \tScenarioValues -> ExpectedValues"); }
console.log("--------------------------------------------------------"); console.log("--------------------------------------------------------");
let scenarioReasons = []; let scenarioReasons = [];
@ -91,7 +91,7 @@ function executeTests(scenarios, expectations, verboseLevel) {
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||trgrd\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");
} }
@ -101,7 +101,7 @@ function executeTests(scenarios, expectations, verboseLevel) {
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].capIsTriggered == expectations[i][0]),
(scenarioReasons[i].reason == expectations[i][1]), (scenarioReasons[i].reason == expectations[i][1]),
(scenarioReasons[i].trueCap == expectations[i][2]), (scenarioReasons[i].trueCap == expectations[i][2]),
(scenarioReasons[i].capSource == expectations[i][3]), (scenarioReasons[i].capSource == expectations[i][3]),
@ -117,7 +117,7 @@ function executeTests(scenarios, expectations, verboseLevel) {
if(verboseLevel >= 2) { if(verboseLevel >= 2) {
const ePad =" \t |"; const ePad =" \t |";
const TestResult_ShouldApplyCap = (assertions[0] == true)? TestResult.Pass : TestResult.Fail; const TestResult_CapIsTriggered = (assertions[0] == true)? TestResult.Pass : TestResult.Fail;
const TestResult_Reason = (assertions[1] == 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_TrueCap = (assertions[2] == true)? TestResult.Pass : TestResult.Fail;
const TestResult_CapSource = (assertions[3] == true)? TestResult.Pass : TestResult.Fail; const TestResult_CapSource = (assertions[3] == true)? TestResult.Pass : TestResult.Fail;
@ -125,7 +125,7 @@ function executeTests(scenarios, expectations, verboseLevel) {
console.log(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"); console.log(" +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
console.log(ePad +" ITEM RESULT \t| ACTUAL \t| EXPECTED"); console.log(ePad +" ITEM RESULT \t| ACTUAL \t| EXPECTED");
console.log(" +---------------------------------------------------"); console.log(" +---------------------------------------------------");
console.log(ePad +"shouldApplyCap: "+ TestResult_ShouldApplyCap +" \t| "+ scenarioReasons[i].shouldApplyCap +" \t| "+ expectations[i][0]); console.log(ePad +"capIsTriggered: "+ TestResult_CapIsTriggered +" \t| "+ scenarioReasons[i].capIsTriggered +" \t| "+ expectations[i][0]);
console.log(ePad +"reason: "+ TestResult_Reason +"\t| "+ scenarioReasons[i].reason +" \t| "+ expectations[i][1]); 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 +"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 +"capSource: "+ TestResult_CapSource+"\t| "+ scenarioReasons[i].capSource +"\t| "+ expectations[i][3]);
@ -160,15 +160,15 @@ function getTest(testId) {
} }
//The function from our main codebase //The function from our main codebase
function getBidCapReason(generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid) { function getBidCapReason(generalCapIsEnabled, pGeneralCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, pRowCap, pTieBid, pMyBid) {
let tieBidNum = Number(tieBid); let tieBid = Number(pTieBid);
let winBidNum = Number(tieBid) + 25; let winBid = Number(pTieBid) + 25;
let generalCapNum = Number(generalCap); let generalCap = Number(pGeneralCap);
let rowCapNum = Number(rowCap); let rowCap = Number(pRowCap);
let myBidNum = Number(myBid); let myBid = Number(pMyBid);
//Build our response object //Build our response object
let results = newResult(false, 0, null, null, myBidNum); let results = newResult(false, 0, null, null, myBid);
//WIP - LOTS of rules here - these are just the beginning. //WIP - LOTS of rules here - these are just the beginning.
if(generalCapIsEnabled) { if(generalCapIsEnabled) {
@ -177,29 +177,29 @@ function getBidCapReason(generalCapIsEnabled, generalCap, capPresidence, applyPr
switch(oversightAction) { switch(oversightAction) {
case Oversight.Win: case Oversight.Win:
if(winBidNum > generalCapNum) { if(winBid > generalCap) {
results = newResult(true, 1, generalCapNum, Capsource.General, generalCapNum); results = newResult(true, 1, generalCap, Capsource.General, generalCap);
return results; return results;
} }
//winBidNum <= generalCapNum //winBid <= generalCap
results = newResult(false, 2, generalCapNum, Capsource.General, myBidNum); results = newResult(false, 2, generalCap, Capsource.General, myBid);
break; break;
case Oversight.Tie: case Oversight.Tie:
if(tieBidNum > generalCapNum) { if(tieBid > generalCap) {
results = newResult(true, 3, generalCapNum, Capsource.General, generalCapNum); results = newResult(true, 3, generalCap, Capsource.General, generalCap);
return results; return results;
} }
//tieBidNum <= generalCapNum //tieBid <= generalCap
results = newResult(false, 4, generalCapNum, Capsource.General, myBidNum); results = newResult(false, 4, generalCap, Capsource.General, myBid);
break; break;
case Oversight.Watch: case Oversight.Watch:
results = newResult(false, 5, generalCapNum, Capsource.General, myBidNum); results = newResult(false, 5, generalCap, Capsource.General, myBid);
break; break;
case Oversight.Ignore: case Oversight.Ignore:
results = newResult(false, 6, generalCapNum, Capsource.General, myBidNum); results = newResult(false, 6, generalCap, Capsource.General, myBid);
break; break;
default: default:
@ -234,29 +234,29 @@ function getBidCapReason(generalCapIsEnabled, generalCap, capPresidence, applyPr
if(rowCapIsEnabled) { if(rowCapIsEnabled) {
switch(oversightAction) { switch(oversightAction) {
case Oversight.Win: case Oversight.Win:
if(winBidNum > rowCapNum) { if(winBid > rowCap) {
results = newResult(true, 101, rowCapNum, Capsource.Row, rowCapNum); results = newResult(true, 101, rowCap, Capsource.Row, rowCap);
return results; return results;
} }
//winBidNum <= rowCapNum //winBid <= rowCap
results = newResult(false, 102, rowCapNum, Capsource.Row, myBidNum); results = newResult(false, 102, rowCap, Capsource.Row, myBid);
break; break;
case Oversight.Tie: case Oversight.Tie:
if(tieBidNum > rowCapNum) { if(tieBid > rowCap) {
results = newResult(true, 103, rowCapNum, Capsource.Row, rowCapNum); results = newResult(true, 103, rowCap, Capsource.Row, rowCap);
return results; return results;
} }
//tieBidNum <= generalCapNum //tieBid <= generalCap
results = newResult(false, 104, rowCapNum, Capsource.Row, myBidNum); results = newResult(false, 104, rowCap, Capsource.Row, myBid);
break; break;
case Oversight.Watch: case Oversight.Watch:
results = newResult(false, 105, null, Capsource.Row, myBidNum); results = newResult(false, 105, null, Capsource.Row, myBid);
break; break;
case Oversight.Ignore: case Oversight.Ignore:
results = newResult(false, 106, null, Capsource.Row, myBidNum); results = newResult(false, 106, null, Capsource.Row, myBid);
break; break;
default: default:
//We should never get here because all oversight actions have been covered. //We should never get here because all oversight actions have been covered.
@ -271,20 +271,40 @@ function getBidCapReason(generalCapIsEnabled, generalCap, capPresidence, applyPr
//All the scenarios we could run into //All the scenarios we could run into
function getUseCases(){ function getUseCases(){
let useCases = []; //[generalCapIsEnabled, generalCap, capPresidence, applyPresidenceTo, oversightAction, rowCapIsEnabled, rowCap, tieBid, myBid]; 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]; // [generalCapIsEnabled, gCap, capPresidence , applyTo , rowAction , rowCapIsEnabled, rCap, tie, myBid]; //win
useCases[2] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, !RowCapIsEnabled, null, 500, 350]; //winBid > generalCap > rowCap > myBid
useCases[3] = [GeneralCapIsEnabled, 300, Presidence.General, AppliesTo.All, Oversight.Tie, RowCapIsEnabled, 450 , 500, 350]; useCases[0] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, !RowCapIsEnabled, null, 550, 225]; //575
useCases[1] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, RowCapIsEnabled, 450 , 550, 225]; //575
//winBid = generalCap > rowCap > myBid
useCases[2] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, !RowCapIsEnabled, null, 275, 225]; //300
useCases[3] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, RowCapIsEnabled, 450 , 275, 225]; //300
//winBid < generalCap > rowCap > myBid
useCases[4] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, !RowCapIsEnabled, null, 250, 225]; //275
useCases[5] = [GeneralCapIsEnabled, 350, Presidence.General, AppliesTo.All, Oversight.Win, RowCapIsEnabled, 450 , 250, 225]; //275
//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; return useCases;
} }
//And what we expect from each scenario //And what we expect from each scenario
function getExpectedOutcomes(){ function getExpectedOutcomes(){
let expectedOutcomes = []; //[shouldApplyCap, reason, trueCap, capSource, myBid]); let expectedOutcomes = [];//[capIsTriggered, reason, trueCap, capSource, myBid]);
expectedOutcomes[0] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300];
expectedOutcomes[1] = [GeneralCapIsEnabled, 1, 300, Capsource.General, 300]; // [ capIsTriggered, r,trueCap, capSource, myBid] //wBid,(gC||rC ) -> tCap? myBid
expectedOutcomes[2] = [GeneralCapIsEnabled, 3, 300, Capsource.General, 300]; //winBid > generalCap > rowCap > myBid
expectedOutcomes[3] = [GeneralCapIsEnabled, 4, 300, Capsource.General, 300]; expectedOutcomes[0] = [!CapIsTriggered, 1, 350, Capsource.General, 225]; //575,(350||null) -> 350 ? 225
expectedOutcomes[1] = [!CapIsTriggered, 1, 350, Capsource.General, 225]; //575,(350||450) -> 350 ? 225
//winBid = generalCap > rowCap > myBid
expectedOutcomes[2] = [!CapIsTriggered, 0, 350, Capsource.General, 225]; //300,(350||null) -> 350 ? 225
expectedOutcomes[3] = [!CapIsTriggered, 0, 350, Capsource.General, 225]; //300,(350||450) -> 350 ? 225
//winBid < generalCap > rowCap > myBid
expectedOutcomes[4] = [!CapIsTriggered, 0, 350, Capsource.General, 225]; //275,(350||null) -> 350 ? 225
expectedOutcomes[5] = [!CapIsTriggered, 0, 350, Capsource.General, 225]; //275,(350||450) -> 350 ? 225
//expectedOutcomes[2] = [CapIsTriggered, 3, 300, Capsource.General, 300];
//expectedOutcomes[3] = [CapIsTriggered, 4, 300, Capsource.General, 300];
return expectedOutcomes; return expectedOutcomes;
} }

Loading…
Cancel
Save