-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathindex.test.ts
More file actions
43 lines (36 loc) · 1.27 KB
/
index.test.ts
File metadata and controls
43 lines (36 loc) · 1.27 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
// Uncomment the code below and write your tests
import { simpleCalculator, Action } from './index';
describe('simpleCalculator tests', () => {
test('should add two numbers', () => {
const result = simpleCalculator({ a: 2, b: 3, action: Action.Add });
expect(result).toBe(5);
});
test('should subtract two numbers', () => {
const result = simpleCalculator({ a: 10, b: 7, action: Action.Subtract });
expect(result).toBe(3);
});
test('should multiply two numbers', () => {
const result = simpleCalculator({ a: 3, b: 11, action: Action.Multiply });
expect(result).toBe(33);
});
test('should divide two numbers', () => {
const result = simpleCalculator({ a: 33, b: 11, action: Action.Divide });
expect(result).toBe(3);
});
test('should exponentiate two numbers', () => {
const result = simpleCalculator({
a: 2,
b: 3,
action: Action.Exponentiate,
});
expect(result).toBe(8);
});
test('should return null for invalid action', () => {
const result = simpleCalculator({ a: 2, b: 3, action: '&&' });
expect(result).toBeNull();
});
test('should return null for invalid arguments', () => {
const result = simpleCalculator({ a: 2, b: null, action: Action.Multiply });
expect(result).toBeNull();
});
});