-
Notifications
You must be signed in to change notification settings - Fork 10
/
percent_test.go
59 lines (46 loc) · 1.04 KB
/
percent_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
package percent
import (
"testing"
)
func TestPercent(t *testing.T) {
pct, total := 25, 200
part := Percent(pct, total)
if part != 50.0 {
t.Fatalf("%d is wrong number for %d percent", int(part), pct)
}
}
func TestPercentFloat(t *testing.T) {
pct, total := 25.0, 200.0
part := PercentFloat(pct, total)
if part != 50.0 {
t.Fatalf("%d is wrong number for %f percent!", int(part), pct)
}
}
func TestPercentOf(t *testing.T) {
part, total := 300, 2400
pct := PercentOf(part, total)
if pct != 12.5 {
t.Fatalf("%f is wrong percent!", pct)
}
}
func TestPercentOfFloat(t *testing.T) {
part, total := 300.0, 2400.0
pct := PercentOfFloat(part, total)
if pct != 12.5 {
t.Fatalf("%f is wrong percent!", pct)
}
}
func TestChange(t *testing.T) {
before, after := 20, 60
pct := Change(before, after)
if int(pct) != 200.0 {
t.Fatalf("%f is wrong percent!", pct)
}
}
func TestChangeFloat(t *testing.T) {
before, after := 20.0, 60.0
pct := ChangeFloat(before, after)
if int(pct) != 200.0 {
t.Fatalf("%f is wrong percent!", pct)
}
}