-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUseFiltersTest.scala
144 lines (130 loc) · 3.05 KB
/
UseFiltersTest.scala
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
import UseFilters._
class UseFiltersTest extends org.scalatest.funsuite.AnyFunSuite {
case class TestImage(name: String, path: String) {}
val testImgs = List(
TestImage("zardoz", "images/zardoz.png"),
TestImage("vancouver", "images/vancouver.png"),
TestImage("cohen", "images/cohen.jpg")
)
def outputPath(testName: String, img: TestImage): String = {
s"output/${img.name}/${testName}.png"
}
test("hello world") {
assert(true)
}
test("sanity test for identity function") {
for (img <- testImgs) {
UseFilters.filter(
img.path,
outputPath("id-filter", img),
(_, _, _) => true
)
UseFilters.mapImage(
img.path,
outputPath("id-map", img),
(img, x, y) => img.getRGB(x, y)
)
}
}
test("filter out odd pixels") {
for (img <- testImgs) {
UseFilters.filter(
img.path,
outputPath("even", img),
(_, x, y) => { (x + y) % 2 == 0 }
)
}
assert(true)
}
test("every nth pixel") {
for (
img <- testImgs;
n <- List(2, 5, 7, 13)
) {
UseFilters.filter(
img.path,
outputPath(s"every-${n}th-pixel", img),
(_, x, y) => { (x + y) % n == 0 }
)
}
assert(true)
}
test("map pixels to position as rgb") {
for (img <- testImgs) {
UseFilters.mapImage(
img.path,
outputPath("position", img),
(_, x, y) => { (x + y) % 256 }
)
}
}
test("multiply position with rgb value") {
for (img <- testImgs) {
UseFilters.mapImage(
img.path,
outputPath("position-and-rgb", img),
(img, x, y) => (x + (y * img.getRGB(x, y))) % 256
)
}
}
test("blot out fibonacci pixels") {
for (img <- testImgs) {
UseFilters.fibMap(
img.path,
outputPath("fib-black", img)
)
}
}
test(
s"vary average of surrounding pixels with increasing distance"
) {
for (
img <- testImgs;
distance <- 1 to 1000
) {
UseFilters.avgMap(
img.path,
outputPath(s"avgNeighbours-packed${distance}", img),
distance
)
UseFilters3Byte.avgMap(
img.path,
outputPath(s"avgNeighbours-3byte-${distance}", img),
distance
)
}
}
test("average of all pixels") {
for (img <- testImgs) {
UseFilters.avgAllPixels(img.path, outputPath("avgAllPixels-packed", img))
UseFilters3Byte.avgAllPixels(
img.path,
outputPath("avgAllPixels-3byte", img)
)
}
}
test("avg neighbour pixel applied iteratively") {
for (img <- testImgs) {
UseFilters
.avgMapIterative(
img.path,
s"output/${img.name}/avgNeighbours-iterative",
1,
1000
)
}
}
test(
"avg neighbour pixel applied iteratively w/o writing each change to file system"
) {
for (img <- testImgs) {
UseFilters
.avgMapNthGeneration(
img.path,
s"output/${img.name}/avgNeighbours-iterative",
1,
200
)
}
}
}