-
Notifications
You must be signed in to change notification settings - Fork 1
/
fixed_test.go
43 lines (39 loc) · 992 Bytes
/
fixed_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
package fixed
import (
"testing"
)
func max64(x int64, y int64) int64 {
if x > y {
return x
}
return y
}
func min64(x int64, y int64) int64 {
if x < y {
return x
}
return y
}
func TestFixed(t *testing.T) {
for _, tc := range testCases {
x := From(tc.x)
if x.Float() != tc.x {
t.Errorf("tc.x=%v: Float: got %v, want %v", tc.x, x.Float(), x)
}
if got, want := x.String(), tc.s; got != want {
t.Errorf("tc.x=%v: String: got %q, want %q", tc.x, got, want)
}
if got, want := x.Floor(), int64(tc.floor); got != want {
t.Errorf("tc.x=%v: Floor: got %v, want %v", tc.x, got, want)
}
if got, want := x.Round(), int64(tc.round); got != want {
t.Errorf("tc.x=%v: Round: got %v, want %v", tc.x, got, want)
}
if got, want := x.Ceil(), int64(tc.ceil); got != want {
t.Errorf("tc.x=%v: Ceil: got %v, want %v", tc.x, got, want)
}
if got, want := x.Mul(One), x; got != want {
t.Errorf("tc.x=%v: Mul by one: got %v, want %v", tc.x, got, want)
}
}
}