Skip to content

Commit

Permalink
Add some string related tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pete-the-pete authored and jamesplease committed Aug 1, 2015
1 parent aac8e18 commit e8e2c44
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"numbersAnswers",
"objectsAnswers",
"recursionAnswers",
"regexAnswers"
"regexAnswers",
"stringsAnswers"
]
}
13 changes: 13 additions & 0 deletions app/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
exports = (typeof window === 'undefined') ? global : window;

exports.stringsAnswers = {
reduceString: function(str, amount) {

},
wordWrap: function(str, cols) {

},
reverseString: function(str) {

}
};
51 changes: 51 additions & 0 deletions tests/app/strings.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
if ( typeof window === 'undefined' ) {
require('../../app/strings');
var expect = require('chai').expect;
}

describe('strings', function() {
it('you should be able to reduce duplicate characters to a desired minimum', function() {
expect(stringsAnswers.reduceString('aaaabbbb', 2)).to.eql('aabb');
expect(stringsAnswers.reduceString('xaaabbbb', 2)).to.eql('xaabb');
expect(stringsAnswers.reduceString('aaaabbbb', 1)).to.eql('ab');
expect(stringsAnswers.reduceString('aaxxxaabbbb', 2)).to.eql('aaxxaabb');
});

it('you should be able to wrap lines at a given number of columns, without breaking words', function() {
var wrapCol = 5;
var inputStrings = [
'abcdef abcde abc def',
'abc abc abc',
'a b c def'
];
var outputStrings = [
'abcdef\nabcde\nabc\ndef',
'abc\nabc\nabc',
'a b c\ndef'
];
var formattedStr;

inputStrings.forEach(function(str, index) {
formattedStr = stringsAnswers.wordWrap(str, wrapCol);
expect(formattedStr).to.eql(outputStrings[index]);
});
});

it('you should be able to reverse a string', function() {
var inputStrings = [
'abc',
'i am a string of characters',
'A man, a plan, a canal: Panama'
];
var outputStrings = [
'cba',
'sretcarahc fo gnirts a ma i',
'amanaP :lanac a ,nalp a ,nam A'
];

inputStrings.forEach(function(str, index) {
var result = stringsAnswers.reverseString(str);
expect(result).to.eql(outputStrings[index]);
});
});
});
2 changes: 2 additions & 0 deletions tests/runner.html
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@
<script src="/app/recursion.js"></script>
<script src="/tests/app/regex.js"></script>
<script src="/app/regex.js"></script>
<script src="/tests/app/strings.js"></script>
<script src="/app/strings.js"></script>

<!-- livereload snippet -->
<script src="http://localhost:35729/livereload.js"></script>
Expand Down

0 comments on commit e8e2c44

Please sign in to comment.