From e65f224c907ab4b4a75fc1e1d90a011974553dac Mon Sep 17 00:00:00 2001 From: pete_the_pete Date: Thu, 4 Apr 2013 21:46:34 -0700 Subject: [PATCH 1/3] Adding some string related tests --- tests/app/strings.js | 60 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 tests/app/strings.js diff --git a/tests/app/strings.js b/tests/app/strings.js new file mode 100644 index 000000000..a07c222ff --- /dev/null +++ b/tests/app/strings.js @@ -0,0 +1,60 @@ +/*globals describe:true, it:true, expect:true, beforeEach:true */ +if (typeof define !== 'function') { var define = require('amdefine')(module); } +if (typeof expect !== 'function') { var expect = require('expect.js'); } + +define([ + 'app/strings' +], function(answers) { + + describe('strings', function() { + it('you should be able to reduce duplicate characters to a desired minimum', function() { + expect(answers.reduceString('aaaabbbb', 2)).to.eql('aabb'); + expect(answers.reduceString('xaaabbbb', 2)).to.eql('xaabb'); + expect(answers.reduceString('aaaabbbb', 1)).to.eql('ab'); + expect(answers.reduceString('aaxxxaabbbb', 2)).to.eql('aaxxaabb'); + }); + + it('you should be able to wrap lines at some arbitrary count, but don\'t break words', function() { + //create the data + var formatted_str; + var data = [ + 'abcdef abcde abc def', + 'abc abc abc', + 'a b c def' + ]; + var wrap_col = 5; + + var computed_data = [ + 'abcdef\nabcde\nabc\ndef', + 'abc\nabc\nabc', + 'a b c\ndef' + ]; + + + data.forEach(function(str, index) { + formatted_str = answers.wordwrap(str, wrap_col); + //every char at the wrap line should be a space + expect(formatted_str).to.eql(computed_data[index]); + //the last characters should still be the last characters + expect(formatted_str.charAt(formatted_str.length-1)).to.eql(computed_data[index].charAt(computed_data[index].length-1)); + }); + + }); + it('you should be able to reverse a string', function() { + var data = [ + 'abc', + 'i am a string of characters', + 'A man, a plan, a canal: Panama' + ]; + + data.forEach(function(str) { + var result = answers.reverseString(str); + //should be same length + expect(result.length).to.eql(str.length); + //middle character should be the same + var mid = Math.floor(result.length); + expect(result.charAt(mid)).to.eql(str.charAt(mid)); + }); + }); + }); +}); \ No newline at end of file From 97dc2e28c47d5073ae583a9fdb8007adcffc642c Mon Sep 17 00:00:00 2001 From: pete_the_pete Date: Sun, 23 Jun 2013 11:10:42 -0700 Subject: [PATCH 2/3] Updated formatting to camelCase to be inline with rest of repo --- tests/app/strings.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/app/strings.js b/tests/app/strings.js index a07c222ff..7211b90ec 100644 --- a/tests/app/strings.js +++ b/tests/app/strings.js @@ -16,15 +16,15 @@ define([ it('you should be able to wrap lines at some arbitrary count, but don\'t break words', function() { //create the data - var formatted_str; + var formattedStr; var data = [ 'abcdef abcde abc def', 'abc abc abc', 'a b c def' ]; - var wrap_col = 5; + var wrapCol = 5; - var computed_data = [ + var computedData = [ 'abcdef\nabcde\nabc\ndef', 'abc\nabc\nabc', 'a b c\ndef' @@ -32,11 +32,11 @@ define([ data.forEach(function(str, index) { - formatted_str = answers.wordwrap(str, wrap_col); + formattedStr = answers.wordWrap(str, wrapCol); //every char at the wrap line should be a space - expect(formatted_str).to.eql(computed_data[index]); + expect(formattedStr).to.eql(computedData[index]); //the last characters should still be the last characters - expect(formatted_str.charAt(formatted_str.length-1)).to.eql(computed_data[index].charAt(computed_data[index].length-1)); + expect(formattedStr.charAt(formattedStr.length-1)).to.eql(computedData[index].charAt(computedData[index].length-1)); }); }); @@ -57,4 +57,4 @@ define([ }); }); }); -}); \ No newline at end of file +}); From 78a359f361c720080c752b79ca643ed6c014f653 Mon Sep 17 00:00:00 2001 From: pete_the_pete Date: Sun, 23 Jun 2013 12:08:16 -0700 Subject: [PATCH 3/3] Added the forgotten stubs --- app/strings.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 app/strings.js diff --git a/app/strings.js b/app/strings.js new file mode 100644 index 000000000..fc3a8b997 --- /dev/null +++ b/app/strings.js @@ -0,0 +1,12 @@ +if (typeof define !== 'function') { var define = require('amdefine')(module); } + +define(function() { + return { + reduceString: function(str, amount) { + }, + wordWrap: function(str, cols) { + }, + reverseString: function(str) { + } +} +});