-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Expand file tree
/
Copy pathIsOdd.test.js
More file actions
51 lines (41 loc) · 1.59 KB
/
IsOdd.test.js
File metadata and controls
51 lines (41 loc) · 1.59 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
import { isOdd, isOddBitwise } from '../IsOdd'
describe('Testing isOdd function', () => {
const randomNumber = Math.floor(Math.random() * 1999999) - 999999
it("will test a value which shouldn't be odd: 4", () => {
const isOddNumber = isOdd(4)
expect(isOddNumber).toBe(false)
})
it('will test a value which should be odd: 7', () => {
const isOddNumber = isOdd(7)
expect(isOddNumber).toBe(true)
})
it(`will test a random value: ${randomNumber}`, () => {
const isOddNumber = isOdd(randomNumber)
expect(isOddNumber).toBe(Boolean(randomNumber % 2) !== false)
})
it('will test a TypeError for non-number inputs', () => {
expect(() => isOdd('10')).toThrow(TypeError)
expect(() => isOdd(null)).toThrow(TypeError)
expect(() => isOdd(undefined)).toThrow(TypeError)
expect(() => isOdd(NaN)).toThrow(TypeError)
})
})
describe('Testing isOddBitwise function', () => {
const randomNumber = Math.floor(Math.random() * 1999999) - 999999
it("will test a value which shouldn't be odd: 6", () => {
const isOddNumber = isOddBitwise(6)
expect(isOddNumber).toBe(false)
})
it('will test a value which should be odd: 3', () => {
const isOddNumber = isOddBitwise(3)
expect(isOddNumber).toBe(true)
})
it(`will test a random value: ${randomNumber}`, () => {
const isOddNumber = isOddBitwise(randomNumber)
expect(isOddNumber).toBe(Boolean(randomNumber & 1) !== false)
})
it('will test a TypeError for non-number inputs', () => {
expect(() => isOddBitwise('10')).toThrow(TypeError)
expect(() => isOddBitwise({})).toThrow(TypeError)
})
})