Skip to content

Instantly share code, notes, and snippets.

@tcz
Created July 8, 2012 22:14
Show Gist options
  • Save tcz/3073145 to your computer and use it in GitHub Desktop.
Save tcz/3073145 to your computer and use it in GitHub Desktop.
ROT13 Javascript BDD example with Jasmine
function rot13( text )
{
var results = [];
var charcode;
for ( var i = 0; i < text.length; ++i )
{
charcode = text.charCodeAt( i );
if ( charcode < 65 || charcode > 90 )
{
throw new Error( 'Gooby pls' );
}
charcode = 65 + ( charcode + 13 - 65 ) % 26;
results.push( String.fromCharCode( charcode ) );
}
return results.join('');
}
describe("ROT13 encoding", function()
{
it( "should encode normal text", function()
{
expect( rot13( "TEST" ) ).toEqual( "GRFG" );
} );
it( "should fail for special characters", function()
{
expect( function()
{
return rot13( "$*=" );
} ).toThrow();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment