-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathLCM.test.js
More file actions
28 lines (24 loc) · 697 Bytes
/
LCM.test.js
File metadata and controls
28 lines (24 loc) · 697 Bytes
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
import { describe, it, expect } from 'vitest'
import { lcm } from '../LCM'
describe('lcm()', () => {
it('returns 0 when either argument is 0', () => {
expect(lcm(0, 5)).toBe(0)
expect(lcm(7, 0)).toBe(0)
})
it('computes LCM for positive integers', () => {
expect(lcm(4, 6)).toBe(12)
expect(lcm(7, 3)).toBe(21)
expect(lcm(21, 6)).toBe(42)
})
it('computes LCM when inputs are negative', () => {
expect(lcm(-4, 6)).toBe(12)
expect(lcm(4, -6)).toBe(12)
expect(lcm(-4, -6)).toBe(12)
})
it('throws for non-numeric inputs', () => {
// @ts-ignore
expect(() => lcm('a', 5)).toThrow()
// @ts-ignore
expect(() => lcm(4, {})).toThrow()
})
})