-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathraster_scaler_test.go
151 lines (122 loc) · 5.24 KB
/
raster_scaler_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
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
145
146
147
148
149
150
151
package utils
import (
"testing"
)
func assert(t *testing.T, out *ByteRaster, expected *ByteRaster, err error) {
if err != nil {
t.Errorf("byte raster test failed, %v", err)
}
for i := range out.Data {
if out.Data[i] != expected.Data[i] {
t.Errorf("byte raster test failed, expecting %v, actual %v", expected.Data, out.Data)
}
}
}
func testByteRaster(t *testing.T) {
inRaster := make([]Raster, 1)
sp := ScaleParams{Offset: 1, Scale: 1, Clip: 1000}
inRaster[0] = &ByteRaster{Data: []uint8{uint8(1), uint8(2)}}
expOut := &ByteRaster{Data: []uint8{uint8(2), uint8(3)}}
out, err := Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &ByteRaster{Data: []uint8{uint8(1), uint8(2)}}
sp = ScaleParams{Offset: 0, Scale: 0, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(127), uint8(254)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &ByteRaster{Data: []uint8{uint8(1), uint8(2)}}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 1000}
expOut = &ByteRaster{Data: []uint8{uint8(8), uint8(10)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &ByteRaster{Data: []uint8{uint8(1), uint8(2)}}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(4), uint8(4)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
}
func testInt16Raster(t *testing.T) {
inRaster := make([]Raster, 1)
sp := ScaleParams{Offset: 1, Scale: 1, Clip: 1000}
inRaster[0] = &Int16Raster{Data: []int16{int16(1), int16(2)}, Height: 2, Width: 1}
expOut := &ByteRaster{Data: []uint8{uint8(2), uint8(3)}}
out, err := Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Int16Raster{Data: []int16{int16(1), int16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 0, Scale: 0, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(127), uint8(254)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Int16Raster{Data: []int16{int16(1), int16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 1000}
expOut = &ByteRaster{Data: []uint8{uint8(8), uint8(10)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Int16Raster{Data: []int16{int16(1), int16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(4), uint8(4)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Int16Raster{Data: []int16{int16(-100), int16(-200)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(0), uint8(0)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
}
func testUInt16Raster(t *testing.T) {
inRaster := make([]Raster, 1)
sp := ScaleParams{Offset: 1, Scale: 1, Clip: 1000}
inRaster[0] = &UInt16Raster{Data: []uint16{uint16(1), uint16(2)}, Height: 2, Width: 1}
expOut := &ByteRaster{Data: []uint8{uint8(2), uint8(3)}}
out, err := Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &UInt16Raster{Data: []uint16{uint16(1), uint16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 0, Scale: 0, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(127), uint8(254)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &UInt16Raster{Data: []uint16{uint16(1), uint16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 1000}
expOut = &ByteRaster{Data: []uint8{uint8(8), uint8(10)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &UInt16Raster{Data: []uint16{uint16(1), uint16(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(4), uint8(4)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
}
func testFloat32Raster(t *testing.T) {
inRaster := make([]Raster, 1)
sp := ScaleParams{Offset: 1, Scale: 1, Clip: 1000}
inRaster[0] = &Float32Raster{Data: []float32{float32(1), float32(2)}, Height: 2, Width: 1}
expOut := &ByteRaster{Data: []uint8{uint8(2), uint8(3)}}
out, err := Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Float32Raster{Data: []float32{float32(1), float32(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 0, Scale: 0, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(127), uint8(254)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Float32Raster{Data: []float32{float32(1), float32(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 1000}
expOut = &ByteRaster{Data: []uint8{uint8(8), uint8(10)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Float32Raster{Data: []float32{float32(1), float32(2)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(4), uint8(4)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
inRaster[0] = &Float32Raster{Data: []float32{float32(-100), float32(-200)}, Height: 2, Width: 1}
sp = ScaleParams{Offset: 3, Scale: 2, Clip: 2}
expOut = &ByteRaster{Data: []uint8{uint8(0), uint8(0)}}
out, err = Scale(inRaster, sp)
assert(t, out[0], expOut, err)
}
func TestScale(t *testing.T) {
testByteRaster(t)
testInt16Raster(t)
testUInt16Raster(t)
testFloat32Raster(t)
}