Last active
February 7, 2017 06:45
-
-
Save cmstead/6547be46df5a92dbfa5f7b7989bcd701 to your computer and use it in GitHub Desktop.
Simple UI test runner for stats example program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var testRunner = (function () { | |
'use strict'; | |
function isMatch (expectedValue, actualValue) { | |
var equalMatch = expectedValue === actualValue; | |
var NaNMatch = Number.isNaN(expectedValue) && Number.isNaN(actualValue); | |
return equalMatch || NaNMatch; | |
} | |
function testUi(sample, expectedMean, expectedStandardDeviation) { | |
document.getElementById('sample').value = sample.join(', '); | |
document.getElementById('compute').click(); | |
var mean = parseFloat(document.getElementById('mean').innerText); | |
var standardDeviation = parseFloat(document.getElementById('standard-deviation').innerText); | |
if(!isMatch(mean, expectedMean)) { | |
throw new Error('Expected mean value of ' + expectedMean + ' but got ' + mean); | |
} | |
if(!isMatch(standardDeviation, expectedStandardDeviation)) { | |
throw new Error('Expected standard deviation value of ' + expectedStandardDeviation + ' but got ' + standardDeviation); | |
} | |
return 'Test passed without error'; | |
} | |
return { | |
testUi: testUi | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment