-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
32 lines (30 loc) · 1.29 KB
/
index.test.ts
File metadata and controls
32 lines (30 loc) · 1.29 KB
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
// Uncomment the code below and write your tests
import { simpleCalculator, Action } from './index';
const testCases = [
{ a: 1, b: 2, action: Action.Add, expected: 3 },
{ a: 2, b: 2, action: Action.Add, expected: 4 },
{ a: 3, b: 2, action: Action.Add, expected: 5 },
{ a: 3, b: 2, action: Action.Subtract, expected: 1 },
{ a: 2, b: 2, action: Action.Subtract, expected: 0 },
{ a: 6, b: 2, action: Action.Subtract, expected: 4 },
{ a: 1, b: 1, action: Action.Multiply, expected: 1 },
{ a: 2, b: 2, action: Action.Multiply, expected: 4 },
{ a: 6, b: 2, action: Action.Multiply, expected: 12 },
{ a: 12, b: 6, action: Action.Divide, expected: 2 },
{ a: 2, b: 2, action: Action.Divide, expected: 1 },
{ a: 6, b: 2, action: Action.Divide, expected: 3 },
{ a: 2, b: 3, action: Action.Exponentiate, expected: 8 },
{ a: 1, b: 3, action: Action.Exponentiate, expected: 1 },
{ a: 6, b: 2, action: Action.Exponentiate, expected: 36 },
{ a: 6, b: null, action: Action.Exponentiate, expected: null },
{ a: 6, b: 5, action: '&&', expected: null },
];
describe('simpleCalculator', () => {
it.each(testCases)(
'The correct values must be calculated',
({ a, b, action, expected }) => {
const result = simpleCalculator({ a, b, action });
expect(result).toBe(expected);
},
);
});