Created
March 24, 2014 22:04
-
-
Save 32bitkid/9750224 to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<script src="http://jashkenas.github.io/underscore/underscore-min.js"></script> | |
<link href="http://code.jquery.com/qunit/qunit-git.css" rel="stylesheet" type="text/css" /> | |
<script src="http://code.jquery.com/qunit/qunit-git.js"></script> | |
<meta charset="utf-8"> | |
<title>JS Bin</title> | |
</head> | |
<body> | |
<div id="qunit"></div> | |
<div id="qunit-fixture"></div> | |
</body> | |
</html> |
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
// FizzBuzz | |
var isDivisibleBy = _.constant(false) | |
var isFizz = _.constant(false); | |
var isBuzz = _.constant(false); | |
var isFizzBuzz = _.constant(false); | |
var transform = _.constant(undefined); | |
var play = _.constant([]); | |
// isDivisibleBy(a,b) -> is 'b' is evenly divisible by 'a' | |
test("isDivisibleBy", function() { | |
equal(isDivisibleBy(5,10), true); | |
equal(isDivisibleBy(3,6), true); | |
equal(isDivisibleBy(4,9), false); | |
}); | |
// isFizz(a) -> is 'a' a fizz | |
test("isFizz()", function() { | |
equal(isFizz(1), false); | |
equal(isFizz(3), true); | |
equal(isFizz(5), false); | |
equal(isFizz(15), true); | |
}); | |
// isBuzz(b) -> is 'a' a buzz | |
test("isBuzz()", function() { | |
ok(!isBuzz(1)); | |
ok(!isBuzz(3)); | |
ok(isBuzz(5)); | |
ok(isBuzz(15)); | |
}); | |
// isFizzBuzz(a) -> is 'a' a fizzbuzz | |
test("isFizzBuzz()", function() { | |
ok(!isFizzBuzz(1)); | |
ok(!isFizzBuzz(3)); | |
ok(!isFizzBuzz(5)); | |
ok(isFizzBuzz(15)); | |
}); | |
// transform(a) -> transform 'a' into FizzBuzz value | |
test("transform should work right", function() { | |
equal(transform(1), 1); | |
equal(transform(3), "Fizz"); | |
equal(transform(5), "Buzz"); | |
equal(transform(150), "FizzBuzz"); | |
}) | |
// play(a) -> play 'a' rounds of FizzBuzz | |
test("Play a game to twenty", function() { | |
var expected, result; | |
expected = [1, 2, "Fizz", 4, "Buzz", "Fizz", 7, 8, "Fizz", "Buzz", 11, "Fizz", 13, 14, "FizzBuzz", 16, 17, "Fizz", 19, "Buzz"]; | |
result = play(20); | |
deepEqual(result, expected); | |
expected = [1, 2, "Fizz", 4, "Buzz", "Fizz"]; | |
result = play(6); | |
deepEqual(result, expected); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment