Skip to content

Instantly share code, notes, and snippets.

@cmstead
Last active February 7, 2017 06:45
Show Gist options
  • Save cmstead/6547be46df5a92dbfa5f7b7989bcd701 to your computer and use it in GitHub Desktop.
Save cmstead/6547be46df5a92dbfa5f7b7989bcd701 to your computer and use it in GitHub Desktop.
Simple UI test runner for stats example program
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