From 3972a394802f8566e2b3a55d8466c72f801b4d39 Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 11 Oct 2019 15:16:07 +1300 Subject: [PATCH 1/3] Added some javascript stuff with QUnit browser tests. --- javascript/README.md | 9 +++++++++ javascript/tests.html | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 javascript/README.md create mode 100644 javascript/tests.html diff --git a/javascript/README.md b/javascript/README.md new file mode 100644 index 0000000..248b8fb --- /dev/null +++ b/javascript/README.md @@ -0,0 +1,9 @@ +# JavaScript beard checker + +``` bash +npm install +npm install -g qunit +qunit +``` + +To see the tests run in your browser, enter `file:////javascript/tests.html` in the url bar. diff --git a/javascript/tests.html b/javascript/tests.html new file mode 100644 index 0000000..0e7e054 --- /dev/null +++ b/javascript/tests.html @@ -0,0 +1,39 @@ + + + + + Beard Checker + + + + + + +
+
+ + + From e2407f56cad19dffd8fd17cbef8b27f9c736ac1c Mon Sep 17 00:00:00 2001 From: Jacob Date: Fri, 11 Oct 2019 15:18:24 +1300 Subject: [PATCH 2/3] Spelling error. --- javascript/README.md | 4 ++-- javascript/tests.html | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/javascript/README.md b/javascript/README.md index 248b8fb..651c9cd 100644 --- a/javascript/README.md +++ b/javascript/README.md @@ -1,9 +1,9 @@ # JavaScript beard checker +To see the tests run in your browser, enter `file:////javascript/tests.html` in the url bar. + ``` bash npm install npm install -g qunit qunit ``` - -To see the tests run in your browser, enter `file:////javascript/tests.html` in the url bar. diff --git a/javascript/tests.html b/javascript/tests.html index 0e7e054..6d97352 100644 --- a/javascript/tests.html +++ b/javascript/tests.html @@ -28,7 +28,7 @@ assert.equal( on_or_below_chin, true, "On or below chin"); }); - QUnit.test( "Is is unbroken between ears?", function ( assert ) { + QUnit.test( "Is it unbroken between ears?", function ( assert ) { var unbroken_between_ears = false; assert.equal( unbroken_between_ears, false, "Broken between ears"); var unbroken_between_ears = true; From a2daf9374ea5a49310d4f3e936f718eae406962e Mon Sep 17 00:00:00 2001 From: Jacob Date: Tue, 15 Oct 2019 09:43:27 +1300 Subject: [PATCH 3/3] Beard test. To fix... --- javascript/test/beard_test.js | 38 +++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 javascript/test/beard_test.js diff --git a/javascript/test/beard_test.js b/javascript/test/beard_test.js new file mode 100644 index 0000000..2282048 --- /dev/null +++ b/javascript/test/beard_test.js @@ -0,0 +1,38 @@ +const beardExamples = require('../../shared/example_beards.json'); + +function hasABeard(facial_hair_over_limit, on_or_below_chin, uninterrupted_below_nose) { + return facial_hair_over_limit && (on_or_below_chin || uninterrupted_below_nose); +} + +const beardData = beardExamples.map(function(beard){ + let data = {} + data.facial_hair_over_limit = beard.facial_hair_over_5mm + data.on_or_below_chin = beard.facial_hair_on_or_below_chin + data.uninterrupted_below_nose = beard.facial_hair_uninterrupted + data.outcome = beard.outcome + return(data) +}) + +let passed_tests = []; +let failed_tests = []; + +beardData.forEach(function(beard){ + let result = hasABeard(beard.facial_hair_over_limit, beard.on_or_below_chin, beard.uninterrupted_below_nose); + if(String(result) == String(beard.outcome)){ + console.log("✅") + passed_tests.push(beard) + } else { + console.log("❌") + failed_tests.push(beard) + } +}) + +console.log(passed_tests.length + ' tests passed') +console.log(failed_tests.length + ' tests failed') + +failed_tests.forEach(function(test){ + console.log('Failed this beard:') + console.log(test) +}); + +// console.log(beardExamples);