Created
April 30, 2014 16:53
-
-
Save lrvick/d634353231d61ce898de to your computer and use it in GitHub Desktop.
Pig Latin Translator / Mocha example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var assert = require("assert") | |
var pigLatinTrans = function(text){ | |
var pigText = text.replace(/[A-Za-z]+/gi,function(word){ | |
var letters = word.split('') | |
var firstLetter = letters.shift() | |
if (firstLetter.toUpperCase() == firstLetter){ | |
letters.push(firstLetter.toLowerCase()) | |
letters[0] = letters[0].toUpperCase() | |
letters.push(firstLetter) | |
} | |
return letters.join('') + 'ay' | |
}) | |
return pigText | |
} | |
describe("PigLatinTrans",function(){ | |
describe("pigLatinTrans",function(){ | |
it('can take phrase "hello" and see it translated to Pig Latin "ellohay"',function(){ | |
assert.equal(pigLatinTrans("hello"),"ellohay") | |
}) | |
it('can take phrase "hello world" and see it translated to Pig Latin "ellohay orldway"',function(){ | |
assert.equal(pigLatinTrans("hello world"),"ellohay orldway") | |
}) | |
it('can take phrase "Hello world" and see it translated to Pig Latin "Ellohay orldway"', function(){ | |
assert.equal(pigLatinTrans("Hello world"),"Ellohay orldway") | |
}) | |
it('can take phrase "Hello, world!!" and see it translated to Pig Latin "Ellohay, orldway!!"', function(){ | |
assert.equal(pigLatinTrans("Hello, world!!"),"Ellohay, orldway!!") | |
}) | |
it('can take phrase "eat apples" and see it translated to Pig Latin "eatay applesay"') | |
it('can take phrase "quick brown fox" and see it translated to Pig Latin "ickquay ownbray oxfay"') | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment