forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
health_test.go
66 lines (59 loc) · 1.06 KB
/
health_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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package main
import "testing"
func TestToMegaBytes(t *testing.T) {
tests := []struct {
value uint64
expected float64
}{
{1024, 0},
{1024 * 1024, 1},
{1024 * 1024 * 10, 10},
{1024 * 1024 * 100, 100},
{1024 * 1024 * 250, 250},
}
for _, test := range tests {
val := toMegaBytes(test.value)
if val != test.expected {
t.Errorf("Invalid param: %#v != %#v", val, test.expected)
}
}
}
func TestRound(t *testing.T) {
tests := []struct {
value float64
expected int
}{
{0, 0},
{1, 1},
{1.56, 2},
{1.38, 1},
{30.12, 30},
}
for _, test := range tests {
val := round(test.value)
if val != test.expected {
t.Errorf("Invalid param: %#v != %#v", val, test.expected)
}
}
}
func TestToFixed(t *testing.T) {
tests := []struct {
value float64
expected float64
}{
{0, 0},
{1, 1},
{123, 123},
{0.99, 1},
{1.02, 1},
{1.82, 1.8},
{1.56, 1.6},
{1.38, 1.4},
}
for _, test := range tests {
val := toFixed(test.value, 1)
if val != test.expected {
t.Errorf("Invalid param: %#v != %#v", val, test.expected)
}
}
}