This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.test.js
78 lines (73 loc) · 1.95 KB
/
index.test.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
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
import { calculate, calculateFromMonths } from './index.js';
describe('calculateDownProbability', () => {
describe('calculate', () => {
it('should calculate from months only', () => {
expect(calculate(20, 3)).toEqual({
percent: 0.06626905235255136,
decimal: 0.0006626905235255136,
perBirth: '1/1509',
});
expect(calculate(44, 10)).toEqual({
percent: 3.3333333333333335,
decimal: 0.03333333333333333,
perBirth: '1/30',
});
});
it('should throw for stupid param in first position', () => {
expect(() => {
calculate();
}).toThrow();
expect(() => {
calculate(null);
}).toThrow();
expect(() => {
calculate('');
}).toThrow();
expect(() => {
calculate('abcd');
}).toThrow();
});
it('should throw for stupid param in second position', () => {
expect(() => {
calculate(20);
}).toThrow();
expect(() => {
calculate(20, null);
}).toThrow();
expect(() => {
calculate(20, '');
}).toThrow();
expect(() => {
calculate(20, 'abcd');
}).toThrow();
});
});
describe('calculateFromMonths', () => {
it('should calculate from years and months', () => {
expect(calculateFromMonths(185)).toEqual({
percent: 0.06476683937823835,
decimal: 0.0006476683937823834,
perBirth: '1/1544',
});
expect(calculateFromMonths(784)).toEqual({
percent: 7.6923076923076925,
decimal: 0.07692307692307693,
perBirth: '1/13',
});
});
it('should throw for stupid param', () => {
expect(() => {
calculateFromMonths();
}).toThrow();
expect(() => {
calculateFromMonths(null);
}).toThrow();
expect(() => {
calculateFromMonths('');
}).toThrow();
expect(() => {
calculateFromMonths('abcd');
}).toThrow();
});
});
});