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

Commit ccbf44c

Browse files
committed
Final touch-ups to string tests.
1 parent 6250b55 commit ccbf44c

File tree

2 files changed

+20
-23
lines changed

2 files changed

+20
-23
lines changed

app/strings.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ if (typeof define !== 'function') { var define = require('amdefine')(module); }
33
define(function() {
44
return {
55
reduceString: function(str, amount) {
6+
67
},
78
wordWrap: function(str, cols) {
9+
810
},
911
reverseString: function(str) {
12+
1013
}
11-
}
14+
};
1215
});

tests/app/strings.js

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ if (typeof expect !== 'function') { var expect = require('expect.js'); }
55
define([
66
'app/strings'
77
], function(answers) {
8-
98
describe('strings', function() {
109
it('you should be able to reduce duplicate characters to a desired minimum', function() {
1110
expect(answers.reduceString('aaaabbbb', 2)).to.eql('aabb');
@@ -14,46 +13,41 @@ define([
1413
expect(answers.reduceString('aaxxxaabbbb', 2)).to.eql('aaxxaabb');
1514
});
1615

17-
it('you should be able to wrap lines at some arbitrary count, but don\'t break words', function() {
18-
//create the data
19-
var formattedStr;
20-
var data = [
16+
it('you should be able to wrap lines at a given number of columns, without breaking words', function() {
17+
var wrapCol = 5;
18+
var inputStrings = [
2119
'abcdef abcde abc def',
2220
'abc abc abc',
2321
'a b c def'
2422
];
25-
var wrapCol = 5;
26-
27-
var computedData = [
23+
var outputStrings = [
2824
'abcdef\nabcde\nabc\ndef',
2925
'abc\nabc\nabc',
3026
'a b c\ndef'
3127
];
28+
var formattedStr;
3229

33-
34-
data.forEach(function(str, index) {
30+
inputStrings.forEach(function(str, index) {
3531
formattedStr = answers.wordWrap(str, wrapCol);
36-
//every char at the wrap line should be a space
37-
expect(formattedStr).to.eql(computedData[index]);
38-
//the last characters should still be the last characters
39-
expect(formattedStr.charAt(formattedStr.length-1)).to.eql(computedData[index].charAt(computedData[index].length-1));
32+
expect(formattedStr).to.eql(outputStrings[index]);
4033
});
41-
4234
});
35+
4336
it('you should be able to reverse a string', function() {
44-
var data = [
37+
var inputStrings = [
4538
'abc',
4639
'i am a string of characters',
4740
'A man, a plan, a canal: Panama'
4841
];
42+
var outputStrings = [
43+
'cba',
44+
'sretcarahc fo gnirts a ma i',
45+
'amanaP :lanac a ,nalp a ,nam A'
46+
];
4947

50-
data.forEach(function(str) {
48+
inputStrings.forEach(function(str, index) {
5149
var result = answers.reverseString(str);
52-
//should be same length
53-
expect(result.length).to.eql(str.length);
54-
//middle character should be the same
55-
var mid = Math.floor(result.length);
56-
expect(result.charAt(mid)).to.eql(str.charAt(mid));
50+
expect(result).to.eql(outputStrings[index]);
5751
});
5852
});
5953
});

0 commit comments

Comments
 (0)