Merge pull request #1 from xandora/jester-tester

This commit is contained in:
xandora 2021-04-29 21:54:47 +12:00 committed by GitHub
commit e901090896
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 11269 additions and 189 deletions

3
.gitignore vendored
View File

@ -1 +1,4 @@
.vscode .vscode
node_modules
package-lock.json
package.json

View File

@ -9,10 +9,12 @@ There will eventually be a suggested order of completion, but at this time since
## How To Use These Exercises ## How To Use These Exercises
Before you start you should have a few things installed on your machine: Before you start you should have a few things installed on your machine:
1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md). 1. NPM. To check if you have NPM installed, type `npm --version` in your terminal. If you get back `Command 'npm' not found, but can be installed with:`, do NOT follow the instructions in the terminal to install with `apt-get`. (This causes permission issues.) Instead, install Node with NVM by following the instructions [here](https://github.com/TheOdinProject/curriculum/blob/master/foundations/installations/installing_node.md).
2. Jasmine. Jasmine is a testing framework for JavaScript. Type `jasmine -v` to check for it. If you need to install it, type `npm install -g jasmine` to do so. 2. Jest. Jest is a testing framework for JavaScript. To install it, type `npm install --save-dev jest`. We use `--save-dev` here to specify this module is for development purposes only.
3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository) 3. A copy of this repository. Copies of repositories on your machine are called clones. If you need help cloning, you can learn how [here](https://docs.github.com/en/github/creating-cloning-and-archiving-repositories/cloning-a-repository).
Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `jasmine exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'xit' compared to 'it'. This is purposeful. After you pass your first 'it', you will change the next 'xit' to an 'it' and test your code again. You'll do this until all conditions are satisfied. Each exercise includes 3 files: a markdown file with a description of the task, an empty (or mostly empty) JavaScript file, and a set of tests. To complete an exercise, you'll need to go to the exercise directory with `cd exerciseName` in the terminal and run `npm test exerciseName.spec.js`. This should run the test file and show you the output. When you first run a test, it will fail. This is by design! You must open the exercise file and write the code needed to get the test to pass. Some of the exercises have test conditions defined in their spec file that are defined as 'test.skip' compared to 'test'. This is purposeful. After you pass your first 'test', you will change the next 'test.skip' to an 'test' and test your code again. You'll do this until all conditions are satisfied.
**Note**: Due to the way Jest handles failed tests, it will return an exit code of 1 if any tests fail. NPM will interpret this as an error and you may see some `npm ERR!` messages after Jest runs. You can ignore these, or run your test with `npm test exerciseName.spec.js --silent` to supress the errors.
The first exercise, `helloWorld`, will walk you through the process in-depth. The first exercise, `helloWorld`, will walk you through the process in-depth.

View File

@ -1,25 +1,23 @@
const caesar = require('./caesar') const caesar = require('./caesar')
describe('caesar', function() { test('works with single letters', () => {
it('works with single letters', function() { expect(caesar('A', 1)).toBe('B');
expect(caesar('A', 1)).toEqual('B'); });
}); test.skip('works with words', () => {
xit('works with words', function() { expect(caesar('Aaa', 1)).toBe('Bbb');
expect(caesar('Aaa', 1)).toEqual('Bbb'); });
}); test.skip('works with phrases', () => {
xit('works with phrases', function() { expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!'); });
}); test.skip('works with negative shift', () => {
xit('works with negative shift', function() { expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!'); });
}); test.skip('wraps', () => {
xit('wraps', function() { expect(caesar('Z', 1)).toBe('A');
expect(caesar('Z', 1)).toEqual('A'); });
}); test.skip('works with large shift factors', () => {
xit('works with large shift factors', function() { expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!'); });
}); test.skip('works with large negative shift factors', () => {
xit('works with large negative shift factors', function() { expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
expect(caesar('Hello, World!', -29)).toEqual('Ebiil, Tloia!');
});
}); });

View File

@ -1,24 +1,24 @@
function add () { const add = function() {
} }
function subtract () { const subtract = function() {
} }
function sum () { const sum = function() {
} }
function multiply () { const mulitply = function() {
} }
function power() { const power = function() {
} }
function factorial() { const factorial = function() {
} }

View File

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

View File

@ -2,4 +2,4 @@ const fibonacci = function() {
} }
module.exports = fibonacci module.exports = fibonacci;

View File

@ -1,31 +1,31 @@
const fibonacci = require('./fibonacci') const fibonacci = require('./fibonacci')
describe('fibonacci', function() { describe('fibonacci', () => {
it('works', function() { test('4th fibonacci number is 3', () => {
expect(fibonacci(4)).toEqual(3); expect(fibonacci(4)).toBe(3);
}); });
xit('works', function() { test.skip('6th fibonacci number is 8', () => {
expect(fibonacci(6)).toEqual(8); expect(fibonacci(6)).toBe(8);
}); });
xit('works', function() { test.skip('10th fibonacci number is 55', () => {
expect(fibonacci(10)).toEqual(55); expect(fibonacci(10)).toBe(55);
}); });
xit('works', function() { test.skip('15th fibonacci number is 610', () => {
expect(fibonacci(15)).toEqual(610); expect(fibonacci(15)).toBe(610);
}); });
xit('works', function() { test.skip('25th fibonacci number is 75025', () => {
expect(fibonacci(25)).toEqual(75025); expect(fibonacci(25)).toBe(75025);
}); });
xit('doesn\'t accept negatives', function() { test.skip('doesn\'t accept negatives', () => {
expect(fibonacci(-25)).toEqual("OOPS"); expect(fibonacci(-25)).toBe("OOPS");
}); });
xit('DOES accept strings', function() { test.skip('DOES accept strings', () => {
expect(fibonacci("1")).toEqual(1); expect(fibonacci("1")).toBe(1);
}); });
xit('DOES accept strings', function() { test.skip('DOES accept strings', () => {
expect(fibonacci("2")).toEqual(1); expect(fibonacci("2")).toBe(1);
}); });
xit('DOES accept strings', function() { test.skip('DOES accept strings', () => {
expect(fibonacci("8")).toEqual(21); expect(fibonacci("8")).toBe(21);
}); });
}); });

View File

@ -1,4 +1,4 @@
let findTheOldest = function() { const findTheOldest = function() {
} }

View File

@ -1,7 +1,7 @@
let findTheOldest = require('./findTheOldest') const findTheOldest = require('./findTheOldest')
describe('findTheOldest', function() { describe('findTheOldest', () => {
it('finds the oldest person!', function() { test('finds the oldest person!', () => {
const people = [ const people = [
{ {
name: 'Carly', name: 'Carly',
@ -19,9 +19,9 @@ describe('findTheOldest', function() {
yearOfDeath: 1941 yearOfDeath: 1941
}, },
] ]
expect(findTheOldest(people).name).toEqual('Ray'); expect(findTheOldest(people).name).toBe('Ray');
}); });
xit('finds the oldest person if someone is still living', function() { test.skip('finds the oldest person if someone is still living', () => {
const people = [ const people = [
{ {
name: 'Carly', name: 'Carly',
@ -38,9 +38,9 @@ describe('findTheOldest', function() {
yearOfDeath: 1941 yearOfDeath: 1941
}, },
] ]
expect(findTheOldest(people).name).toEqual('Ray'); expect(findTheOldest(people).name).toBe('Ray');
}); });
xit('finds the oldest person if the OLDEST is still living', function() { test.skip('finds the oldest person if the OLDEST is still living', () => {
const people = [ const people = [
{ {
name: 'Carly', name: 'Carly',
@ -57,7 +57,7 @@ describe('findTheOldest', function() {
yearOfDeath: 1941 yearOfDeath: 1941
}, },
] ]
expect(findTheOldest(people).name).toEqual('Carly'); expect(findTheOldest(people).name).toBe('Carly');
}); });
}); });

View File

@ -1,6 +1,6 @@
let getTheTitles = require('./getTheTitles') const getTheTitles = require('./getTheTitles')
describe('getTheTitles', function() { describe('getTheTitles', () => {
const books = [ const books = [
{ {
title: 'Book', title: 'Book',
@ -12,8 +12,8 @@ describe('getTheTitles', function() {
} }
] ]
it('gets titles', function() { test('gets titles', () => {
expect(getTheTitles(books)).toEqual(['Book','Book2']); expect(getTheTitles(books)).toBe(['Book','Book2']);
}); });
}); });

View File

@ -2,4 +2,4 @@ const helloWorld = function() {
return '' return ''
} }
module.exports = helloWorld module.exports = helloWorld;

View File

@ -1,7 +1,5 @@
const helloWorld = require('./helloWorld'); const helloWorld = require('./helloWorld');
describe('Hello World', function() { test('says "Hello, World!"', function() {
it('says hello world', function() { expect(helloWorld()).toBe("Hello, World!");
expect(helloWorld()).toEqual('Hello, World!');
});
}); });

View File

@ -1,22 +1,22 @@
const leapYears = require('./leapYears') const leapYears = require('./leapYears')
describe('leapYears', function() { describe('leapYears', () => {
it('works with non century years', function() { test('works with non century years', () => {
expect(leapYears(1996)).toEqual(true); expect(leapYears(1996)).toBe(true);
}); });
xit('works with non century years', function() { test.skip('works with non century years', () => {
expect(leapYears(1997)).toEqual(false); expect(leapYears(1997)).toBe(false);
}); });
xit('works with ridiculously futuristic non century years', function() { test.skip('works with ridiculously futuristic non century years', () => {
expect(leapYears(34992)).toEqual(true); expect(leapYears(34992)).toBe(true);
}); });
xit('works with century years', function() { test.skip('works with century years', () => {
expect(leapYears(1900)).toEqual(false); expect(leapYears(1900)).toBe(false);
}); });
xit('works with century years', function() { test.skip('works with century years', () => {
expect(leapYears(1600)).toEqual(true); expect(leapYears(1600)).toBe(true);
}); });
xit('works with century years', function() { test.skip('works with century years', () => {
expect(leapYears(700)).toEqual(false); expect(leapYears(700)).toBe(false);
}); });
}); });

11072
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

9
package.json Normal file
View File

@ -0,0 +1,9 @@
{
"devDependencies": {
"jest": "^26.6.3",
"jest-cli": "^26.6.3"
},
"scripts": {
"test": "jest"
}
}

View File

@ -2,4 +2,4 @@ const palindromes = function() {
} }
module.exports = palindromes module.exports = palindromes;

View File

@ -1,23 +1,23 @@
const palindromes = require('./palindromes') const palindromes = require('./palindromes')
describe('palindromes', function() { describe('palindromes', () => {
it('works with single words', function() { test('works with single words', () => {
expect(palindromes('racecar')).toEqual(true); expect(palindromes('racecar')).toBe(true);
}); });
xit('works with punctuation ', function() { test.skip('works with punctuation ', () => {
expect(palindromes('racecar!')).toEqual(true); expect(palindromes('racecar!')).toBe(true);
}); });
xit('works with upper-case letters ', function() { test.skip('works with upper-case letters ', () => {
expect(palindromes('Racecar!')).toEqual(true); expect(palindromes('Racecar!')).toBe(true);
}); });
xit('works with multiple words', function() { test.skip('works with multiple words', () => {
expect(palindromes('A car, a man, a maraca.')).toEqual(true); expect(palindromes('A car, a man, a maraca.')).toBe(true);
}); });
xit('works with multiple words', function() { test.skip('works with multiple words', () => {
expect(palindromes('Animal loots foliated detail of stool lamina.')).toEqual(true); expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
}); });
xit('doesn\'t just always return true', function() { test.skip('doesn\'t just always return true', () => {
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false); expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
}); });
}); });

View File

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

View File

@ -1,3 +1,5 @@
const expect = require("expect");
// Topics // Topics
// * modules // * modules
@ -5,11 +7,11 @@
// Pig Latin // 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. // Pig Latin is a made-up children's language that's intended to be confusing. test obeys a few simple rules (below) but when test's spoken quickly test'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 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. // Rule 2: If a word begins with a consonant sound, move test 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.) // (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
@ -17,48 +19,48 @@
const pigLatin = require("./pigLatin.js"); const pigLatin = require("./pigLatin.js");
describe('#translate', function() { describe('translate', () => {
it('translates a word beginning with a vowel', function() { test('translates a word beginning with a vowel', () => {
s = pigLatin.translate("apple"); s = pigLatin.translate("apple");
expect(s).toEqual('appleay'); expect(s).toBe('appleay');
}); });
xit('translates a word beginning with a consonant', function() { test.skip('translates a word beginning with a consonant', () => {
s = pigLatin.translate("banana"); s = pigLatin.translate("banana");
expect(s).toEqual("ananabay"); expect(s).toBe("ananabay");
}); });
xit('translates a word beginning with two consonants', function() { test.skip('translates a word beginning with two consonants', () => {
s = pigLatin.translate("cherry"); s = pigLatin.translate("cherry");
expect(s).toEqual('errychay'); expect(s).toBe('errychay');
}); });
xit('translates two words', function() { test.skip('translates two words', () => {
s = pigLatin.translate("eat pie"); s = pigLatin.translate("eat pie");
expect(s).toEqual('eatay iepay'); expect(s).toBe('eatay iepay');
}); });
xit('translates a word beginning with three consonants', function() { test.skip('translates a word beginning with three consonants', () => {
expect(pigLatin.translate("three")).toEqual("eethray"); expect(pigLatin.translate("three")).toBe("eethray");
}); });
xit('counts "sch" as a single phoneme', function() { test.skip('counts "sch" as a single phoneme', () => {
s = pigLatin.translate("school"); s = pigLatin.translate("school");
expect(s).toEqual("oolschay"); expect(s).toBe("oolschay");
}); });
xit('counts "qu" as a single phoneme', function() { test.skip('counts "qu" as a single phoneme', () => {
s = pigLatin.translate("quiet"); s = pigLatin.translate("quiet");
expect(s).toEqual("ietquay"); expect(s).toBe("ietquay");
}); });
xit('counts "qu" as a consonant even when its preceded by a consonant', function() { test.skip('counts "qu" as a consonant even when its preceded by a consonant', () => {
s = pigLatin.translate("square"); s = pigLatin.translate("square");
expect(s).toEqual("aresquay"); expect(s).toBe("aresquay");
}); });
xit('translates many words', function() { test.skip('translates many words', () => {
s = pigLatin.translate("the quick brown fox"); s = pigLatin.translate("the quick brown fox");
expect(s).toEqual("ethay ickquay ownbray oxfay"); expect(s).toBe("ethay ickquay ownbray oxfay");
}); });
}); });

View File

@ -1,25 +1,25 @@
const removeFromArray = require('./removeFromArray') const removeFromArray = require('./removeFromArray')
describe('removeFromArray', function() { describe('removeFromArray', () => {
it('removes a single value', function() { test('removes a single value', () => {
expect(removeFromArray([1, 2, 3, 4], 3)).toEqual([1, 2, 4]); expect(removeFromArray([1, 2, 3, 4], 3)).toBe([1, 2, 4]);
}); });
xit('removes multiple values', function() { test.skip('removes multiple values', () => {
expect(removeFromArray([1, 2, 3, 4], 3, 2)).toEqual([1, 4]); expect(removeFromArray([1, 2, 3, 4], 3, 2)).toBe([1, 4]);
}); });
xit('ignores non present values', function() { test.skip('ignores non present values', () => {
expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toEqual([1, 2, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, "tacos")).toBe([1, 2, 3, 4]);
}); });
xit('ignores non present values, but still works', function() { test.skip('ignores non present values, but still works', () => {
expect(removeFromArray([1, 2, 3, 4], 7, 2)).toEqual([1, 3, 4]); expect(removeFromArray([1, 2, 3, 4], 7, 2)).toBe([1, 3, 4]);
}); });
xit('can remove all values', function() { test.skip('can remove all values', () => {
expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toEqual([]); expect(removeFromArray([1, 2, 3, 4], 1, 2, 3, 4)).toBe([]);
}); });
xit('works with strings', function() { test.skip('works with strings', () => {
expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toEqual([2, "ho"]); expect(removeFromArray(["hey", 2, 3, "ho"], "hey", 3)).toBe([2, "ho"]);
}); });
xit('only removes same type', function() { test.skip('only removes same type', () => {
expect(removeFromArray([1, 2, 3], "1", 3)).toEqual([1, 2]); expect(removeFromArray([1, 2, 3], "1", 3)).toBe([1, 2]);
}); });
}); });

View File

@ -1,4 +1,4 @@
const repeatString = require('./repeatString') const expect = require('expect');const repeatString = require('./repeatString')
describe('repeatString', function() { describe('repeatString', function() {
it('repeats the string', function() { it('repeats the string', function() {

View File

@ -1,4 +1,4 @@
const reverseString = require('./reverseString') const expect = require('expect');const reverseString = require('./reverseString')
describe('reverseString', function() { describe('reverseString', function() {
it('reverses single word', function() { it('reverses single word', function() {

View File

@ -1,4 +1,4 @@
const snakeCase = require('./snakeCase') const expect = require('expect');const snakeCase = require('./snakeCase')
describe('snakeCase', function() { describe('snakeCase', function() {
it('works with simple lowercased phrases', function() { it('works with simple lowercased phrases', function() {

View File

@ -1,4 +1,4 @@
const sumAll = require('./sumAll') const expect = require('expect');const sumAll = require('./sumAll')
describe('sumAll', function() { describe('sumAll', function() {
it('sums numbers within the range', function() { it('sums numbers within the range', function() {

View File

@ -1,4 +1,4 @@
const {ftoc, ctof} = require('./tempConversion') const expect = require('expect');const {ftoc, ctof} = require('./tempConversion')
describe('ftoc', function() { describe('ftoc', function() {
it('works', function() { it('works', function() {