-
-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathutils_test.go
More file actions
54 lines (50 loc) · 1.02 KB
/
utils_test.go
File metadata and controls
54 lines (50 loc) · 1.02 KB
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
package hyperliquid
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRoundToSignificantFigures(t *testing.T) {
tests := []struct {
name string
price float64
sigFigs int
expected float64
}{
{
name: "keeps all digits",
price: 123.456789,
sigFigs: 9,
expected: 123.456789,
},
{
name: "keeps 2 of the 3 decimal places",
price: 123.453,
sigFigs: 5,
expected: 123.45,
},
{
name: "if integer part has more significant figures, return whole integer part",
price: 110454,
sigFigs: 5,
expected: 110454,
},
{
name: "even if sigFigs is 0, return the whole integer part",
price: 24,
sigFigs: 0,
expected: 24,
},
{
name: "test rounding a fraction",
price: 0.00252312,
sigFigs: 5,
expected: 0.0025231,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
rounded := roundToSignificantFigures(test.price, test.sigFigs)
assert.Equal(t, test.expected, rounded)
})
}
}