UNPKG

2.06 kBJavaScriptView Raw
1/* eslint-env mocha */
2
3const chai = require('chai')
4const expect = chai.expect
5const calculateGrowthCurve = require('./../lib/components/services/rankings/calculate-growth-curve')
6const growthCurveIntersection = require('./../lib/components/services/rankings/growth-curve-intersection')
7
8describe('calculated risk score', () => {
9 const growthCurves = [
10 {
11 maxScore: 146,
12 meanRisk: 79,
13 highRiskThreshold: 98,
14 exp: -0.0025,
15 expectedDays: 220
16 },
17 {
18 maxScore: 146,
19 meanRisk: 79,
20 highRiskThreshold: 98,
21 exp: -0.0004,
22 expectedDays: 1372 // spreadsheet caption says 1432 and 1171 but they're both wrong - if you examine the figures it is 1372
23 },
24 {
25 maxScore: 146,
26 meanRisk: 79,
27 highRiskThreshold: 98,
28 exp: -0.00088,
29 expectedDays: 624 // spreadsheet caption says 532, but checking the figures gives 624
30 }
31 ]
32
33 for (const curves of growthCurves) {
34 const {
35 maxScore,
36 meanRisk,
37 highRiskThreshold,
38 exp,
39 expectedDays
40 } = curves
41
42 it(`${meanRisk} to ${highRiskThreshold} with exp = ${exp} takes ${expectedDays} days`, () => {
43 const baseline = growthCurveIntersection(maxScore, meanRisk, exp)
44 const target = growthCurveIntersection(maxScore, highRiskThreshold, exp)
45
46 const daysElapsed = target - baseline
47
48 expect(daysElapsed).to.equal(expectedDays)
49 })
50 }
51
52 for (const curves of growthCurves) {
53 const {
54 maxScore: assessedScore,
55 meanRisk: temporaryScore,
56 highRiskThreshold: expectedScore,
57 exp,
58 expectedDays: elapsedDays
59 } = curves
60
61 it(`TRS of ${temporaryScore} with exp = ${exp} after ${elapsedDays} days is ${expectedScore}`, () => {
62 const dayOffset = growthCurveIntersection(assessedScore, temporaryScore, exp)
63
64 const effectiveDaysElapsed = elapsedDays + dayOffset
65
66 const modifiedScore = calculateGrowthCurve(exp, effectiveDaysElapsed, assessedScore)
67
68 expect(Math.round(modifiedScore)).to.equal(expectedScore)
69 })
70 }
71})