Merge branch 'origin/master' into 'jest'
This commit is contained in:
commit
8430e59fe4
|
@ -9,10 +9,10 @@ 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. 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.
|
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.
|
||||||
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/free-pro-team@latest/github/creating-cloning-and-archiving-repositories/duplicating-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 `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.
|
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.
|
||||||
|
|
||||||
**Note**: Due to the way Jest handles failed tests, it may 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.
|
**Note**: Due to the way Jest handles failed tests, it may 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.
|
||||||
|
|
||||||
|
|
|
@ -1,23 +1,25 @@
|
||||||
const caesar = require('./caesar')
|
const caesar = require('./caesar')
|
||||||
|
|
||||||
test('works with single letters', () => {
|
describe('caesar', function() {
|
||||||
expect(caesar('A', 1)).toBe('B');
|
it('works with single letters', function() {
|
||||||
});
|
expect(caesar('A', 1)).toEqual('B');
|
||||||
test.skip('works with words', () => {
|
});
|
||||||
expect(caesar('Aaa', 1)).toBe('Bbb');
|
xit('works with words', function() {
|
||||||
});
|
expect(caesar('Aaa', 1)).toEqual('Bbb');
|
||||||
test.skip('works with phrases', () => {
|
});
|
||||||
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
|
xit('works with phrases', function() {
|
||||||
});
|
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!');
|
||||||
test.skip('works with negative shift', () => {
|
});
|
||||||
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
|
xit('works with negative shift', function() {
|
||||||
});
|
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!');
|
||||||
test.skip('wraps', () => {
|
});
|
||||||
expect(caesar('Z', 1)).toBe('A');
|
xit('wraps', function() {
|
||||||
});
|
expect(caesar('Z', 1)).toEqual('A');
|
||||||
test.skip('works with large shift factors', () => {
|
});
|
||||||
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
|
xit('works with large shift factors', function() {
|
||||||
});
|
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!');
|
||||||
test.skip('works with large negative shift factors', () => {
|
});
|
||||||
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
|
xit('works with large negative shift factors', function() {
|
||||||
|
expect(caesar('Hello, World!', -29)).toEqual('Ebiil, Tloia!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
const calculator = require('./calculator');
|
const calculator = require('./calculator');
|
||||||
|
|
||||||
describe('add', () => {
|
describe('add', function() {
|
||||||
test('adds 0 and 0', () => {
|
it('adds 0 and 0', function() {
|
||||||
expect(calculator.add(0,0)).toBe(0);
|
expect(calculator.add(0,0)).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('adds 2 and 2', () => {
|
test.skip('adds 2 and 2', () => {
|
||||||
|
@ -54,24 +54,24 @@ describe('power', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('factorial', () => {
|
describe('factorial', function() {
|
||||||
test.skip('computes the factorial of 0', () => {
|
xit('computes the factorial of 0', function() {
|
||||||
expect(calculator.factorial(0)).toBe(1); // 0! = 1
|
expect(calculator.factorial(0)).toEqual(1); // 0! = 1
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('computes the factorial of 1', () => {
|
xit('computes the factorial of 1', function() {
|
||||||
expect(calculator.factorial(1)).toBe(1);
|
expect(calculator.factorial(1)).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('computes the factorial of 2', () => {
|
xit('computes the factorial of 2', function() {
|
||||||
expect(calculator.factorial(2)).toBe(2);
|
expect(calculator.factorial(2)).toEqual(2);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('computes the factorial of 5', () => {
|
xit('computes the factorial of 5', function() {
|
||||||
expect(calculator.factorial(5)).toBe(120);
|
expect(calculator.factorial(5)).toEqual(120);
|
||||||
});
|
});
|
||||||
|
|
||||||
test.skip('computes the factorial of 10', () => {
|
xit('computes the factorial of 10', function() {
|
||||||
expect(calculator.factorial(10)).toBe(3628800);
|
expect(calculator.factorial(10)).toEqual(3628800);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const fibonacci = function() {
|
const fibonacci = function () {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = fibonacci;
|
|
||||||
|
|
|
@ -1,31 +1,31 @@
|
||||||
const fibonacci = require('./fibonacci')
|
const fibonacci = require('./fibonacci')
|
||||||
|
|
||||||
describe('fibonacci', () => {
|
describe('fibonacci', function() {
|
||||||
test('4th fibonacci number is 3', () => {
|
it('works', function() {
|
||||||
expect(fibonacci(4)).toBe(3);
|
expect(fibonacci(4)).toEqual(3);
|
||||||
});
|
});
|
||||||
test.skip('6th fibonacci number is 8', () => {
|
xit('works', function() {
|
||||||
expect(fibonacci(6)).toBe(8);
|
expect(fibonacci(6)).toEqual(8);
|
||||||
});
|
});
|
||||||
test.skip('10th fibonacci number is 55', () => {
|
xit('works', function() {
|
||||||
expect(fibonacci(10)).toBe(55);
|
expect(fibonacci(10)).toEqual(55);
|
||||||
});
|
});
|
||||||
test.skip('15th fibonacci number is 610', () => {
|
xit('works', function() {
|
||||||
expect(fibonacci(15)).toBe(610);
|
expect(fibonacci(15)).toEqual(610);
|
||||||
});
|
});
|
||||||
test.skip('25th fibonacci number is 75025', () => {
|
xit('works', function() {
|
||||||
expect(fibonacci(25)).toBe(75025);
|
expect(fibonacci(25)).toEqual(75025);
|
||||||
});
|
});
|
||||||
test.skip('doesn\'t accept negatives', () => {
|
xit('doesn\'t accept negatives', function() {
|
||||||
expect(fibonacci(-25)).toBe("OOPS");
|
expect(fibonacci(-25)).toEqual("OOPS");
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
xit('DOES accept strings', function() {
|
||||||
expect(fibonacci("1")).toBe(1);
|
expect(fibonacci("1")).toEqual(1);
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
xit('DOES accept strings', function() {
|
||||||
expect(fibonacci("2")).toBe(1);
|
expect(fibonacci("2")).toEqual(1);
|
||||||
});
|
});
|
||||||
test.skip('DOES accept strings', () => {
|
xit('DOES accept strings', function() {
|
||||||
expect(fibonacci("8")).toBe(21);
|
expect(fibonacci("8")).toEqual(21);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,63 +1,62 @@
|
||||||
const findTheOldest = require('./findTheOldest')
|
let findTheOldest = require('./findTheOldest')
|
||||||
|
|
||||||
describe('findTheOldest', () => {
|
describe('findTheOldest', function() {
|
||||||
test('finds the oldest person!', () => {
|
it('finds the oldest person!', function() {
|
||||||
const people = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: 'Carly',
|
name: "Carly",
|
||||||
yearOfBirth: 1942,
|
yearOfBirth: 1942,
|
||||||
yearOfDeath: 1970,
|
yearOfDeath: 1970,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Ray',
|
name: "Ray",
|
||||||
yearOfBirth: 1962,
|
yearOfBirth: 1962,
|
||||||
yearOfDeath: 2011
|
yearOfDeath: 2011,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Jane',
|
name: "Jane",
|
||||||
yearOfBirth: 1912,
|
yearOfBirth: 1912,
|
||||||
yearOfDeath: 1941
|
yearOfDeath: 1941,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Ray');
|
expect(findTheOldest(people).name).toEqual('Ray');
|
||||||
});
|
});
|
||||||
test.skip('finds the oldest person if someone is still living', () => {
|
xit('finds the oldest person if someone is still living', function() {
|
||||||
const people = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: 'Carly',
|
name: "Carly",
|
||||||
yearOfBirth: 2018,
|
yearOfBirth: 2018,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Ray',
|
name: "Ray",
|
||||||
yearOfBirth: 1962,
|
yearOfBirth: 1962,
|
||||||
yearOfDeath: 2011
|
yearOfDeath: 2011,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Jane',
|
name: "Jane",
|
||||||
yearOfBirth: 1912,
|
yearOfBirth: 1912,
|
||||||
yearOfDeath: 1941
|
yearOfDeath: 1941,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Ray');
|
expect(findTheOldest(people).name).toEqual('Ray');
|
||||||
});
|
});
|
||||||
test.skip('finds the oldest person if the OLDEST is still living', () => {
|
xit('finds the oldest person if the OLDEST is still living', function() {
|
||||||
const people = [
|
const people = [
|
||||||
{
|
{
|
||||||
name: 'Carly',
|
name: "Carly",
|
||||||
yearOfBirth: 1066,
|
yearOfBirth: 1066,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Ray',
|
name: "Ray",
|
||||||
yearOfBirth: 1962,
|
yearOfBirth: 1962,
|
||||||
yearOfDeath: 2011
|
yearOfDeath: 2011,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'Jane',
|
name: "Jane",
|
||||||
yearOfBirth: 1912,
|
yearOfBirth: 1912,
|
||||||
yearOfDeath: 1941
|
yearOfDeath: 1941,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
expect(findTheOldest(people).name).toBe('Carly');
|
expect(findTheOldest(people).name).toEqual('Carly');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
const getTheTitles = require('./getTheTitles')
|
let getTheTitles = require('./getTheTitles')
|
||||||
|
|
||||||
describe('getTheTitles', () => {
|
describe('getTheTitles', function() {
|
||||||
const books = [
|
const books = [
|
||||||
{
|
{
|
||||||
title: 'Book',
|
title: 'Book',
|
||||||
|
@ -15,5 +15,4 @@ describe('getTheTitles', () => {
|
||||||
test('gets titles', () => {
|
test('gets titles', () => {
|
||||||
expect(getTheTitles(books)).toEqual(['Book','Book2']);
|
expect(getTheTitles(books)).toEqual(['Book','Book2']);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -2,4 +2,4 @@ const helloWorld = function() {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = helloWorld;
|
module.exports = helloWorld
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
const helloWorld = require('./helloWorld');
|
const helloWorld = require('./helloWorld');
|
||||||
|
|
||||||
test('says "Hello, World!"', function() {
|
describe('Hello World', function() {
|
||||||
expect(helloWorld()).toBe("Hello, World!");
|
it('says hello world', function() {
|
||||||
|
expect(helloWorld()).toEqual('Hello, World!');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,22 +1,22 @@
|
||||||
const leapYears = require('./leapYears')
|
const leapYears = require('./leapYears')
|
||||||
|
|
||||||
describe('leapYears', () => {
|
describe('leapYears', function() {
|
||||||
test('works with non century years', () => {
|
it('works with non century years', function() {
|
||||||
expect(leapYears(1996)).toBe(true);
|
expect(leapYears(1996)).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with non century years', () => {
|
xit('works with non century years', function() {
|
||||||
expect(leapYears(1997)).toBe(false);
|
expect(leapYears(1997)).toEqual(false);
|
||||||
});
|
});
|
||||||
test.skip('works with ridiculously futuristic non century years', () => {
|
xit('works with ridiculously futuristic non century years', function() {
|
||||||
expect(leapYears(34992)).toBe(true);
|
expect(leapYears(34992)).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with century years', () => {
|
xit('works with century years', function() {
|
||||||
expect(leapYears(1900)).toBe(false);
|
expect(leapYears(1900)).toEqual(false);
|
||||||
});
|
});
|
||||||
test.skip('works with century years', () => {
|
xit('works with century years', function() {
|
||||||
expect(leapYears(1600)).toBe(true);
|
expect(leapYears(1600)).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with century years', () => {
|
xit('works with century years', function() {
|
||||||
expect(leapYears(700)).toBe(false);
|
expect(leapYears(700)).toEqual(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
const palindromes = function() {
|
const palindromes = function () {};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = palindromes;
|
module.exports = palindromes
|
||||||
|
|
|
@ -1,23 +1,22 @@
|
||||||
const palindromes = require('./palindromes')
|
const palindromes = require('./palindromes')
|
||||||
|
|
||||||
describe('palindromes', () => {
|
describe('palindromes', function() {
|
||||||
test('works with single words', () => {
|
it('works with single words', function() {
|
||||||
expect(palindromes('racecar')).toBe(true);
|
expect(palindromes('racecar')).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with punctuation ', () => {
|
xit('works with punctuation ', function() {
|
||||||
expect(palindromes('racecar!')).toBe(true);
|
expect(palindromes('racecar!')).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with upper-case letters ', () => {
|
xit('works with upper-case letters ', function() {
|
||||||
expect(palindromes('Racecar!')).toBe(true);
|
expect(palindromes('Racecar!')).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with multiple words', () => {
|
xit('works with multiple words', function() {
|
||||||
expect(palindromes('A car, a man, a maraca.')).toBe(true);
|
expect(palindromes('A car, a man, a maraca.')).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('works with multiple words', () => {
|
xit('works with multiple words', function() {
|
||||||
expect(palindromes('Animal loots foliated detail of stool lamina.')).toBe(true);
|
expect(palindromes('Animal loots foliated detail of stool lamina.')).toEqual(true);
|
||||||
});
|
});
|
||||||
test.skip('doesn\'t just always return true', () => {
|
xit('doesn\'t just always return true', function() {
|
||||||
expect(palindromes('ZZZZ car, a man, a maraca.')).toBe(false);
|
expect(palindromes('ZZZZ car, a man, a maraca.')).toEqual(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -7,11 +7,11 @@ const pigLatin = require('./pigLatin')
|
||||||
|
|
||||||
// Pig Latin
|
// Pig Latin
|
||||||
|
|
||||||
// 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.
|
// 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 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 test 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 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.)
|
// (There are a few more rules for edge cases, and there are regional variants too, but that should be enough to understand the tests.)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
function translate() {
|
||||||
|
// body...
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
translate
|
||||||
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ describe('repeatString', () => {
|
||||||
|
|
||||||
// DO NOT use Math.floor(Math.random() * 1000) in your code,
|
// DO NOT use Math.floor(Math.random() * 1000) in your code,
|
||||||
// this test generates a random number, then passes it into your code with a function parameter.
|
// this test generates a random number, then passes it into your code with a function parameter.
|
||||||
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/courses/web-development-101/lessons/fundamentals-part-3
|
// If this doesn't make sense, you should go read about functions here: https://www.theodinproject.com/paths/foundations/courses/foundations/lessons/fundamentals-part-3
|
||||||
const number = Math.floor(Math.random() * 1000)
|
const number = Math.floor(Math.random() * 1000)
|
||||||
/*The .match(/((hey))/g).length is a regex that will count the number of heys
|
/*The .match(/((hey))/g).length is a regex that will count the number of heys
|
||||||
in the result, which if your function works correctly will equal the number that
|
in the result, which if your function works correctly will equal the number that
|
||||||
|
|
|
@ -19,5 +19,4 @@ describe('snakeCase', () => {
|
||||||
test.skip('works with WTF case', () => {
|
test.skip('works with WTF case', () => {
|
||||||
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
|
expect(snakeCase('SnAkE..CaSe..Is..AwEsOmE')).toEqual('snake_case_is_awesome');
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue