|
/** |
|
* The winners are: |
|
* testWithOrAndRepeatedVariables - Winner for testing if a string IS a particular value |
|
* testWithoutAndAndRepeatedVariables - Winner for testing if a string IS NOT a particular value |
|
*/ |
|
|
|
function testWithOrAndOneVariable(str) |
|
{ |
|
if(str === 'bar' || 'quz' || 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
// Winner for testing if a string IS a particular value |
|
function testWithOrAndRepeatedVariables(str) |
|
{ |
|
if(str === 'bar' || str === 'quz' || str === 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
function testWithAndAndOneVariable(str) |
|
{ |
|
if(str === 'bar' && 'quz' && 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
function testWithAndAndRepeatedVariables(str) |
|
{ |
|
if(str === 'bar' && str === 'quz' && str === 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
function testWithoutOrAndOneVariable(str) |
|
{ |
|
if(str !== 'bar' || 'quz' || 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
function testWithoutOrAndRepeatedVariables(str) |
|
{ |
|
if(str !== 'bar' || str !== 'quz' || str !== 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
function testWithoutAndAndOneVariable(str) |
|
{ |
|
if(str !== 'bar' && 'quz' && 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
// Winner for testing if a string IS NOT a particular value |
|
function testWithoutAndAndRepeatedVariables(str) |
|
{ |
|
if(str !== 'bar' && str !== 'quz' && str !== 'dog') |
|
{ |
|
return true; |
|
} |
|
else |
|
{ |
|
return false; |
|
} |
|
} |
|
|
|
var output = ''; |
|
|
|
function test(expected, actual, name) |
|
{ |
|
var name = name || test.caller.name; |
|
if(expected === actual) |
|
{ |
|
output += '<p>PASS: "'+actual+' - called by '+name+'"</p>' |
|
$('.output').html(output); |
|
} |
|
else |
|
{ |
|
output += '<p>FAIL: "'+'expected: '+expected+', actual: '+actual+' - called by '+name+'"</p>'; |
|
$('.output').html(output); |
|
} |
|
} |
|
|
|
test(false, testWithOrAndOneVariable('foo'), 'testWithOrAndOneVariable'); |
|
test(false, testWithOrAndRepeatedVariables('foo'), 'testWithOrAndRepeatedVariables'); |
|
test(false, testWithAndAndOneVariable('foo'), 'testWithAndAndOneVariable'); |
|
test(false, testWithAndAndRepeatedVariables('foo'), 'testWithAndAndRepeatedVariables'); |
|
|
|
test(true, testWithOrAndOneVariable('bar'), 'testWithOrAndOneVariable'); |
|
test(true, testWithOrAndRepeatedVariables('bar'), 'testWithOrAndRepeatedVariables'); |
|
test(true, testWithAndAndOneVariable('bar'), 'testWithAndAndOneVariable'); |
|
test(true, testWithAndAndRepeatedVariables('bar'), 'testWithAndAndRepeatedVariables'); |
|
|
|
test(true, testWithOrAndOneVariable('quz'), 'testWithOrAndOneVariable'); |
|
test(true, testWithOrAndRepeatedVariables('quz'), 'testWithOrAndRepeatedVariables'); |
|
test(true, testWithAndAndOneVariable('quz'), 'testWithAndAndOneVariable'); |
|
test(true, testWithAndAndRepeatedVariables('quz'), 'testWithAndAndRepeatedVariables'); |
|
|
|
test(true, testWithOrAndOneVariable('dog'), 'testWithOrAndOneVariable'); |
|
test(true, testWithOrAndRepeatedVariables('dog'), 'testWithOrAndRepeatedVariables'); |
|
test(true, testWithAndAndOneVariable('dog'), 'testWithAndAndOneVariable'); |
|
test(true, testWithAndAndRepeatedVariables('dog'), 'testWithAndAndRepeatedVariables'); |
|
|
|
test(true, testWithoutOrAndOneVariable('foo'), 'testWithoutOrAndOneVariable'); |
|
test(true, testWithoutOrAndRepeatedVariables('foo'), 'testWithoutOrAndRepeatedVariables'); |
|
test(true, testWithoutAndAndOneVariable('foo'), 'testWithoutAndAndOneVariable'); |
|
test(true, testWithoutAndAndRepeatedVariables('foo'), 'testWithoutAndAndRepeatedVariables'); |
|
|
|
test(false, testWithoutOrAndOneVariable('bar'), 'testWithoutOrAndOneVariable'); |
|
test(false, testWithoutOrAndRepeatedVariables('bar'), 'testWithoutOrAndRepeatedVariables'); |
|
test(false, testWithoutAndAndOneVariable('bar'), 'testWithoutAndAndOneVariable'); |
|
test(false, testWithoutAndAndRepeatedVariables('bar'), 'testWithoutAndAndRepeatedVariables'); |
|
|
|
test(false, testWithoutOrAndOneVariable('quz'), 'testWithoutOrAndOneVariable'); |
|
test(false, testWithoutOrAndRepeatedVariables('quz'), 'testWithoutOrAndRepeatedVariables'); |
|
test(false, testWithoutAndAndOneVariable('quz'), 'testWithoutAndAndOneVariable'); |
|
test(false, testWithoutAndAndRepeatedVariables('quz'), 'testWithoutAndAndRepeatedVariables'); |
|
|
|
test(false, testWithoutOrAndOneVariable('dog'), 'testWithoutOrAndOneVariable'); |
|
test(false, testWithoutOrAndRepeatedVariables('dog'), 'testWithoutOrAndRepeatedVariables'); |
|
test(false, testWithoutAndAndOneVariable('dog'), 'testWithoutAndAndOneVariable'); |
|
test(false, testWithoutAndAndRepeatedVariables('dog'), 'testWithoutAndAndRepeatedVariables'); |
|
|
|
/* |
|
Output: |
|
|
|
FAIL: "expected: false, actual: true - called by testWithOrAndOneVariable" |
|
|
|
PASS: "false - called by testWithOrAndRepeatedVariables" |
|
|
|
PASS: "false - called by testWithAndAndOneVariable" |
|
|
|
PASS: "false - called by testWithAndAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithOrAndOneVariable" |
|
|
|
PASS: "true - called by testWithOrAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithAndAndOneVariable" |
|
|
|
FAIL: "expected: true, actual: false - called by testWithAndAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithOrAndOneVariable" |
|
|
|
PASS: "true - called by testWithOrAndRepeatedVariables" |
|
|
|
FAIL: "expected: true, actual: false - called by testWithAndAndOneVariable" |
|
|
|
FAIL: "expected: true, actual: false - called by testWithAndAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithOrAndOneVariable" |
|
|
|
PASS: "true - called by testWithOrAndRepeatedVariables" |
|
|
|
FAIL: "expected: true, actual: false - called by testWithAndAndOneVariable" |
|
|
|
FAIL: "expected: true, actual: false - called by testWithAndAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithoutOrAndOneVariable" |
|
|
|
PASS: "true - called by testWithoutOrAndRepeatedVariables" |
|
|
|
PASS: "true - called by testWithoutAndAndOneVariable" |
|
|
|
PASS: "true - called by testWithoutAndAndRepeatedVariables" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndOneVariable" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndRepeatedVariables" |
|
|
|
PASS: "false - called by testWithoutAndAndOneVariable" |
|
|
|
PASS: "false - called by testWithoutAndAndRepeatedVariables" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndOneVariable" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndRepeatedVariables" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutAndAndOneVariable" |
|
|
|
PASS: "false - called by testWithoutAndAndRepeatedVariables" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndOneVariable" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutOrAndRepeatedVariables" |
|
|
|
FAIL: "expected: false, actual: true - called by testWithoutAndAndOneVariable" |
|
|
|
PASS: "false - called by testWithoutAndAndRepeatedVariables" |
|
|
|
*/ |
Also on jsFiddle: http://jsfiddle.net/jasdeepkhalsa/brja2r6f/