2023-04-23 12:10:56 +02:00
|
|
|
const chai = require("chai");
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let assert = chai.assert;
|
2023-04-23 12:10:56 +02:00
|
|
|
const ConvertHandler = require("../controllers/convertHandler.js");
|
2017-02-18 20:14:10 +01:00
|
|
|
|
Fix (Boilerplate): Add Event Parameter to test, Remove Infosec Requriements, Add Lowercase Requirement (#12)
* Fix missing event, correct example conversion
* Fix unit case
* Remove Infosec items, add lowercase requirement
* Convert to ES6, Update Packages, Fix display
* Applying @nhcarrigan's changes from site tests
* Removed unneeded mongodb ref
* Remove User Stories, Reformat README
* Apply suggestions from code review - Remove "Quality Assurance Project" Prefix
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
* Re-add the example text, clean up formatting
* Update Favicon
* Fix repo link, remove zombie.js
* Remove unused files, add sample.env
Co-authored-by: Shaun Hamilton <51722130+Sky020@users.noreply.github.com>
Co-authored-by: Rex Schrader <rex.schader@gmail.com>
2020-11-25 16:09:04 +01:00
|
|
|
let convertHandler = new ConvertHandler();
|
2017-02-18 20:14:10 +01:00
|
|
|
|
2023-04-23 12:10:56 +02:00
|
|
|
suite("Unit Tests", function () {
|
|
|
|
test("convertHandler should correctly read a whole number input.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getNum("4224sdfwfs"), 4224);
|
|
|
|
});
|
2017-02-18 20:14:10 +01:00
|
|
|
|
2023-04-23 12:10:56 +02:00
|
|
|
test("convertHandler should correctly read a decimal number input.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getNum("422.4sdfwfs"), 422.4);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly read a fractional input.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getNum("42/4sdfwfs"), 10.5);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly read a fractional input with a decimal.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getNum("4.5/4sdfwfs"), 1.125);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly return an error on a double-fraction (i.e. 3/2/3).", () => {
|
|
|
|
assert.isNotOk(convertHandler.getNum("3/2/3"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly default to a numerical input of 1 when no numerical input is provided.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getNum("sdfsf"), 1);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly read each valid input unit.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getUnit("13122gal"), "gal");
|
|
|
|
assert.strictEqual(convertHandler.getUnit("13122l"), "L");
|
|
|
|
assert.strictEqual(convertHandler.getUnit("13122kG"), "kg");
|
|
|
|
assert.strictEqual(convertHandler.getUnit("13122lBs"), "lbs");
|
|
|
|
assert.strictEqual(convertHandler.getUnit("KM"), "km");
|
|
|
|
assert.strictEqual(convertHandler.getUnit("mi"), "mi");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly return an error for an invalid input unit.", () => {
|
|
|
|
assert.isNotOk(convertHandler.getUnit("fsdf"));
|
|
|
|
assert.isNotOk(convertHandler.getUnit("lbs32424mi"));
|
|
|
|
assert.isNotOk(convertHandler.getUnit("132km4234mi"));
|
|
|
|
assert.isNotOk(convertHandler.getUnit("sfddsF"));
|
|
|
|
assert.isNotOk(convertHandler.getUnit("2312sdfg"));
|
|
|
|
assert.isNotOk(convertHandler.getUnit("dafd56456"));
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should return the correct return unit for each valid input unit.", () => {
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("gal"), "L");
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("l"), "gal");
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("MI"), "km");
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("kM"), "mi");
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("lBs"), "kg");
|
|
|
|
assert.strictEqual(convertHandler.getReturnUnit("Kg"), "lbs");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly return the spelled-out string unit for each valid input unit.", () => {
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("L"), "liters");
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("gal"), "gallons");
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("kM"), "kilometers");
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("MI"), "miles");
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("kG"), "kilograms");
|
|
|
|
assert.strictEqual(convertHandler.spellOutUnit("lBS"), "pounds");
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert gal to L.", () => {
|
|
|
|
assert.approximately(convertHandler.convert(10.5, "gal"), 39.74682, 0.0001);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert L to gal.", () => {
|
|
|
|
assert.approximately(convertHandler.convert(2.9, "l"), 0.766098, 0.0001);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert mi to km.", () => {
|
|
|
|
assert.approximately(convertHandler.convert(10.5, "mi"), 16.89811, 0.0001);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert km to mi.", () => {
|
|
|
|
assert.approximately(
|
|
|
|
convertHandler.convert(8.237415, "km"),
|
|
|
|
5.118492,
|
|
|
|
0.0001
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert lbs to kg.", () => {
|
|
|
|
assert.approximately(convertHandler.convert(22, "lbs"), 9.97903214, 0.0001);
|
|
|
|
});
|
|
|
|
|
|
|
|
test("convertHandler should correctly convert kg to lbs..", () => {
|
|
|
|
assert.approximately(
|
|
|
|
convertHandler.convert(191612, "kg"),
|
|
|
|
422432.24352,
|
|
|
|
0.5
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|