/*
* ut_findOdd is a unit test for findOdd.js
* @requires jquery
* @requires jqUnit
* @author Adam Eivy
*/
var ut_findOdd = function() {
/*
* configure the test
*/
var testName = 'findOdd'; // name of the test
var testExpect = 2; // we will test 2 parts of each function return
/*
* testSet defines a list of arguments and expected outputs to run through
*
*/
var testSet = [
{
arg: [1,17,2,2,3,1],
exp: {
success: true,
items: [3,17]
}
},{
arg: [3,1,2,2],
exp: {
success: true,
items: ['1','3']
}
},{
arg: [1,1],
exp: {
success: false,
items: []
}
},{
arg: [],
exp: {
success: false,
items: []
}
}
];
var val = {}; // the return value for each test
var set = {}; // the test set currently being run
var success = false; // whether the test reported success or not
var n = 0; // a counter to keep track of the current test globally
with (jqUnit) {
module(testName); // name this test
for(var i=0;i<testSet.length;i++) {
test('test '+(i+1) + ': '+testName+'( ['+testSet[i].arg+'] )', function(){
set = testSet[n]; // shorten
expect(testExpect); // there will be this many assertions to test (no more, no less)
// run the test
val = findOdd(set.arg);
// prepare the success value for the expected assertion
success = set.exp.success ? val.success : !val.success;
// run assertions againsts the output
ok(success,val.error || 'pass: '+val.items);
isSet(val.items,set.exp.items, 'pass');
// increment global tracker for test set number
n++;
});
}
}
}(jQuery);