Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Added some javascript stuff with QUnit browser tests. #22

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions javascript/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# JavaScript beard checker

To see the tests run in your browser, enter `file:///<file directory>/javascript/tests.html` in the url bar.

``` bash
npm install
npm install -g qunit
qunit
```
38 changes: 38 additions & 0 deletions javascript/test/beard_test.js
Original file line number Diff line number Diff line change
@@ -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);
39 changes: 39 additions & 0 deletions javascript/tests.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Beard Checker</title>
<link rel="stylesheet" href="https://code.jquery.com/qunit/qunit-2.9.2.css">
<script src="https://code.jquery.com/qunit/qunit-2.9.2.js"></script>
<script src="../beard_checker.js"></script>
<script src="tests.js"></script>
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture"></div>
<script>
QUnit.test( "Is the length more than or equal to 5mm?", function ( assert ) {
var length_in_mm = 3;
assert.equal( length_in_mm>=5, false, "Less than 5mm");
var length_in_mm = 5;
assert.equal( length_in_mm>=5, true, "Equal to 5mm");
var length_in_mm = 7;
assert.equal( length_in_mm>=5, true, "More than 5mm");
});

QUnit.test( "Is is on or below chin?", function ( assert ) {
var on_or_below_chin = false;
assert.equal( on_or_below_chin, false, "Doesn't occur on chin or below chin");
var on_or_below_chin = true;
assert.equal( on_or_below_chin, true, "On or below chin");
});

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;
assert.equal( unbroken_between_ears, true, "Unbroken between ears");
});
</script>
</body>
</html>