main
1package pipeline
2
3import (
4 "math"
5 "testing"
6)
7
8func TestCalculateSpeed(t *testing.T) {
9 tests := []struct {
10 name string
11 totalDuration float64
12 cfg SpeedConfig
13 expectedSpeed float64
14 expectedOutput float64
15 }{
16 {
17 name: "exact target",
18 totalDuration: 6000, // 100 minutes
19 cfg: SpeedConfig{
20 TargetSecs: 600,
21 MinSpeedMult: 1.0,
22 MaxSpeedMult: 2000.0,
23 },
24 expectedSpeed: 10.0,
25 expectedOutput: 600.0,
26 },
27 {
28 name: "less than target",
29 totalDuration: 300, // 5 minutes
30 cfg: SpeedConfig{
31 TargetSecs: 600,
32 MinSpeedMult: 1.0,
33 MaxSpeedMult: 2000.0,
34 },
35 expectedSpeed: 1.0, // Clamped to min
36 expectedOutput: 300.0,
37 },
38 {
39 name: "very long duration",
40 totalDuration: 86400, // 24 hours
41 cfg: SpeedConfig{
42 TargetSecs: 600,
43 MinSpeedMult: 1.0,
44 MaxSpeedMult: 2000.0,
45 },
46 expectedSpeed: 144.0, // 86400 / 600
47 expectedOutput: 600.0,
48 },
49 {
50 name: "exceeds max speed",
51 totalDuration: 2000000, // Very long
52 cfg: SpeedConfig{
53 TargetSecs: 600,
54 MinSpeedMult: 1.0,
55 MaxSpeedMult: 100.0,
56 },
57 expectedSpeed: 100.0, // Clamped to max
58 expectedOutput: 20000.0,
59 },
60 {
61 name: "zero duration",
62 totalDuration: 0,
63 cfg: DefaultSpeedConfig(),
64 expectedSpeed: 1.0,
65 expectedOutput: 0,
66 },
67 }
68
69 for _, tc := range tests {
70 t.Run(tc.name, func(t *testing.T) {
71 speed, output := CalculateSpeed(tc.totalDuration, tc.cfg)
72
73 if math.Abs(speed-tc.expectedSpeed) > 0.001 {
74 t.Errorf("speed = %v, want %v", speed, tc.expectedSpeed)
75 }
76 if math.Abs(output-tc.expectedOutput) > 0.001 {
77 t.Errorf("output duration = %v, want %v", output, tc.expectedOutput)
78 }
79 })
80 }
81}