-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.ts
108 lines (88 loc) · 4.07 KB
/
test.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
// Code under test
import { calculate, Drag, IInput, IOutput, RollingResistanceCoefficient } from "../BikeCalculator";
// Test infra
import * as chai from "chai";
const expect = chai.expect;
// Test input - baseline values
let input: IInput;
// Tests themselves
describe("#test-calculations", () => {
beforeEach(() => {
input = {
bikeWeightInKg: 9,
casetteChainRingTeethCount: 28,
crankLengthInMillimeters: 170,
desiredConstantSpeedInKmPerHour: 10,
drag: Drag.StraightArms,
frontChainRingTeethCount: 34,
gradeInPercent: 10, // Hill incline
mechanicalLosses: 5, // (3-5% is typical)
riderWeightInKg: 82,
rollingResistanceCoefficient: RollingResistanceCoefficient.RoadClinchersRacingTiresAt95Psi,
wheelDiameterInMillimeters: 685.8,
};
});
it("baseline values", () => {
// Where power goes?
expect(Math.round(calculate(input).requiredHillPowerInPercentage)).to.be.eql(90);
expect(Math.round(calculate(input).requiredAirPowerInPercentage)).to.be.eql(1);
expect(Math.round(calculate(input).requiredRollPowerInPercentage)).to.be.eql(4);
expect(Math.round(calculate(input).powerLostToMechanicalLossesInPercentage)).to.be.eql(5);
// What is needed?
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(275);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("lose 5kg", () => {
input.riderWeightInKg -= 5;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(260);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("get bike which weights 5kg", () => {
input.bikeWeightInKg = 5;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(263);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("get bike which weights nothing", () => {
input.bikeWeightInKg = 0;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(248);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("lose 10kg", () => {
input.riderWeightInKg -= 10;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(245);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("climb 15%", () => {
input.gradeInPercent = 15;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(402);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("climb 20%", () => {
input.gradeInPercent = 20;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(527);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("climb 25%", () => {
input.gradeInPercent = 25;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(648);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("get compact chainset", () => {
input.frontChainRingTeethCount = 34;
input.casetteChainRingTeethCount = 28;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(275);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(63);
});
it("get compact chainset and 32 chainring back", () => {
input.frontChainRingTeethCount = 34;
input.casetteChainRingTeethCount = 32;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(275);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(72);
});
it("get compact chainset and 34 chainring back", () => {
input.frontChainRingTeethCount = 34;
input.casetteChainRingTeethCount = 34;
expect(Math.round(calculate(input).requiredTotalInputInWatts)).to.be.eql(275);
expect(Math.round(calculate(input).pedalSpeedInRPM)).to.be.eql(77);
});
});