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

BIN
.DS_Store vendored Normal file

Binary file not shown.

6
02_calculator/README.md Normal file
View File

@ -0,0 +1,6 @@
The goal for this exercise is to create a calculator that does the following:
add, subtract, get the sum, multiply, get the power, and find the factorial
In order to do this please fill out each function with your solution. Make sure to return the value so you can test it in Jasmine! To see the expected value
take a look at the spec file that houses the Jasmine test cases.

View File

@ -0,0 +1,32 @@
function add () {
}
function subtract () {
}
function sum () {
}
function multiply () {
}
function power() {
}
function factorial() {
}
module.exports = {
add,
subtract,
sum,
multiply,
power,
factorial
}

View File

@ -0,0 +1,77 @@
var calculator = require ('./calculator.js');
describe('add', function() {
it('adds 0 and 0', function() {
expect(calculator.add(0,0)).toEqual(0);
});
it('adds 2 and 2', function() {
expect(calculator.add(2,2)).toEqual(4);
});
it('adds positive numbers', function() {
expect(calculator.add(2,6)).toEqual(8);
});
});
describe('subtract', function() {
it('subtracts numbers', function() {
expect(calculator.subtract(10,4)).toEqual(6);
});
});
describe('sum', function() {
it('computes the sum of an empty array', function() {
expect(calculator.sum([])).toEqual(0);
});
it('computes the sum of an array of one number', function() {
expect(calculator.sum([7])).toEqual(7);
});
it('computes the sum of an array of one number', function() {
expect(calculator.sum([7,11])).toEqual(18);
});
it('computes the sum of an array of many numbers', function() {
expect(calculator.sum([1,3,5,7,9])).toEqual(25);
});
});
describe('multiply', function() {
it('multiplies two numbers', function() {
expect(calculator.multiply([2,4])).toEqual(8);
});
it('multiplies several numbers', function() {
expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120);
});
});
describe('power', function() {
it('raises one number to the power of another number', function() {
expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64
});
});
describe('factorial', function() {
it('computes the factorial of 0', function() {
expect(calculator.factorial(0)).toEqual(0);
});
it('computes the factorial of 1', function() {
expect(calculator.factorial(1)).toEqual(1);
});
it('computes the factorial of 2', function() {
expect(calculator.factorial(2)).toEqual(2);
});
it('computes the factorial of 5', function() {
expect(calculator.factorial(5)).toEqual(120);
});
it('computes the factorial of 10', function() {
expect(calculator.factorial(10)).toEqual(3628800);
});
});

15
03_simon_says/README.md Normal file
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.

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
}

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");
});
});
});

6
04_pig_latin/README.md Normal file
View File

@ -0,0 +1,6 @@
Pig Latin is a children's language that is intended to be confusing when spoken quickly. Your job for this exercise is to create a solution that takes the words given and
turns them into pig latin. Please see the following wikipedia page for details regarding the rules of Pig Latin:
https://en.wikipedia.org/wiki/Pig_Latin
The rules section will give the rules and the examples that are required to complete this exercise.

9
04_pig_latin/pigLatin.js Normal file
View File

@ -0,0 +1,9 @@
function translate() {
// body...
}
module.exports = {
translate
}

View File

@ -0,0 +1,64 @@
// Topics
// * modules
// * strings
// Pig Latin
// Pig Latin is a made-up children's language that's intended to be confusing. It obeys a few simple rules (below) but when it's spoken quickly it's really difficult for non-children (and non-native speakers) to understand.
// Rule 1: If a word begins with a vowel sound, add an "ay" sound to the end of the word.
// Rule 2: If a word begins with a consonant sound, move it to the end of the word, and then add an "ay" sound to the end of the word.
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
// See https://en.wikipedia.org/wiki/Pig_Latin for more details.
var pigLatin = require("./pigLatin.js");
describe('#translate', function() {
it('translates a word beginning with a vowel', function() {
s = pigLatin.translate("apple");
expect(s).toEqual('appleay');
});
it('translates a word beginning with a consonant', function() {
s = pigLatin.translate("banana");
expect(s).toEqual("ananabay");
});
it('translates a word beginning with two consonants', function() {
s = pigLatin.translate("cherry");
expect(s).toEqual('errychay');
});
it('translates two words', function() {
s = pigLatin.translate("eat pie");
expect(s).toEqual('eatay iepay');
});
it('translates a word beginning with three consonants', function() {
expect(pigLatin.translate("three")).toEqual("eethray");
});
it('counts "sch" as a single phoneme', function() {
s = pigLatin.translate("school");
expect(s).toEqual("oolschay");
});
it('counts "qu" as a single phoneme', function() {
s = pigLatin.translate("quiet");
expect(s).toEqual("ietquay");
});
it('counts "qu" as a consonant even when its preceded by a consonant', function() {
s = pigLatin.translate("square");
expect(s).toEqual("aresquay");
});
it('translates many words', function() {
s = pigLatin.translate("the quick brown fox");
expect(s).toEqual("ethay ickquay ownbray oxfay");
});
});

3
05_book_titles/README.md Normal file
View File

@ -0,0 +1,3 @@
The goal of this exercise is to introduce you to the concept of objects and classes. These are fundamental building blocks for OOP (Object Oriented Programming). You shouldn't need to write a ton of new code, in fact you can re-use your solution from the Simon Says exercise!
The key here will be rewriting certain bits of it to work within the class given to you.

View File

@ -0,0 +1,8 @@
class bookTitle {
}
module.exports = {
bookTitle
}

View File

@ -0,0 +1,64 @@
var bookTitles = require ('./bookTitles.js');
describe('bookTitle', function() {
var book; // note the scope here, if you declare this inside beforeEach then the scope won't allow it to access the other specs
beforeEach(function() {
book = new bookTitles.bookTitle(); // creates a new book instance before each test is run
});
describe('title', function() {
it('should capitalize the first letter', function() {
book.title = 'inferno';
expect(book.title).toEqual('Inferno');
});
it('should capitalize every word', function() {
book.title = 'stuart little';
expect(book.title).toEqual('Stuart Little');
});
describe('should capitalize every word except...', function() {
describe('articles', function() {
it('does not capitalize "the"', function() {
book.title = 'alexander the great';
expect(book.title).toEqual('Alexander the Great');
});
it('does not capitalize "a"', function() {
book.title = 'to kill a mockingbird';
expect(book.title).toEqual('To Kill a Mockingbird');
});
it('does not capitalize "an"', function() {
book.title = 'to eat an apple a day';
expect(book.title).toEqual('To Eat an Apple a Day');
});
});
it('conjunctions', function() {
book.title = 'war and peace';
expect(book.title).toEqual('War and Peace');
});
it('prepositions', function() {
book.title = 'love in the time of cholera';
expect(book.title).toEqual('Love in the Time of Cholera');
});
});
describe('should always capitalize...', function() {
it('I', function() {
book.title = 'what i wish i knew when i was 20';
expect(book.title).toEqual('What I Wish I Knew When I Was 20');
});
it('the first word', function() {
book.title = 'the man in the iron mask';
expect(book.title).toEqual('The Man in the Iron Mask');
});
});
});
});

11
06_timer/README.md Normal file
View File

@ -0,0 +1,11 @@
The goal of this exercise is for you to create a timer. The timer will operate with the following format:
00:00:00
You will be given an object with the value of seconds already added. Your job is to use the class to add a string containing the timer result to this original object.
Example:
12 seconds given
00:00:12 should be the output

7
06_timer/timer.js Normal file
View File

@ -0,0 +1,7 @@
class timeFormat {
}
module.exports = {
timeFormat
}

35
06_timer/timer.spec.js Normal file
View File

@ -0,0 +1,35 @@
var Timer = require ('./timer.js');
describe('Timer', function() {
var timer; // undefined, here for scope purposes
beforeEach(function () {
timer = new Timer.timeFormat();
});
it('should initialize to 0 seconds', function() {
expect(timer.seconds).toEqual(0); // makes sure timer starts with 0 seconds
});
describe('time_string', function() {
it('should display 0 seconds as 00:00:00', function() {
timer.seconds = 0;
expect(timer.time_string()).toEqual("00:00:00");
});
it('should display 12 seconds as 00:00:12', function() {
timer.seconds = 12;
expect(timer.time_string()).toEqual("00:00:12");
});
it('should display 66 seconds as 00:01:06', function() {
timer.seconds = 66;
expect(timer.time_string()).toEqual("00:01:06");
});
it('should display 4000 seconds as 01:06:40', function() {
timer.seconds = 4000;
expect(timer.time_string()).toEqual("01:06:40");
});
});
});

BIN
caesar/.DS_Store vendored Normal file

Binary file not shown.