Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Post class19 #259

Merged
merged 2 commits into from
Jan 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions Week1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,42 @@ In week one we will discuss the following topics:
- Live Server
- Bracket Pair Colorizer

2. Install the ESLint tool globally by issuing the following command from the command line:
2. Modify the VSCode User Settings to include the settings listed below. If a particular setting is already present in your User Settings, make sure that the setting value listed below is used and change it if necessary.

To open your user and workspace settings, use the following VS Code menu command:

- On Windows/Linux - **File** > **Preferences** > **Settings**
- On macOS - **Code** > **Preferences** > **Settings**

Then, click on the `{ }` button in the top-right corner of the settings screen to access the settings in JSON format.

```json
/// Place your settings in this file to overwrite the default settings
{
"editor.detectIndentation": false,
"editor.formatOnSave": true,
"editor.formatOnType": true,
"editor.minimap.enabled": false,
"editor.renderIndentGuides": true,
"editor.tabSize": 2,
"files.autoSave": "onFocusChange",
"prettier.printWidth": 100,
"prettier.singleQuote": true,
"prettier.trailingComma": "es5"
}
```

3. Install the ESLint CLI tool globally by issuing the following command from the command line:

```
npm install -g eslint
npm install -g eslint-cli
```

3. Fork this repository (i.e., **JavaScript2**) and clone your fork to your laptop.
4. Fork this repository (i.e., **JavaScript2**) and clone your fork to your laptop.

4. Open the `JavaScript2` folder from the cloned repository in VSCode.
5. Open the `JavaScript2` folder from the cloned repository in VSCode.

5. Open a terminal window in VSCode and type the following command:
6. Open a terminal window in VSCode and type the following command:

```
npm install
Expand Down
10 changes: 6 additions & 4 deletions Week2/test/maartjes-work.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const { maartjesTasks, maartjesHourlyRate, computeEarnings } = require(`../homework/maartjes-work`);

test('maartjes_work.js', () => {
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
const result = earnings.toFixed(2);
expect(result).toBe('373.33');
describe('maartjes_work', () => {
test('earnings rounded to euro cents', () => {
const earnings = computeEarnings(maartjesTasks, maartjesHourlyRate);
const result = earnings.toFixed(2);
expect(result).toBe('373.33');
});
});
8 changes: 5 additions & 3 deletions Week2/test/map-filter.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { myNumbers, doubleOddNumbers } = require(`../homework/map-filter`);

test('map_filter.js', () => {
const result = doubleOddNumbers(myNumbers);
expect(result).toEqual([2, 6]);
describe('map_filter', () => {
test('result -> [2, 6]', () => {
const result = doubleOddNumbers(myNumbers);
expect(result).toEqual([2, 6]);
});
});
8 changes: 5 additions & 3 deletions Week3/test/step2-1.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ const foo = require('../homework/step2-1');

const mockFn = jest.fn(() => undefined);

test('1-step3.js', () => {
foo(mockFn);
expect(mockFn.mock.calls.length).toBe(1);
describe('step2-1', () => {
test('foo calls func', () => {
foo(mockFn);
expect(mockFn.mock.calls.length).toBe(1);
});
});
22 changes: 14 additions & 8 deletions Week3/test/step2-2.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ const threeFive = require('../homework/step2-2');
const mockSayThree = jest.fn(() => undefined);
const mockSayFive = jest.fn(() => undefined);

test('2-step3.js', () => {
threeFive(10, 15, mockSayThree, mockSayFive);
describe('step2-2', () => {
test('12 and 15 divisible by 3', () => {
threeFive(10, 15, mockSayThree, () => undefined);

expect(mockSayThree.mock.calls.length).toBe(2);
expect(mockSayThree.mock.calls[0][0]).toBe(12);
expect(mockSayThree.mock.calls[1][0]).toBe(15);
expect(mockSayThree.mock.calls.length).toBe(2);
expect(mockSayThree.mock.calls[0][0]).toBe(12);
expect(mockSayThree.mock.calls[1][0]).toBe(15);
});

expect(mockSayFive.mock.calls.length).toBe(2);
expect(mockSayFive.mock.calls[0][0]).toBe(10);
expect(mockSayFive.mock.calls[1][0]).toBe(15);
test('10 and 15 divisible by 5', () => {
threeFive(10, 15, () => undefined, mockSayFive);

expect(mockSayFive.mock.calls.length).toBe(2);
expect(mockSayFive.mock.calls[0][0]).toBe(10);
expect(mockSayFive.mock.calls[1][0]).toBe(15);
});
});
57 changes: 44 additions & 13 deletions Week3/test/step2-3.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,68 @@ const {
repeatStringNumTimesWithDoWhile
} = require('../homework/step2-3');

describe('1-step3.js', () => {
test('for-loop', () => {
let result = repeatStringNumTimesWithFor('abc', 3);
describe('step2-3 with for-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithFor('abc', 3);
expect(result).toBe('abcabcabc');
});

result = repeatStringNumTimesWithFor('abc', 1);
test('num = 1', () => {
const result = repeatStringNumTimesWithFor('abc', 1);
expect(result).toBe('abc');
});

result = repeatStringNumTimesWithFor('abc', -2);
test('num = -2', () => {
const result = repeatStringNumTimesWithFor('abc', -2);
expect(result).toBe('');
});

test('while-loop', () => {
let result = repeatStringNumTimesWithWhile('abc', 3);
test('num = 0', () => {
const result = repeatStringNumTimesWithFor('abc', 0);
expect(result).toBe('');
});
});

describe('step2-3 with while-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithWhile('abc', 3);
expect(result).toBe('abcabcabc');
});

result = repeatStringNumTimesWithFor('abc', 1);
test('num = 1', () => {
const result = repeatStringNumTimesWithWhile('abc', 1);
expect(result).toBe('abc');
});

result = repeatStringNumTimesWithFor('abc', -2);
test('num = 0', () => {
const result = repeatStringNumTimesWithWhile('abc', 0);
expect(result).toBe('');
});

test('do-while-loop', () => {
let result = repeatStringNumTimesWithDoWhile('abc', 3);
test('num = -2', () => {
const result = repeatStringNumTimesWithWhile('abc', -2);
expect(result).toBe('');
});
});

describe('step2-3 with do-while-loop', () => {
test('num = 3', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 3);
expect(result).toBe('abcabcabc');
});

result = repeatStringNumTimesWithFor('abc', 1);
test('num = 1', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 1);
expect(result).toBe('abc');
});

test('num = 0', () => {
const result = repeatStringNumTimesWithDoWhile('abc', 0);
expect(result).toBe('');
});

result = repeatStringNumTimesWithFor('abc', -2);
test('num = -2', () => {
const result = repeatStringNumTimesWithDoWhile('abc', -2);
expect(result).toBe('');
});
});
21 changes: 16 additions & 5 deletions Week3/test/step2-4.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,19 @@
const hound = require('../homework/step2-4');

test('4-step3', () => {
expect(typeof hound).toBe('object');
expect(typeof hound.name).toBe('string');
expect(typeof hound.color).toBe('string');
expect(typeof hound.numLegs).toBe('number');
describe('step2-4', () => {
test('hound to be an object', () => {
expect(typeof hound).toBe('object');
});

test('hound.name to be a string', () => {
expect(typeof hound.name).toBe('string');
});

test('hound.color to be a string', () => {
expect(typeof hound.color).toBe('string');
});

test('hound.numLegs to be a number', () => {
expect(typeof hound.numLegs).toBe('number');
});
});
8 changes: 5 additions & 3 deletions Week3/test/step2-5.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const multiplyAll = require('../homework/step2-5');

test('5-step3.js', () => {
const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
expect(result).toBe(5040);
describe('step2-5', () => {
test('result to be product of array elements', () => {
const result = multiplyAll([[1, 2], [3, 4], [5, 6, 7]]);
expect(result).toBe(5040);
});
});
7 changes: 4 additions & 3 deletions Week3/test/step2-6.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-return-assign, dot-notation */
const { printArray2d, printArray3d } = require('../homework/step2-6');

const arr2d = [[1, 2], [3, 4], [5, 6]];
Expand All @@ -6,18 +7,18 @@ const expected2d = [1, 2, 3, 4, 5, 6].join('');
const arr3d = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]];
const expected3d = [1, 2, 3, 4, 5, 6, 7, 8].join('');

describe('6-step3.js', () => {
describe('step2-6', () => {
let outputData;
const storeLog = (...inputs) => (outputData += inputs.join(' '));

test('printArray2d', () => {
test('printArray2d -> 1, 2, 3, 4, 5, 6', () => {
outputData = '';
console['log'] = jest.fn(storeLog);
printArray2d(arr2d);
expect(outputData).toBe(expected2d);
});

test('printArray2d', () => {
test('printArray3d -> 1, 2, 3, 4, 5, 6, 7, 8', () => {
outputData = '';
console['log'] = jest.fn(storeLog);
printArray3d(arr3d);
Expand Down
12 changes: 7 additions & 5 deletions Week3/test/step3-bonus.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const makeUnique = require(`../homework/step3-bonus`);

test('step4-bonus', () => {
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
const expected = ['a', 'b', 'c', 'd', 'e', 'f'];
const result = makeUnique(values);
expect(result).toEqual(expected);
describe('step3-bonus', () => {
test('array should not contain duplicates', () => {
const values = ['a', 'b', 'c', 'd', 'a', 'e', 'f', 'c'];
const expected = ['a', 'b', 'c', 'd', 'e', 'f'];
const result = makeUnique(values);
expect(result).toEqual(expected);
});
});
16 changes: 12 additions & 4 deletions Week3/test/step3.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
const createBase = require(`../homework/step3`);

test('step4.js', () => {
const addSix = createBase(6);
const result = addSix(10);
expect(result).toBe(16);
describe('step3', () => {
test('base = 6', () => {
const addSix = createBase(6);
const result = addSix(10);
expect(result).toBe(16);
});

test('base = 10', () => {
const addTen = createBase(10);
const result = addTen(10);
expect(result).toBe(20);
});
});