-
Notifications
You must be signed in to change notification settings - Fork 931
/
Copy pathprimes.spec.js
53 lines (42 loc) · 1.17 KB
/
primes.spec.js
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
const { nextPrime, isPrime, isOdd } = require('./primes');
describe('Prime Util Tests', () => {
describe('#isPrime', () => {
test('2 is prime', () => {
expect(isPrime(2)).toBe(true);
});
test('1 is not prime', () => {
expect(isPrime(1)).toBe(false);
});
test('large prime number', () => {
expect(isPrime(914021)).toBe(true);
});
test('non prime number', () => {
expect(isPrime(99)).toBe(false);
});
});
describe('#isOdd', () => {
it('odd number', () => {
expect(isOdd(1)).toBe(true);
});
it('even number', () => {
expect(isOdd(10)).toBe(false);
});
it('zero is an even number', () => {
expect(isOdd(0)).toBe(false);
});
});
describe('#nextPrime', () => {
it('should find the next prime of 19', () => {
expect(nextPrime(38)).toBe(41);
});
it('should find the next prime of 11558', () => {
expect(nextPrime(11558)).toBe(11579);
});
it('should find the next prime of large number', () => {
expect(nextPrime(11579 * 2)).toBe(23159);
});
it('should find of negative number', () => {
expect(nextPrime(-1)).toBe(2);
});
});
});