-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_test.go
More file actions
112 lines (89 loc) · 1.9 KB
/
path_test.go
File metadata and controls
112 lines (89 loc) · 1.9 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
// V0.1.1
// Author: wunderbarb
package imgpath
import (
"path/filepath"
"testing"
"github.com/wunderbarb/test"
)
func TestNew(t *testing.T) {
require, _ := test.Describe(t)
var path []Pos
_, err := New(path)
require.ErrorIs(err, ErrNoPath)
path = []Pos{{1, 1}}
ip, err := New(path)
require.NoError(err)
require.NotNil(ip)
}
func TestImagePath_Next(t *testing.T) {
require, _ := test.Describe(t)
c := initC3("test1.png")
tests := []uint8{32, 128, 32, 32, 32, 32, 32, 32, 255, 255, 255, 32, 32}
for _, tt := range tests {
require.Equal(tt, c.Next())
}
}
func TestImagePath_All(t *testing.T) {
require, _ := test.Describe(t)
var cnt = 0
c := initC3("test1.png")
c.All(func(_ uint8, _ int) {
cnt++
})
require.Equal(c.Len(), cnt)
}
func TestImagePath_Until(t *testing.T) {
require, _ := test.Describe(t)
c := initC3("test1.png")
cnt := 0
c.Until(func(v uint8, index int) bool {
if v != 255 {
return true
}
cnt = index
return false
})
require.Equal(8, cnt)
}
func TestImagePath_Threshold(t *testing.T) {
require, _ := test.Describe(t)
c := initC3("test1.png")
nn := c.Diff()
require.Len(nn, C3.Len())
require.Equal([]int{-223, -127, -223, -223, -223, -223, -223, -223, 0, 0, 0, -223}, nn)
}
// -----------------
func initC2(file string) ImagePath {
img, err := GrayFromFile(filepath.Join("testfixtures", file))
isPanic(err)
c := C2
c.SetImage(img)
return c
}
func initC3(file string) ImagePath {
img, err := GrayFromFile(filepath.Join("testfixtures", file))
isPanic(err)
c := C3
c.SetImage(img)
return c
}
func initC4(file string) ImagePath {
img, err := GrayFromFile(filepath.Join("testfixtures", file))
isPanic(err)
c := C4
c.SetImage(img)
return c
}
func initC5(file string) ImagePath {
img, err := GrayFromFile(filepath.Join("testfixtures", file))
isPanic(err)
c := C5
c.SetImage(img)
return c
}
func isPanic(err error) {
if err != nil {
panic(err)
}
}