-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0d9bb5
commit 27a0fe5
Showing
3 changed files
with
41 additions
and
10 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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,31 @@ | ||
// This is an example of using Canary to test some code! | ||
// Try it out with `node leftPad.js` | ||
|
||
// This library | ||
const canary = require("./canary.js"); | ||
// Node's built-in assertion library | ||
const assert = require("assert"); | ||
|
||
// A function that ought to be tested | ||
function leftPad(value, length){ | ||
let text = String(value); | ||
while(text.length < length){ | ||
text = " " + text; | ||
} | ||
return text; | ||
} | ||
|
||
// Tests written using Canary | ||
canary.group("leftPad", function(){ | ||
this.test("returns the input when it's as long as or longer than the input length", () => { | ||
assert.equal(leftPad("hello", 3), "hello"); | ||
assert.equal(leftPad("world", 5), "world"); | ||
}); | ||
this.test("pads shorter inputs with spaces to match the desired length", () => { | ||
assert.equal(leftPad("hi", 4), " hi"); | ||
assert.equal(leftPad("123", 6), " 123"); | ||
}); | ||
}); | ||
|
||
// Run the tests! | ||
canary.doReport(); |
This file contains 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