1 |
|
2 |
|
3 | const chai = require('chai')
|
4 | const expect = chai.expect
|
5 | const calculateGrowthCurve = require('./../lib/components/services/rankings/calculate-growth-curve')
|
6 |
|
7 | function roundToSixDp (num) {
|
8 | return +(num.toFixed(7).slice(0, -1))
|
9 | }
|
10 |
|
11 | describe('growth curve validation', () => {
|
12 | const factors = [
|
13 | {
|
14 | score: 146,
|
15 | exp: -0.00088,
|
16 | expected: [
|
17 | [0, 1.780487],
|
18 | [1, 1.782036],
|
19 | [2, 1.783585],
|
20 | [10, 1.796031],
|
21 | [50, 1.859558],
|
22 | [365, 2.443615],
|
23 | [600, 2.993493]
|
24 | ]
|
25 | },
|
26 | {
|
27 | score: 146,
|
28 | exp: -0.0025,
|
29 | expected: [
|
30 | [0, 1.780487],
|
31 | [1, 1.784890],
|
32 | [2, 1.789303],
|
33 | [10, 1.824997],
|
34 | [50, 2.014286],
|
35 | [365, 4.355211],
|
36 | [600, 7.654582],
|
37 | [2000, 94.451082],
|
38 | [2400, 121.587743],
|
39 | [10000, 145.999999]
|
40 | ]
|
41 | }
|
42 | ]
|
43 |
|
44 | for (const { score, exp, expected } of factors) {
|
45 | describe(`RIDGE score of ${score} with ${exp} exponent`, () => {
|
46 | for (const [days, target] of expected) {
|
47 | it(`${days} days elapsed`, () => {
|
48 | const curve = calculateGrowthCurve(
|
49 | exp,
|
50 | days,
|
51 | score
|
52 | )
|
53 |
|
54 | expect(
|
55 | roundToSixDp(curve)
|
56 | )
|
57 | .to.be.eql(target)
|
58 | })
|
59 | }
|
60 | })
|
61 | }
|
62 | })
|