forked from PolusAI/filepattern
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTestFilePattern.java
More file actions
154 lines (114 loc) · 5.08 KB
/
Copy pathTestFilePattern.java
File metadata and controls
154 lines (114 loc) · 5.08 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
145
146
147
148
149
150
151
152
153
154
package filepattern.test;
import static org.junit.Assert.*;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import java.util.ArrayList;
import java.util.HashMap;
import java.io.File;
import java.nio.file.*;
import java.io.*;
import java.util.Iterator;
import filepattern.java.*;
public class TestFilePattern {
@BeforeAll
public static void setUp() {
TestData data = new TestData("test_fp_data");
try {
data.generateData();
} catch (Exception e) {
fail("Error creating test data." + e);
}
ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>> fp_result = data.getResults();
}
@Test
public void testFilePattern() {
FilePattern fp = null;
try {
fp = new FilePattern.FilePatternBuilder("test_fp_data")
.recursive(false)
.filePattern("img_r00{r:d}_c00{c:d}_{channel:c+}.tif")
.suppressWarnings(false)
.blockSize("")
.recursive(false).build();
} catch (Exception e) {
fail("Error creating FilePattern object.");
}
ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>> result = new ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>();
for (Iterator<?> i = fp.iterator(); i.hasNext(); ) {
result.add((Pair<HashMap<String, Object>, ArrayList<Path>>) i.next());
}
ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>> truth = TestData.getResults();
assertEquals(result.size(), truth.size());
assertEquals(result, truth);
}
@Test
public void testGetMatching() {
FilePattern fp = null;
try {
fp = new FilePattern.FilePatternBuilder("test_fp_data")
.recursive(false)
.filePattern("img_r00{r:d}_c00{c:d}_{channel:c+}.tif")
.suppressWarnings(false)
.blockSize("")
.recursive(false).build();
} catch (Exception e) {
fail("Error creating FilePattern object.");
}
ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>> result = new ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>();
HashMap<String, Object> matching = new HashMap<>();
matching.put("r", 1);
for (Iterator<?> i = fp.iterator(matching); i.hasNext(); ) {
result.add((Pair<HashMap<String, Object>, ArrayList<Path>>) i.next());
}
ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>> truth = TestData.getMatchingResults();
assertEquals(result.size(), truth.size());
assertEquals(result, truth);
}
@Test
public void testSetGroup() {
FilePattern fp = null;
try {
fp = new FilePattern.FilePatternBuilder("test_fp_data")
.recursive(false)
.filePattern("img_r00{r:d}_c00{c:d}_{channel:c+}.tif")
.suppressWarnings(false)
.blockSize("")
.recursive(false).build();
} catch (Exception e) {
fail("Error creating FilePattern object.");
}
ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> result = new ArrayList<>();
fp.setGroup("r");
for (Iterator<?> i = fp.iterator(); i.hasNext(); ) {
result.add((Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>) i.next());
}
ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> truth = TestData.getGroupedResults();
System.out.println(result.size());
System.out.println(truth.size());
assertEquals(result.size(), truth.size());
assertEquals(result, truth);
}
@Test
public void testGroupBy() {
FilePattern fp = null;
try {
fp = new FilePattern.FilePatternBuilder("test_fp_data")
.recursive(false)
.filePattern("img_r00{r:d}_c00{c:d}_{channel:c+}.tif")
.suppressWarnings(false)
.blockSize("")
.recursive(false).build();
} catch (Exception e) {
fail("Error creating FilePattern object.");
}
ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> result = new ArrayList<>();
for (Iterator<?> i = fp.iterator("r"); i.hasNext(); ) {
result.add((Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>) i.next());
}
ArrayList<Pair<ArrayList<Pair<String, Object>>, ArrayList<Pair<HashMap<String, Object>, ArrayList<Path>>>>> truth = TestData.getGroupedResults();
System.out.println(result.size());
System.out.println(truth.size());
assertEquals(result.size(), truth.size());
assertEquals(result, truth);
}
}