Skip to content

Commit 5708c3d

Browse files
Michael FrankKevinMulhern
Michael Frank
authored andcommitted
Added jest
Removed generator-exercises folder as it breaks jest-codemods run jest-codemods on .spec.js files, move generator-exercises back in Change references from Jasmine to Jest in main readme Update README with Jest specific language. Update some spec files with new syntax update tests, multiple exercises .gitignore: Added package-lock.json, package.json that were used when I ran code-blocks over the tests. Standardised function declaration calls across exercises fix typo in caesar.spec.js Ignoring package-lock.json, package.json Backtrack on .gitignore modification, add instructions to readme move files from testing repo to this repo Typo fixes, remove duplicate exercise folder Remove solution from non-solution branch Minor grammatical fixes added trailing semicolon to all function and module exports Fix words caught by search/replace action. remove doubled semicolon. Correct words caught by search/replace action. Add missing semicolon. Add .DS_Store to .gitignore multiple files: Added a blank line at the end of each file Ignore generator-exercise when linting exercise files Update exercise number of each exercise Update exercise number
1 parent 4c771f2 commit 5708c3d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+6258
-321
lines changed

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
generator-exercise/

.eslintrc.json

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"plugins": [
3+
"import"
4+
],
5+
"parserOptions": {
6+
"ecmaVersion": 12,
7+
"sourceType": "module"
8+
},
9+
"rules": {
10+
"eol-last": ["error", "always"]
11+
}
12+
}

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
.vscode
1+
.vscode
2+
node_modules/
3+
.DS_Store

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ There will eventually be a suggested order of completion, but at this time since
99
## How To Use These Exercises
1010
Before you start you should have a few things installed on your machine:
1111
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).
12-
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.
13-
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)
12+
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.
13+
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).
1414

15-
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.
15+
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.
16+
17+
**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.
1618

1719
The first exercise, `helloWorld`, will walk you through the process in-depth.
1820

caesar/README.md

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Exercise XX - caesar cipher
1+
# Exercise 13 - Caesar cipher
22

3-
Implement the legendary caesar cipher:
3+
Implement the legendary Caesar cipher:
44

55
> In cryptography, a Caesar cipher, also known as Caesar's cipher, the shift cipher, Caesar's code or Caesar shift, is one of the simplest and most widely known encryption techniques. It is a type of substitution cipher in which each letter in the plaintext is replaced by a letter some fixed number of positions down the alphabet. For example, with a left shift of 3, D would be replaced by A, E would become B, and so on. The method is named after Julius Caesar, who used it in his private correspondence.
66
@@ -31,5 +31,3 @@ negative numbers should work as well:
3131
```javascript
3232
caesar('Mjqqt, Btwqi!', -5) // returns 'Hello, World!'
3333
```
34-
35-

caesar/caesar.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const caesar = function() {
22

3-
}
3+
};
44

5-
module.exports = caesar
5+
module.exports = caesar;

caesar/caesar.spec.js

+20-22
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
11
const caesar = require('./caesar')
22

3-
describe('caesar', function() {
4-
it('works with single letters', function() {
5-
expect(caesar('A', 1)).toEqual('B');
6-
});
7-
xit('works with words', function() {
8-
expect(caesar('Aaa', 1)).toEqual('Bbb');
9-
});
10-
xit('works with phrases', function() {
11-
expect(caesar('Hello, World!', 5)).toEqual('Mjqqt, Btwqi!');
12-
});
13-
xit('works with negative shift', function() {
14-
expect(caesar('Mjqqt, Btwqi!', -5)).toEqual('Hello, World!');
15-
});
16-
xit('wraps', function() {
17-
expect(caesar('Z', 1)).toEqual('A');
18-
});
19-
xit('works with large shift factors', function() {
20-
expect(caesar('Hello, World!', 75)).toEqual('Ebiil, Tloia!');
21-
});
22-
xit('works with large negative shift factors', function() {
23-
expect(caesar('Hello, World!', -29)).toEqual('Ebiil, Tloia!');
24-
});
3+
test('works with single letters', () => {
4+
expect(caesar('A', 1)).toBe('B');
5+
});
6+
test.skip('works with words', () => {
7+
expect(caesar('Aaa', 1)).toBe('Bbb');
8+
});
9+
test.skip('works with phrases', () => {
10+
expect(caesar('Hello, World!', 5)).toBe('Mjqqt, Btwqi!');
11+
});
12+
test.skip('works with negative shift', () => {
13+
expect(caesar('Mjqqt, Btwqi!', -5)).toBe('Hello, World!');
14+
});
15+
test.skip('wraps', () => {
16+
expect(caesar('Z', 1)).toBe('A');
17+
});
18+
test.skip('works with large shift factors', () => {
19+
expect(caesar('Hello, World!', 75)).toBe('Ebiil, Tloia!');
20+
});
21+
test.skip('works with large negative shift factors', () => {
22+
expect(caesar('Hello, World!', -29)).toBe('Ebiil, Tloia!');
2523
});

calculator/README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# Exercise 08 - Calculator
2+
13
The goal for this exercise is to create a calculator that does the following:
24

35
add, subtract, get the sum, multiply, get the power, and find the factorial
46

5-
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
6-
take a look at the spec file that houses the Jasmine test cases.
7+
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 Jest! To see the expected value
8+
take a look at the spec file that houses the Jest test cases.

calculator/calculator.js

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,32 @@
1-
function add () {
1+
const add = function() {
22

3-
}
3+
};
44

5-
function subtract () {
5+
const subtract = function() {
66

7-
}
7+
};
88

9-
function sum () {
9+
const sum = function() {
1010

11-
}
11+
};
1212

13-
function multiply () {
14-
15-
}
13+
const multiply = function() {
14+
15+
};;
1616

17-
function power() {
17+
const power = function() {
1818

19-
}
19+
};
2020

21-
function factorial() {
21+
const factorial = function() {
2222

23-
}
23+
};
2424

2525
module.exports = {
26-
add,
27-
subtract,
28-
sum,
29-
multiply,
30-
power,
31-
factorial
32-
}
26+
add,
27+
subtract,
28+
sum,
29+
multiply,
30+
power,
31+
factorial
32+
};

calculator/calculator.spec.js

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,77 @@
1-
const calculator = require ('./calculator.js');
1+
const calculator = require('./calculator');
22

3-
describe('add', function() {
4-
it('adds 0 and 0', function() {
5-
expect(calculator.add(0,0)).toEqual(0);
3+
describe('add', () => {
4+
test('adds 0 and 0', () => {
5+
expect(calculator.add(0,0)).toBe(0);
66
});
77

8-
xit('adds 2 and 2', function() {
9-
expect(calculator.add(2,2)).toEqual(4);
8+
test.skip('adds 2 and 2', () => {
9+
expect(calculator.add(2,2)).toBe(4);
1010
});
1111

12-
xit('adds positive numbers', function() {
13-
expect(calculator.add(2,6)).toEqual(8);
12+
test.skip('adds positive numbers', () => {
13+
expect(calculator.add(2,6)).toBe(8);
1414
});
1515
});
1616

17-
describe('subtract', function() {
18-
xit('subtracts numbers', function() {
19-
expect(calculator.subtract(10,4)).toEqual(6);
17+
describe('subtract', () => {
18+
test.skip('subtracts numbers', () => {
19+
expect(calculator.subtract(10,4)).toBe(6);
2020
});
2121
});
2222

23-
describe('sum', function() {
24-
xit('computes the sum of an empty array', function() {
25-
expect(calculator.sum([])).toEqual(0);
23+
describe('sum', () => {
24+
test.skip('computes the sum of an empty array', () => {
25+
expect(calculator.sum([])).toBe(0);
2626
});
2727

28-
xit('computes the sum of an array of one number', function() {
29-
expect(calculator.sum([7])).toEqual(7);
28+
test.skip('computes the sum of an array of one number', () => {
29+
expect(calculator.sum([7])).toBe(7);
3030
});
3131

32-
xit('computes the sum of an array of two numbers', function() {
33-
expect(calculator.sum([7,11])).toEqual(18);
32+
test.skip('computes the sum of an array of two numbers', () => {
33+
expect(calculator.sum([7,11])).toBe(18);
3434
});
3535

36-
xit('computes the sum of an array of many numbers', function() {
37-
expect(calculator.sum([1,3,5,7,9])).toEqual(25);
36+
test.skip('computes the sum of an array of many numbers', () => {
37+
expect(calculator.sum([1,3,5,7,9])).toBe(25);
3838
});
3939
});
4040

41-
describe('multiply', function() {
42-
xit('multiplies two numbers', function() {
43-
expect(calculator.multiply([2,4])).toEqual(8);
41+
describe('multiply', () => {
42+
test.skip('multiplies two numbers', () => {
43+
expect(calculator.multiply([2,4])).toBe(8);
4444
});
4545

46-
xit('multiplies several numbers', function() {
47-
expect(calculator.multiply([2,4,6,8,10,12,14])).toEqual(645120);
46+
test.skip('multiplies several numbers', () => {
47+
expect(calculator.multiply([2,4,6,8,10,12,14])).toBe(645120);
4848
});
4949
});
5050

51-
describe('power', function() {
52-
xit('raises one number to the power of another number', function() {
53-
expect(calculator.power(4,3)).toEqual(64); // 4 to third power is 64
51+
describe('power', () => {
52+
test.skip('raises one number to the power of another number', () => {
53+
expect(calculator.power(4,3)).toBe(64); // 4 to third power is 64
5454
});
5555
});
5656

57-
describe('factorial', function() {
58-
xit('computes the factorial of 0', function() {
59-
expect(calculator.factorial(0)).toEqual(1); // 0! = 1
57+
describe('factorial', () => {
58+
test.skip('computes the factorial of 0', () => {
59+
expect(calculator.factorial(0)).toBe(1); // 0! = 1
6060
});
6161

62-
xit('computes the factorial of 1', function() {
63-
expect(calculator.factorial(1)).toEqual(1);
62+
test.skip('computes the factorial of 1', () => {
63+
expect(calculator.factorial(1)).toBe(1);
6464
});
6565

66-
xit('computes the factorial of 2', function() {
67-
expect(calculator.factorial(2)).toEqual(2);
66+
test.skip('computes the factorial of 2', () => {
67+
expect(calculator.factorial(2)).toBe(2);
6868
});
6969

70-
xit('computes the factorial of 5', function() {
71-
expect(calculator.factorial(5)).toEqual(120);
70+
test.skip('computes the factorial of 5', () => {
71+
expect(calculator.factorial(5)).toBe(120);
7272
});
7373

74-
xit('computes the factorial of 10', function() {
75-
expect(calculator.factorial(10)).toEqual(3628800);
74+
test.skip('computes the factorial of 10', () => {
75+
expect(calculator.factorial(10)).toBe(3628800);
7676
});
7777
});

fibonacci/README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
# Exercise XX - fibonacci
1+
# Exercise 10 - Fibonacci
22

3-
Create a function that returns a specific member of the fibonacci sequence:
3+
Create a function that returns a specific member of the Fibonacci sequence:
44

5-
> a series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
5+
> A series of numbers in which each number ( Fibonacci number ) is the sum of the two preceding numbers. The simplest is the series 1, 1, 2, 3, 5, 8, etc.
66
77
```javascript
88
fibonacci(4) // returns the 4th member of the series: 3 (1, 1, 2, 3)

fibonacci/fibonacci.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const fibonacci = function() {
22

3-
}
3+
};
44

5-
module.exports = fibonacci
5+
module.exports = fibonacci;

fibonacci/fibonacci.spec.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,31 @@
11
const fibonacci = require('./fibonacci')
22

3-
describe('fibonacci', function() {
4-
it('works', function() {
5-
expect(fibonacci(4)).toEqual(3);
3+
describe('fibonacci', () => {
4+
test('4th fibonacci number is 3', () => {
5+
expect(fibonacci(4)).toBe(3);
66
});
7-
xit('works', function() {
8-
expect(fibonacci(6)).toEqual(8);
7+
test.skip('6th fibonacci number is 8', () => {
8+
expect(fibonacci(6)).toBe(8);
99
});
10-
xit('works', function() {
11-
expect(fibonacci(10)).toEqual(55);
10+
test.skip('10th fibonacci number is 55', () => {
11+
expect(fibonacci(10)).toBe(55);
1212
});
13-
xit('works', function() {
14-
expect(fibonacci(15)).toEqual(610);
13+
test.skip('15th fibonacci number is 610', () => {
14+
expect(fibonacci(15)).toBe(610);
1515
});
16-
xit('works', function() {
17-
expect(fibonacci(25)).toEqual(75025);
16+
test.skip('25th fibonacci number is 75025', () => {
17+
expect(fibonacci(25)).toBe(75025);
1818
});
19-
xit('doesn\'t accept negatives', function() {
20-
expect(fibonacci(-25)).toEqual("OOPS");
19+
test.skip('doesn\'t accept negatives', () => {
20+
expect(fibonacci(-25)).toBe("OOPS");
2121
});
22-
xit('DOES accept strings', function() {
23-
expect(fibonacci("1")).toEqual(1);
22+
test.skip('DOES accept strings', () => {
23+
expect(fibonacci("1")).toBe(1);
2424
});
25-
xit('DOES accept strings', function() {
26-
expect(fibonacci("2")).toEqual(1);
25+
test.skip('DOES accept strings', () => {
26+
expect(fibonacci("2")).toBe(1);
2727
});
28-
xit('DOES accept strings', function() {
29-
expect(fibonacci("8")).toEqual(21);
28+
test.skip('DOES accept strings', () => {
29+
expect(fibonacci("8")).toBe(21);
3030
});
3131
});

findTheOldest/README.md

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
# Find the Oldest
1+
# Exercise 12 - Find the Oldest
22

3-
given an array of objects representing people with a birth and death year, return the oldest person.
3+
Given an array of objects representing people with a birth and death year, return the oldest person.
44

55
## Hints
66
- You should return the whole person object, but the tests mostly just check to make sure the name is correct.
77
- this can be done with a couple of chained array methods, or by using `reduce`.
88
- One of the tests checks for people with no death-date.. use JavaScript's Date function to get their age as of today.
9-

findTheOldest/findTheOldest.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
let findTheOldest = function() {
1+
const findTheOldest = function() {
22

3-
}
3+
};
44

5-
module.exports = findTheOldest
5+
module.exports = findTheOldest;

0 commit comments

Comments
 (0)