-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtestdata_test.go
More file actions
49 lines (43 loc) · 1.19 KB
/
testdata_test.go
File metadata and controls
49 lines (43 loc) · 1.19 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
package etxt
import "testing"
// Tests using pre-generated test data for comparison
// of Ebitengine and gtxt rendering results. Take a look
// at testdata_generate.go for more details.
var testdata = make(map[string][]byte)
func TestTestdataBlendRand(t *testing.T) {
// get test data
valuesE, foundE := testdata["blend_rand_ebiten"]
valuesG, foundG := testdata["blend_rand_gtxt"]
valuesB, foundB := testdata["blend_rand_ebiten_gtxt"]
if foundE != foundG || foundE != foundB {
panic("incorrect test data generation or setup")
}
if !foundE {
t.SkipNow()
}
// compare values
if !similarByteSlices(valuesE, valuesG) {
t.Fatalf("Mismatched testdata blend_rand results:\nEbitengine results: %v\ngtxt results: %v", valuesE, valuesG)
}
if !similarByteSlices(valuesE, valuesB) {
t.Fatalf("Mismatched testdata blend_rand results:\nEbitengine results: %v\nEbitengine + gtxt results: %v", valuesE, valuesB)
}
}
func similarByteSlices(a, b []byte) bool {
if len(a) != len(b) {
return false
}
for i := 0; i < len(a); i++ {
if a[i] == b[i] {
continue
}
if a[i] < b[i] && a[i]+1 == b[i] {
continue
}
if b[i] < a[i] && b[i]+1 == a[i] {
continue
}
return false
}
return true
}