-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmath.test.ts
98 lines (82 loc) · 1.67 KB
/
math.test.ts
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { ref } from 'vue-demi'
import { describe, it } from 'vitest'
import { divide, gcd, is, lcm, mod, multiply, negative, set, subtract, sum } from '../src'
import { $expect } from './utils'
describe('reactiveMath', () => {
it('negative', () => {
const a = ref(9)
const c = negative(a)
$expect(is(c, -9))
$expect(is(a, 9))
set(a, 10)
$expect(is(c, -10))
})
it('sum', () => {
const a = ref(1)
const b = ref(2)
const c = ref(3)
const d = sum(a, b, c)
$expect(is(d, 6))
set(a, 10)
set(b, 15)
$expect(is(d, 28))
})
it('subtract', () => {
const a = ref(1)
const b = ref(2)
const c = subtract(a, b)
$expect(is(c, -1))
set(a, 20)
set(b, 15)
$expect(is(c, 5))
})
it('multiply', () => {
const a = ref(1)
const b = ref(2)
const c = ref(3)
const d = multiply(a, b, c)
$expect(is(d, 6))
set(a, 4)
set(b, 5)
$expect(is(d, 60))
})
it('divide', () => {
const a = ref(1)
const b = ref(2)
const c = divide(a, b)
$expect(is(c, 0.5))
set(a, 20)
set(b, 10)
$expect(is(c, 2))
})
it('mod', () => {
const a = ref(15)
const b = ref(9)
const c = mod(a, b)
$expect(is(c, 6))
$expect(is(b, 9))
set(a, 3)
set(b, 2)
$expect(is(c, 1))
})
it('gcd', () => {
const a = ref(9)
const b = ref(15)
const c = gcd(a, b)
$expect(is(c, 3))
$expect(is(a, 9))
set(a, 14)
set(b, 21)
$expect(is(c, 7))
$expect(is(a, 14))
})
it('lcm', () => {
const a = ref(2)
const b = ref(3)
const c = lcm(a, b)
$expect(is(c, 6))
set(a, 7)
set(b, 14)
$expect(is(c, 14))
})
})