-
Notifications
You must be signed in to change notification settings - Fork 10
/
blip_test.go
47 lines (41 loc) · 1.1 KB
/
blip_test.go
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
// Copyright 2024 Block, Inc.
package blip_test
import (
"testing"
"time"
"github.com/cashapp/blip"
)
func TestTimeLimit(t *testing.T) {
var testCases = []struct {
p float64
in time.Duration
max time.Duration
out time.Duration
}{
{
0.20, // 20% off
time.Duration(1) * time.Second, // 1s
time.Duration(1) * time.Second, // up to 1s
time.Duration(800) * time.Millisecond, // = 800ms
},
{
0.20, // 20% off
time.Duration(10) * time.Second, // 10s
time.Duration(1) * time.Second, // up to 1s
time.Duration(9) * time.Second, // = 9s
},
// Not normal usage, but used for fast testing:
{
0.20, // 20% off
time.Duration(100) * time.Millisecond, // 100ms
time.Duration(20) * time.Millisecond, // up to 20ms
time.Duration(80) * time.Millisecond, // = 80ms
},
}
for _, tc := range testCases {
got := blip.TimeLimit(tc.p, tc.in, tc.max)
if got != tc.out {
t.Errorf("TimeLimit(%v, %v, %v) = %v, expected %v", tc.p, tc.in, tc.max, got, tc.out)
}
}
}