-
Notifications
You must be signed in to change notification settings - Fork 26
Expand file tree
/
Copy pathcalculator.test.js
More file actions
41 lines (36 loc) · 1.02 KB
/
calculator.test.js
File metadata and controls
41 lines (36 loc) · 1.02 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
import { expect, test } from 'vitest'
import {
add,
divide,
multiply,
subtract,
} from './calculator'
test('add function', () => {
expect(add(1, 2)).toBe(3);
expect(add(1.0, 2.0)).toBe(3.0);
expect(add(0, 2.0)).toBe(2.0);
expect(add(2.0, 0)).toBe(2.0);
expect(add(-4, 2.0)).toBe(-2.0);
});
test('subtract function', () => {
expect(subtract(1, 2)).toBe(-1.0);
expect(subtract(2, 1)).toBe(1.0);
expect(subtract(1.0, 2.0)).toBe(-1.0);
expect(subtract(0, 2.0)).toBe(-2.0);
expect(subtract(2.0, 0)).toBe(2.0);
expect(subtract(-4, 2.0)).toBe(-6.0);
});
test('multiply function', () => {
expect(multiply(1, 2)).toBe(2.0);
expect(multiply(1.0, 2.0)).toBe(2.0);
expect(multiply(0, 2.0)).toBe(0.0);
expect(multiply(2.0, 0)).toBe(0.0);
expect(multiply(-4, 2.0)).toBe(-8.0);
});
test('divide function', () => {
expect(divide(1, 2)).toBe(0.5);
expect(divide(1.0, 2.0)).toBe(0.5);
expect(divide(0, 2.0)).toBe(0);
expect(divide(-4, 2.0)).toBe(-2.0);
// expect(divide(2.0, 0)).toBe('Cannot divide by 0');
});