This repository was archived by the owner on Jul 4, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2k
Some String tests #66
Closed
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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) { | ||
| } | ||
| } | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 formattedStr; | ||
| var data = [ | ||
| 'abcdef abcde abc def', | ||
| 'abc abc abc', | ||
| 'a b c def' | ||
| ]; | ||
| var wrapCol = 5; | ||
|
|
||
| var computedData = [ | ||
| 'abcdef\nabcde\nabc\ndef', | ||
| 'abc\nabc\nabc', | ||
| 'a b c\ndef' | ||
| ]; | ||
|
|
||
|
|
||
| data.forEach(function(str, index) { | ||
| formattedStr = answers.wordWrap(str, wrapCol); | ||
| //every char at the wrap line should be a space | ||
| expect(formattedStr).to.eql(computedData[index]); | ||
| //the last characters should still be the last characters | ||
| expect(formattedStr.charAt(formattedStr.length-1)).to.eql(computedData[index].charAt(computedData[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)); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The variable |
||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this check necessary? Seems like the equality check above should be sufficient.