aboutsummaryrefslogtreecommitdiffstats
path: root/style/fixed_test.go
blob: 5cae4bf03fb905807f051258988284c3cf8a6d69 (plain) (blame)
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
67
68
69
70
71
72
73
74
package style

import (
	"testing"

	"golang.org/x/image/math/fixed"
)

func TestFixed26ToFloat(t *testing.T) {
	t.Parallel()

	var (
		in        fixed.Int26_6
		out, want float64
	)

	in = 0
	out = fixed26ToFloat(in)
	want = 0
	if out != want {
		t.Errorf("float(%#v) = %v; want %v", in, out, want)
	}

	in = fixed.I(123)
	out = fixed26ToFloat(in)
	want = 123
	if out != want {
		t.Errorf("float(%#v) = %v; want %v", in, out, want)
	}

	in = fixed.I(-123)
	out = fixed26ToFloat(in)
	want = -123
	if out != want {
		t.Errorf("float(%#v) = %v; want %v", in, out, want)
	}

	in = fixed.Int26_6(1<<6 + 1<<4)
	out = fixed26ToFloat(in)
	want = 1.25
	if out != want {
		t.Errorf("float(%#v) = %v; want %v", in, out, want)
	}
}

func TestFloatToFixed26(t *testing.T) {
	t.Parallel()

	var (
		in        float64
		out, want fixed.Int26_6
	)

	in = 0
	out = floatToFixed26(in)
	want = 0
	if out != want {
		t.Errorf("fixed(%#v) = %v; want %v", in, out, want)
	}

	in = 1.25
	out = floatToFixed26(in)
	want = fixed.Int26_6(1<<6 + 1<<4)
	if out != want {
		t.Errorf("fixed(%#v) = %v; want %v", in, out, want)
	}

	in = -1.25
	out = floatToFixed26(in)
	want = -fixed.Int26_6(1<<6 + 1<<4)
	if out != want {
		t.Errorf("fixed(%#v) = %v; want %v", in, out, want)
	}
}