-
Notifications
You must be signed in to change notification settings - Fork 1
/
questions.spec.ts
80 lines (68 loc) · 2.21 KB
/
questions.spec.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
import { availableHearts } from './questions';
import { describe, test } from 'node:test';
import assert from 'node:assert/strict';
// Test availableHearts function
describe('service: forumQuestions', () => {
test('calculates available hearts correctly', () => {
const numProposals = 2;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.8;
const result = availableHearts(numProposals, baseNumerator, baseDenominator, maxRatio);
assert.equal(result, 5);
});
test('error if max ratio was not calculated correctly', () => {
const numProposals = 2;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.9;
const result = availableHearts(numProposals, baseNumerator, baseDenominator, maxRatio);
assert.equal(result, 0);
});
test('returns custom hearts if customHearts is set', () => {
const numProposals = 2;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.8;
const customHearts = 10;
const result = availableHearts(
numProposals,
baseNumerator,
baseDenominator,
maxRatio,
customHearts,
);
assert.equal(result, customHearts);
});
test('executes the function if customHearts is not set', () => {
const numProposals = 2;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.8;
const result = availableHearts(numProposals, baseNumerator, baseDenominator, maxRatio);
assert.equal(result, 5);
});
test('executes the function if customHearts is set to less than 2', () => {
const numProposals = 2;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.8;
const customHearts = 1;
const result = availableHearts(
numProposals,
baseNumerator,
baseDenominator,
maxRatio,
customHearts,
);
assert.equal(result, 5);
});
test('that function returns 0 in case the number of proposals are less than 2', () => {
const numProposals = 1;
const baseNumerator = 4;
const baseDenominator = 5;
const maxRatio = 0.8;
const result = availableHearts(numProposals, baseNumerator, baseDenominator, maxRatio);
assert.equal(result, 0);
});
});