forked from knaxus/problem-solving-javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct-of-elements.test.js
53 lines (48 loc) · 1.37 KB
/
product-of-elements.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const { findProduct, findProduct2 } = require('.');
describe('Productof elements', () => {
let array = [];
describe('When count of zero is 0', () => {
beforeEach(() => {
array = [1, 2, 3, 4];
});
it('With 1st Approach', () => {
expect(findProduct(array)).toEqual([24, 12, 8, 6]);
});
it('With 2st Approach', () => {
expect(findProduct2(array)).toEqual([24, 12, 8, 6]);
});
});
describe('When count of zero is 1', () => {
beforeEach(() => {
array = [2, 3, 0, 4];
});
it('With 1st Approach', () => {
expect(findProduct(array)).toEqual([0, 0, 24, 0]);
});
it('With 2st Approach', () => {
expect(findProduct2(array)).toEqual([0, 0, 24, 0]);
});
});
describe('When count of zero is 2', () => {
beforeEach(() => {
array = [0, 3, 0, 4];
});
it('With 1st Approach', () => {
expect(findProduct(array)).toEqual([0, 0, 0, 0]);
});
it('With 2st Approach', () => {
expect(findProduct2(array)).toEqual([0, 0, 0, 0]);
});
});
describe('When count of zero is greater than 2', () => {
beforeEach(() => {
array = [0, 3, 0, 4, 8, 0];
});
it('With 1st Approach', () => {
expect(findProduct(array)).toEqual([0, 0, 0, 0, 0, 0]);
});
it('With 2st Approach', () => {
expect(findProduct2(array)).toEqual([0, 0, 0, 0, 0, 0]);
});
});
});