From 6012c3a095261e7c8d091d9d286ffde29b8c401f Mon Sep 17 00:00:00 2001 From: Matthew-Cravinhos Date: Wed, 20 Sep 2017 19:04:46 -0400 Subject: [PATCH] Added test cases --- .DS_Store | Bin 0 -> 6148 bytes 02_calculator/README.md | 6 +++ 02_calculator/calculator.js | 32 ++++++++++++ 02_calculator/calculator.spec.js | 77 +++++++++++++++++++++++++++++ 03_simon_says/README.md | 15 ++++++ 03_simon_says/simonSays.js | 37 ++++++++++++++ 03_simon_says/simonSays.spec.js | 78 ++++++++++++++++++++++++++++++ 04_pig_latin/README.md | 6 +++ 04_pig_latin/pigLatin.js | 9 ++++ 04_pig_latin/pigLatin.spec.js | 64 ++++++++++++++++++++++++ 05_book_titles/README.md | 3 ++ 05_book_titles/bookTitles.js | 8 +++ 05_book_titles/bookTitles.spec.js | 64 ++++++++++++++++++++++++ 06_timer/README.md | 11 +++++ 06_timer/timer.js | 7 +++ 06_timer/timer.spec.js | 35 ++++++++++++++ caesar/.DS_Store | Bin 0 -> 6148 bytes 17 files changed, 452 insertions(+) create mode 100644 .DS_Store create mode 100644 02_calculator/README.md create mode 100644 02_calculator/calculator.js create mode 100644 02_calculator/calculator.spec.js create mode 100644 03_simon_says/README.md create mode 100644 03_simon_says/simonSays.js create mode 100644 03_simon_says/simonSays.spec.js create mode 100644 04_pig_latin/README.md create mode 100644 04_pig_latin/pigLatin.js create mode 100644 04_pig_latin/pigLatin.spec.js create mode 100644 05_book_titles/README.md create mode 100644 05_book_titles/bookTitles.js create mode 100644 05_book_titles/bookTitles.spec.js create mode 100644 06_timer/README.md create mode 100644 06_timer/timer.js create mode 100644 06_timer/timer.spec.js create mode 100644 caesar/.DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..b150425a3cb4d48e8efd876abe9fd864393d222b GIT binary patch literal 6148 zcmeHKOHRWu5FJB>Dt_t;vCI+pucIoQpa+0{P(dV3)uan{*|1^DjxAT=3Y>%s@MdgP ziQ=RnB!tk6piO>Jd>Fjj^+ho9z%+0OiScp zjjaRffI9Hk9N@LPM@Mu*S6I2_^_x>li+FlG7^lg+B)f&3q){|k=3}Dww~t4e)5@NF zgFV0XDmjJjjP59b+L`o+^gvmI?gn;6_tQ#uBfF$~E!(4e7k-~X>m0hLK>k|h=+8W= z8@UzD&!V}7TT;A+>(RRpz30$5g2yS{qsMA<=)R$Bl8xh0n#Qc4mFOw1m0v0FMG9QQ zFBSO(zNgSG3cYaUB`D7K`qwxWov)(P!zpQN;CS?G$&!T0ctI9rqva_-PS~?Kx;qv% zs{`tQILq) zU^>wt>Z2sLx7Lc|y*5C*M&n>!VNs?ax$RgwycHj!N#I(*9bo9Nu!s?a{t*xxG^qo> G>cA&fsnj+A literal 0 HcmV?d00001 diff --git a/02_calculator/README.md b/02_calculator/README.md new file mode 100644 index 0000000..9f27d73 --- /dev/null +++ b/02_calculator/README.md @@ -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. \ No newline at end of file diff --git a/02_calculator/calculator.js b/02_calculator/calculator.js new file mode 100644 index 0000000..2d904a8 --- /dev/null +++ b/02_calculator/calculator.js @@ -0,0 +1,32 @@ +function add () { + +} + +function subtract () { + +} + +function sum () { + +} + +function multiply () { + +} + +function power() { + +} + +function factorial() { + +} + +module.exports = { + add, + subtract, + sum, + multiply, + power, + factorial +} \ No newline at end of file diff --git a/02_calculator/calculator.spec.js b/02_calculator/calculator.spec.js new file mode 100644 index 0000000..29b90af --- /dev/null +++ b/02_calculator/calculator.spec.js @@ -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); + }); +}); \ No newline at end of file diff --git a/03_simon_says/README.md b/03_simon_says/README.md new file mode 100644 index 0000000..5ea295d --- /dev/null +++ b/03_simon_says/README.md @@ -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. \ No newline at end of file diff --git a/03_simon_says/simonSays.js b/03_simon_says/simonSays.js new file mode 100644 index 0000000..bab089f --- /dev/null +++ b/03_simon_says/simonSays.js @@ -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 +} \ No newline at end of file diff --git a/03_simon_says/simonSays.spec.js b/03_simon_says/simonSays.spec.js new file mode 100644 index 0000000..ae8f74c --- /dev/null +++ b/03_simon_says/simonSays.spec.js @@ -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"); + }); + }); +}); \ No newline at end of file diff --git a/04_pig_latin/README.md b/04_pig_latin/README.md new file mode 100644 index 0000000..3e1d537 --- /dev/null +++ b/04_pig_latin/README.md @@ -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. \ No newline at end of file diff --git a/04_pig_latin/pigLatin.js b/04_pig_latin/pigLatin.js new file mode 100644 index 0000000..c9784c3 --- /dev/null +++ b/04_pig_latin/pigLatin.js @@ -0,0 +1,9 @@ +function translate() { + // body... +} + + +module.exports = { + translate +} + diff --git a/04_pig_latin/pigLatin.spec.js b/04_pig_latin/pigLatin.spec.js new file mode 100644 index 0000000..1eb4bfb --- /dev/null +++ b/04_pig_latin/pigLatin.spec.js @@ -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"); + }); +}); \ No newline at end of file diff --git a/05_book_titles/README.md b/05_book_titles/README.md new file mode 100644 index 0000000..acf79cf --- /dev/null +++ b/05_book_titles/README.md @@ -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. \ No newline at end of file diff --git a/05_book_titles/bookTitles.js b/05_book_titles/bookTitles.js new file mode 100644 index 0000000..e546db0 --- /dev/null +++ b/05_book_titles/bookTitles.js @@ -0,0 +1,8 @@ +class bookTitle { + +} + +module.exports = { + bookTitle +} + diff --git a/05_book_titles/bookTitles.spec.js b/05_book_titles/bookTitles.spec.js new file mode 100644 index 0000000..3a0e8ad --- /dev/null +++ b/05_book_titles/bookTitles.spec.js @@ -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'); + }); + }); + }); +}); \ No newline at end of file diff --git a/06_timer/README.md b/06_timer/README.md new file mode 100644 index 0000000..97ae612 --- /dev/null +++ b/06_timer/README.md @@ -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 \ No newline at end of file diff --git a/06_timer/timer.js b/06_timer/timer.js new file mode 100644 index 0000000..3cd09b8 --- /dev/null +++ b/06_timer/timer.js @@ -0,0 +1,7 @@ +class timeFormat { + +} + +module.exports = { + timeFormat +} diff --git a/06_timer/timer.spec.js b/06_timer/timer.spec.js new file mode 100644 index 0000000..d6ce0e2 --- /dev/null +++ b/06_timer/timer.spec.js @@ -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"); + }); + }); +}); \ No newline at end of file diff --git a/caesar/.DS_Store b/caesar/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0