Skip to content

Instantly share code, notes, and snippets.

@yuxel
Created July 6, 2011 15:32
Show Gist options
  • Save yuxel/1067529 to your computer and use it in GitHub Desktop.
Save yuxel/1067529 to your computer and use it in GitHub Desktop.
Jasmine
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Jasmine Test Runner</title>
<link rel="stylesheet" type="text/css" href="lib/jasmine-1.0.2/jasmine.css">
<script type="text/javascript" src="lib/jasmine-1.0.2/jasmine.js"></script>
<script type="text/javascript" src="lib/jasmine-1.0.2/jasmine-html.js"></script>
</head>
<body>
<script type="text/javascript">
var Hoppity = function () {
};
Hoppity.prototype.getText = function (num) {
if (num) {
if (num % 5 == 0 && num % 3 == 0){
return "Hop";
}
if(num % 3 == 0) {
return "Hoppity";
}
if(num % 5 == 0) {
return "Hophop";
}
}
};
//-------------------------
describe("Hoppity Hop puzzle", function () {
var hoppity;
beforeEach(function (){
hoppity = new Hoppity();
});
describe("For integers that are evenly divisible by three, output the exact string Hoppity", function () {
it("should return Hoppity with 3", function (){
var result = hoppity.getText(3);
expect(result).toEqual("Hoppity");
});
it("should return Hoppity with 6", function (){
var result = hoppity.getText(6);
expect(result).toEqual("Hoppity");
});
it("should not return Hoppity with 7", function (){
var result = hoppity.getText(7);
expect(result).not.toEqual("Hoppity");
});
it("should return Hoppity with 99", function (){
var result = hoppity.getText(99);
expect(result).toEqual("Hoppity");
});
});
describe("For integers that are evenly divisible by five, output the exact string Hophop", function (){
it("should return Hophop with 5", function (){
var result = hoppity.getText(5);
expect(result).toEqual("Hophop");
});
});
describe("For integers that are evenly divisible by both three and five, do not do any of the above, but instead output the exact string Hop", function (){
it("should return Hop with 15", function (){
var result = hoppity.getText(15);
expect(result).toEqual("Hop");
});
});
describe("For zero it should return nothing", function (){
it("should return falsy for 0", function (){
var result = hoppity.getText(0);
expect(result).toBeFalsy();
});
});
});
//run written suites
jasmine.getEnv()['addReporter'](new jasmine.TrivialReporter());
jasmine.getEnv()['execute']();
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment