Skip to content

Instantly share code, notes, and snippets.

@greghelton
Last active July 2, 2016 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greghelton/3ba87c58d27f7ad95c7da146d4fe8d75 to your computer and use it in GitHub Desktop.
Save greghelton/3ba87c58d27f7ad95c7da146d4fe8d75 to your computer and use it in GitHub Desktop.
var expect = require('chai').expect;
var isPalindrome = require('../src/ispalindrome');
describe('palindrome-test', function() {
it('should pass this canary test', function() {
expect(true).to.be.true;
});
it('should return true for argument mom', function() {
expect(isPalindrome('mom')).to.be.true;
});
it('should return true for argument dad', function() {
expect(isPalindrome('dad')).to.be.true;
});
it('should return false for argument dude', function() {
expect(isPalindrome('dude')).to.be.false;
});
it ('should throw an exception when argument is missing', function() {
var call = function() { isPalindrome() }
expect(call).to.throw(Error, 'Invalid Argument');
});
it('should return true for argument mom mom', function() {
expect(isPalindrome('mom mom')).to.be.true;
});
it('should return false for argument mom dad', function() {
expect(isPalindrome('mom dad')).to.be.false;
});
});
module.exports = function(phrase) {
if (phrase === undefined) {
throw new Error('Invalid Argument');
}
return phrase.trim().length > 0 &&
phrase.split('').reverse().join('') === phrase;
}
{
"name": "palindrome",
"version": "1.0.0",
"description": "",
"main": "index.js",
"directories": {
"test": "test"
},
"scripts": {
"test": "mocha test",
"node": "node_modules/istanbul/lib/cli.js cover node_modules/mocha/bin/_mocha"
},
"author": "Greg Helton",
"license": "ISC",
"devDependencies": {
"chai": "^3.5.0",
"istanbul": "^0.4.2",
"mocha": "^2.4.5"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment