Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Kata realizada con Javascript y Jasmine #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions animalaes/fizzbuzz.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE html>
<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>

<!-- include source files here... -->
<script type="text/javascript" src="src/fizzbuzz.js"></script>

<!-- include spec files here... -->
<script type="text/javascript" src="spec/fizzbuzzSpec.js"></script>

</head>
<body>

<script type="text/javascript">
jasmine.getEnv().addReporter(new jasmine.TrivialReporter());
jasmine.getEnv().execute();
</script>

</body>
33 changes: 33 additions & 0 deletions animalaes/fizzbuzz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function FizzBuzz() {
};

FizzBuzz.prototype.fizz = "Fizz";

FizzBuzz.prototype.buzz = "Buzz";

FizzBuzz.prototype.say = function(number) {
var result = "";
if (this.isMultipleOfThree(number) || this.containsTree(number))
result += this.fizz;
if (this.isMultipleOfFive(number) || this.containsFive(number))
result += this.buzz;
if (result.length == 0)
result += number;
return result;
};

FizzBuzz.prototype.isMultipleOfThree = function(number) {
return number % 3 === 0;
};

FizzBuzz.prototype.isMultipleOfFive = function(number) {
return number % 5 === 0;
};

FizzBuzz.prototype.containsTree = function(number) {
return number.toString().indexOf('3') != -1;
};

FizzBuzz.prototype.containsFive = function(number) {
return number.toString().indexOf('5') != -1;
};
42 changes: 42 additions & 0 deletions animalaes/fizzbuzzSpec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
describe("FizzBuzz", function() {
var fizzBuzz;

beforeEach(function() {
fizzBuzz = new FizzBuzz();

});

it('should return number', function() {
expect(fizzBuzz.say(2)).toEqual('2');
expect(fizzBuzz.say(4)).toEqual('4');
expect(fizzBuzz.say(7)).toEqual('7');
expect(fizzBuzz.say(19)).toEqual('19');
});

it('should return Fizz', function() {
expect(fizzBuzz.say(3)).toEqual('Fizz');
expect(fizzBuzz.say(13)).toEqual('Fizz');
expect(fizzBuzz.say(18)).toEqual('Fizz');
expect(fizzBuzz.say(96)).toEqual('Fizz');
});

it('should return Buzz', function() {
expect(fizzBuzz.say(5)).toEqual('Buzz');
expect(fizzBuzz.say(20)).toEqual('Buzz');
expect(fizzBuzz.say(95)).toEqual('Buzz');
expect(fizzBuzz.say(100)).toEqual('Buzz');
});

it('should return FizzBuzz', function() {
expect(fizzBuzz.say(15)).toEqual('FizzBuzz');
expect(fizzBuzz.say(35)).toEqual('FizzBuzz');
expect(fizzBuzz.say(54)).toEqual('FizzBuzz');
expect(fizzBuzz.say(75)).toEqual('FizzBuzz');
expect(fizzBuzz.say(90)).toEqual('FizzBuzz');
});

for ( var x = 0; x < 101; x++) {
console.log(fizzBuzz.say(x));
}

});