-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
60 lines (53 loc) · 1.62 KB
/
Copy pathindex.test.ts
File metadata and controls
60 lines (53 loc) · 1.62 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import { simpleCalculator, Action } from './index';
describe('simpleCalculator tests', () => {
test('should add two numbers', () => {
const a = 2;
const b = 10;
const sum = simpleCalculator({ a, b, action: Action.Add });
expect(sum).toBe(a + b);
}, 30);
test('should subtract two numbers', () => {
const a = 10;
const b = 14;
const diff = simpleCalculator({ a, b, action: Action.Subtract });
expect(diff).toBe(a - b);
});
test('should multiply two numbers', () => {
const a = 10;
const b = 14;
const mult = simpleCalculator({ a, b, action: Action.Multiply });
expect(mult).toBe(a * b);
});
test('should divide two numbers', () => {
const a = 22;
const b = 2;
const div = simpleCalculator({ a, b, action: Action.Divide });
expect(div).toBe(a / b);
});
test('should exponentiate two numbers', () => {
const a = 12;
const b = 2;
const exp = simpleCalculator({ a, b, action: Action.Exponentiate });
expect(exp).toBe(a ** b);
});
test('should return null for invalid action', () => {
const res = simpleCalculator({ a: 2, b: 2, action: 'Purify' });
expect(res).toBeNull();
});
test('should return null for invalid arguments', () => {
const invalidA = simpleCalculator({ a: 'hi', b: 2, action: Action.Add });
const invalidB = simpleCalculator({
a: 10,
b: 'invalid',
action: Action.Subtract,
});
const invalidArgs = simpleCalculator({
a: 'hi',
b: 'invalid',
action: 'action',
});
expect(invalidA).toBeNull();
expect(invalidB).toBeNull();
expect(invalidArgs).toBeNull();
});
});