Added test cases

This commit is contained in:
Matthew-Cravinhos
2017-09-20 19:04:46 -04:00
parent f72bdd2ee3
commit 6012c3a095
17 changed files with 452 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
This exercise is meant to (loosely) simulate the game Simon Says. The goal of this program in order is:
Echo the value given,
Capitalize the value given,
Repeat the value given,
Return a piece of the value given,
Return the first word of the value given,
Create a title with the value given
See Jasmine test cases for expected results.
+37
View File
@@ -0,0 +1,37 @@
function echo() {
}
function shout() {
}
function repeat() {
}
function pieceOfWord() {
}
function firstWord() {
}
function capitalize(word) {
return word.charAt(0).toUpperCase() + word.slice(1);
// This function just capitalizes the word given to it, use in conjunction with titleCreator
}
function titleCreator() {
}
module.exports = {
echo,
shout,
repeat,
pieceOfWord,
firstWord,
titleCreator
}
+78
View File
@@ -0,0 +1,78 @@
var simon = require ('./simonSays.js');
describe('Simon says', function() {
describe('echo', function() {
it('should echo hello', function() {
expect(simon.echo("hello")).toEqual("hello");
});
it('should echo bye', function() {
expect(simon.echo("bye")).toEqual("bye")
});
});
describe('shout', function() {
it('should shout hello', function() {
expect(simon.shout("hello")).toEqual("HELLO");
});
it('should shout multiple words', function() {
expect(simon.shout("hello world")).toEqual("HELLO WORLD");
});
});
describe('repeat', function() {
it('should repeat', function() {
expect(simon.repeat("hello")).toEqual("hello hello");
});
it('should repeat a number of times', function() {
expect(simon.repeat("hello",3)).toEqual("hello hello hello");
});
});
describe('pieceOfWord', function() {
it('returns the first letter', function() {
expect(simon.pieceOfWord("hello", 1)).toEqual("h");
});
it('returns the first two letters', function() {
expect(simon.pieceOfWord("Bob", 2)).toEqual("Bo");
});
it('returns the first several letters', function() {
var s = "abcdefg";
expect(simon.pieceOfWord(s, 1)).toEqual("a");
expect(simon.pieceOfWord(s, 2)).toEqual("ab");
expect(simon.pieceOfWord(s, 3)).toEqual("abc");
});
});
describe('firstWord', function() {
it('tells us the first word of "Hello World" is "Hello"', function() {
expect(simon.firstWord("Hello World")).toEqual("Hello");
});
it('tells us the first word of "oh dear" is "oh"', function() {
expect(simon.firstWord("oh dear")).toEqual("oh");
});
});
describe('titleCreator', function() {
it('capitalizes a word', function() {
expect(simon.titleCreator("jaws")).toEqual("Jaws");
});
it('capitalizes every word (aka title case)', function() {
expect(simon.titleCreator("david copperfield")).toEqual("David Copperfield");
});
it("doesn't capitalize 'little words' in a title", function() {
expect(simon.titleCreator("war and peace")).toEqual("War and Peace");
});
it('does capitalize "little words" at the start of a title', function() {
expect(simon.titleCreator("the bridge over the river kwai")).toEqual("The Bridge over the River Kwai");
});
});
});