This repository was archived by the owner on Oct 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvec_test.go
More file actions
144 lines (124 loc) · 3.65 KB
/
Copy pathvec_test.go
File metadata and controls
144 lines (124 loc) · 3.65 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
package vector
import (
"github.com/duncanpierce/vector/vec16"
"github.com/duncanpierce/vector/vec2"
"reflect"
"testing"
)
func TestAdd(t *testing.T) {
v := vec2.Add(vec2.SelectAll(), [2]int{3, 4}, [2]int{5, 6})
if v[0] != 8 {
t.Errorf("got %v", v[0])
}
if v[1] != 10 {
t.Errorf("got %v", v[1])
}
}
func TestMax(t *testing.T) {
v := vec2.Max(vec2.SelectAll(), [2]int{3, 4}, [2]int{2, 6})
if v[0] != 3 {
t.Errorf("got %v", v[0])
}
if v[1] != 6 {
t.Errorf("got %v", v[1])
}
}
func TestMask(t *testing.T) {
v := vec2.Add(vec2.SelectFirst(1), [2]int{1, 2}, [2]int{3, 4})
if v[0] != 4 {
t.Errorf("got %v", v[0])
}
if v[1] != 0 {
t.Errorf("got %v", v[1])
}
v = vec2.Add(vec2.SelectFirst(1).Not(), [2]int{1, 2}, [2]int{3, 4})
if v[0] != 0 {
t.Errorf("got %v", v[0])
}
if v[1] != 6 {
t.Errorf("got %v", v[1])
}
}
func TestInterlace(t *testing.T) {
a := [8]int{1, 2, 3, 4, 5, 6, 7, 8}
b := [8]int{9, 10, 11, 12, 13, 14, 15, 16}
r := vec16.Interlace(1, a, b)
if !reflect.DeepEqual(r, [16]int{1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 8, 16}) {
t.Errorf("failed at interlace 1")
}
r = vec16.Interlace(2, a, b)
if !reflect.DeepEqual(r, [16]int{1, 2, 9, 10, 3, 4, 11, 12, 5, 6, 13, 14, 7, 8, 15, 16}) {
t.Errorf("failed at interlace 2")
}
r = vec16.Interlace(4, a, b)
if !reflect.DeepEqual(r, [16]int{1, 2, 3, 4, 9, 10, 11, 12, 5, 6, 7, 8, 13, 14, 15, 16}) {
t.Errorf("failed at interlace 4")
}
r = vec16.Interlace(8, a, b)
if !reflect.DeepEqual(r, [16]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}) {
t.Errorf("failed at interlace 8")
}
}
func TestDeinterlace(t *testing.T) {
r, s := vec16.Deinterlace(1, [16]int{1, 9, 2, 10, 3, 11, 4, 12, 5, 13, 6, 14, 7, 15, 8, 16})
checkDeinterlace(t, r, s)
r, s = vec16.Deinterlace(2, [16]int{1, 2, 9, 10, 3, 4, 11, 12, 5, 6, 13, 14, 7, 8, 15, 16})
checkDeinterlace(t, r, s)
r, s = vec16.Deinterlace(4, [16]int{1, 2, 3, 4, 9, 10, 11, 12, 5, 6, 7, 8, 13, 14, 15, 16})
checkDeinterlace(t, r, s)
r, s = vec16.Deinterlace(8, [16]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16})
checkDeinterlace(t, r, s)
}
func checkDeinterlace(t *testing.T, r, s [8]int) {
if !reflect.DeepEqual(r, [8]int{1, 2, 3, 4, 5, 6, 7, 8}) {
t.Errorf("failed on r")
}
if !reflect.DeepEqual(s, [8]int{9, 10, 11, 12, 13, 14, 15, 16}) {
t.Errorf("failed on s")
}
}
func TestFirstN(t *testing.T) {
a := [16]int{}
b := [16]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
mask := vec16.SelectFirst(3)
r := vec16.Blend(mask, a, b)
if !reflect.DeepEqual(r, [16]int{1, 2, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}) {
t.Errorf("unexpectedly got %v", r)
}
}
func TestLastN(t *testing.T) {
a := [16]int{}
b := [16]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}
mask := vec16.SelectLast(3)
r := vec16.Blend(mask, a, b)
if !reflect.DeepEqual(r, [16]int{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14, 15, 16}) {
t.Errorf("unexpectedly got %v", r)
}
}
func TestHorizontalMax(t *testing.T) {
a := [16]int{1, 2, 6, 10, 44, 3, 17, 19, 23, 33, 12, 2, 6, 43, 13, 16}
r, ok := vec16.ElementMax(vec16.SelectAll(), a)
if !ok {
t.Errorf("should be ok")
}
if r != 44 {
t.Errorf("wrong value returned %v", r)
}
}
func TestMaskedHorizontalMax(t *testing.T) {
a := [16]int{1, 2, 6, 10, 44, 3, 17, 19, 23, 33, 12, 2, 6, 43, 13, 16}
r, ok := vec16.ElementMax(vec16.SelectFirst(4), a)
if !ok {
t.Errorf("should be ok")
}
if r != 10 {
t.Errorf("wrong value returned %v", r)
}
}
func TestNoneMaskedHorizontalMax(t *testing.T) {
a := [16]int{1, 2, 6, 10, 44, 3, 17, 19, 23, 33, 12, 2, 6, 43, 13, 16}
_, ok := vec16.ElementMax(vec16.SelectNone(), a)
if ok {
t.Errorf("should not be ok")
}
}