Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 0303e8c

Browse files
Merge pull request #102 from rmurphey/string-tests
add String tests
2 parents aac8e18 + e8e2c44 commit 0303e8c

File tree

4 files changed

+68
-1
lines changed

4 files changed

+68
-1
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"numbersAnswers",
4040
"objectsAnswers",
4141
"recursionAnswers",
42-
"regexAnswers"
42+
"regexAnswers",
43+
"stringsAnswers"
4344
]
4445
}

app/strings.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
exports = (typeof window === 'undefined') ? global : window;
2+
3+
exports.stringsAnswers = {
4+
reduceString: function(str, amount) {
5+
6+
},
7+
wordWrap: function(str, cols) {
8+
9+
},
10+
reverseString: function(str) {
11+
12+
}
13+
};

tests/app/strings.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
if ( typeof window === 'undefined' ) {
2+
require('../../app/strings');
3+
var expect = require('chai').expect;
4+
}
5+
6+
describe('strings', function() {
7+
it('you should be able to reduce duplicate characters to a desired minimum', function() {
8+
expect(stringsAnswers.reduceString('aaaabbbb', 2)).to.eql('aabb');
9+
expect(stringsAnswers.reduceString('xaaabbbb', 2)).to.eql('xaabb');
10+
expect(stringsAnswers.reduceString('aaaabbbb', 1)).to.eql('ab');
11+
expect(stringsAnswers.reduceString('aaxxxaabbbb', 2)).to.eql('aaxxaabb');
12+
});
13+
14+
it('you should be able to wrap lines at a given number of columns, without breaking words', function() {
15+
var wrapCol = 5;
16+
var inputStrings = [
17+
'abcdef abcde abc def',
18+
'abc abc abc',
19+
'a b c def'
20+
];
21+
var outputStrings = [
22+
'abcdef\nabcde\nabc\ndef',
23+
'abc\nabc\nabc',
24+
'a b c\ndef'
25+
];
26+
var formattedStr;
27+
28+
inputStrings.forEach(function(str, index) {
29+
formattedStr = stringsAnswers.wordWrap(str, wrapCol);
30+
expect(formattedStr).to.eql(outputStrings[index]);
31+
});
32+
});
33+
34+
it('you should be able to reverse a string', function() {
35+
var inputStrings = [
36+
'abc',
37+
'i am a string of characters',
38+
'A man, a plan, a canal: Panama'
39+
];
40+
var outputStrings = [
41+
'cba',
42+
'sretcarahc fo gnirts a ma i',
43+
'amanaP :lanac a ,nalp a ,nam A'
44+
];
45+
46+
inputStrings.forEach(function(str, index) {
47+
var result = stringsAnswers.reverseString(str);
48+
expect(result).to.eql(outputStrings[index]);
49+
});
50+
});
51+
});

tests/runner.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
<script src="/app/recursion.js"></script>
5353
<script src="/tests/app/regex.js"></script>
5454
<script src="/app/regex.js"></script>
55+
<script src="/tests/app/strings.js"></script>
56+
<script src="/app/strings.js"></script>
5557

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

0 commit comments

Comments
 (0)