Skip to content

Instantly share code, notes, and snippets.

@valbaca
Created July 7, 2013 03:10
Show Gist options
  • Save valbaca/5942126 to your computer and use it in GitHub Desktop.
Save valbaca/5942126 to your computer and use it in GitHub Desktop.
// readable solution
var TestTester = exports;
TestTester.run = function(string) {
var good = 'Good test data'
, bad = 'Mismatch! Bad test data'
, splitString = string.split(' ')
, output = bad
if (splitString[0] === '0') {
output = ( isMirrors(splitString[1], splitString[2]) ? good : bad )
} else if (splitString[0] === '1') {
output = ( isAllCaps(splitString[1], splitString[2]) ? good : bad )
}
return output
}
var isMirrors = function(first, second) {
var mirror = function (string) {
var splitString = string.split('')
, mirror = ''
for (var i = 0, len = splitString.length; i < len; ++i) {
mirror = splitString[i] + mirror
}
return mirror
}
return first && second && mirror(first) === second
}
var isAllCaps = function(first, second) {
return first && second && first.toUpperCase() === second
}
var assert = require('assert')
var TestTester = require('../scripts/TestTester.js')
describe('TestTester', function() {
describe('#run()', function() {
it('should return "Good test data" if type is 0 and strings are mirrors', function() {
assert.equal('Good test data', TestTester.run('0 Car raC'))
assert.equal('Good test data', TestTester.run('0 01234 43210'))
})
it('should return "Mismatch! Bad test data" if type is 0 and strings are not mirrors', function() {
assert.equal('Mismatch! Bad test data', TestTester.run('0 Alpha AhplA'))
assert.equal('Mismatch! Bad test data', TestTester.run('0 Discuss noissucsiD'))
})
it('should return "Good test data" if type is 1 and second string is the first in all caps', function() {
assert.equal('Good test data', TestTester.run('1 Batman BATMAN'))
assert.equal('Good test data', TestTester.run('1 Graph GRAPH'))
})
it('should return "Mismatch! Bad test data" if type is 1 and second string is not the first in all caps', function() {
assert.equal('Mismatch! Bad test data', TestTester.run('1 One one'))
assert.equal('Mismatch! Bad test data', TestTester.run('1 two three'))
})
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment