Skip to content

Commit 88fd712

Browse files
author
tibuch
committed
Add ComputerSetProcessor tests.
1 parent b2c8899 commit 88fd712

File tree

5 files changed

+515
-0
lines changed

5 files changed

+515
-0
lines changed
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, University of Konstanz and Brian Northan.
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
package net.imagej.ops.features.sets.processors;
31+
32+
import java.util.List;
33+
import java.util.Map;
34+
35+
import net.imagej.ops.features.AbstractFeatureTest;
36+
import net.imagej.ops.features.sets.ComputerSet;
37+
import net.imagej.table.GenericTable;
38+
import net.imglib2.type.numeric.real.DoubleType;
39+
40+
import org.junit.Assert;
41+
42+
/**
43+
*
44+
* @author Tim-Oliver Buchholz, University of Konstanz
45+
*
46+
*/
47+
public abstract class AbstractComputerSetProcessorTest extends AbstractFeatureTest {
48+
49+
/**
50+
* Check for the correct column names from a start index. If the result
51+
* table was generate based on a labeling, the label would be stored in the
52+
* first column.
53+
*
54+
* Note: No duplicate ComputerSets.
55+
*
56+
* @param result the result table
57+
* @param computerSets the computer sets
58+
* @param startIdx the start index
59+
*/
60+
protected void checkAllResultTableForOneComputerSet(final GenericTable result,
61+
final List<ComputerSet<?, DoubleType>> computerSets, final int startIdx) {
62+
String computerSetName = ComputerSetProcessorUtils.getUniqueNames(computerSets).get(computerSets.get(0));
63+
64+
String[] names = computerSets.get(0).getComputerNames();
65+
66+
for (int i = startIdx; i < result.getColumnCount(); i++) {
67+
String tmpName = computerSetName + "_" + names[i-startIdx];
68+
Assert.assertTrue("Wrong column order.", tmpName.equals(result.get(i).getHeader()));
69+
}
70+
}
71+
72+
/**
73+
* Check for the correct column names from a start index. If the result
74+
* table was generate based on a labeling, the label would be stored in the
75+
* first column.
76+
*
77+
* Note: Checks correct column names for duplicate ComputerSets.
78+
*
79+
* @param result the result table
80+
* @param computerSets the computer sets
81+
* @param startIdx the start index
82+
*/
83+
protected void checkResultTableForManyComputerSets(final GenericTable result,
84+
final List<ComputerSet<?, DoubleType>> computerSets, final int startIdx) {
85+
Map<ComputerSet<?, DoubleType>, String> computerSetNames = ComputerSetProcessorUtils.getUniqueNames(computerSets);
86+
87+
int i = startIdx;
88+
for (ComputerSet<?, DoubleType> set : computerSets) {
89+
String computerSetName = computerSetNames.get(set);
90+
String[] names = set.getComputerNames();
91+
for (String s : names) {
92+
String tmpName = computerSetName + "_" + s;
93+
Assert.assertTrue("Wrong column order.", tmpName.equals(result.get(i++).getHeader()));
94+
}
95+
}
96+
}
97+
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, University of Konstanz and Brian Northan.
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
package net.imagej.ops.features.sets.processors;
31+
32+
import java.util.ArrayList;
33+
import java.util.Collection;
34+
import java.util.HashSet;
35+
import java.util.List;
36+
import java.util.Map;
37+
38+
import net.imagej.ops.AbstractOpTest;
39+
import net.imagej.ops.features.sets.ComputerSet;
40+
import net.imagej.ops.features.sets.FirstOrderStatsComputerSet;
41+
import net.imglib2.type.numeric.real.DoubleType;
42+
43+
import org.junit.Assert;
44+
import org.junit.Test;
45+
46+
/**
47+
* Test for the {@link ComputerSetProcessorUtils}.
48+
*
49+
* @author Tim-Oliver Buchholz, University of Konstanz
50+
*
51+
*/
52+
public class ComputerSetProcessorUtilsTest extends AbstractOpTest {
53+
54+
@SuppressWarnings({ "cast", "unchecked" })
55+
@Test
56+
public void uniqueNamesTest() {
57+
List<ComputerSet<?, DoubleType>> sets = new ArrayList<>();
58+
sets.add((FirstOrderStatsComputerSet<?, DoubleType>) ops.op(FirstOrderStatsComputerSet.class, Iterable.class));
59+
sets.add((FirstOrderStatsComputerSet<?, DoubleType>) ops.op(FirstOrderStatsComputerSet.class, Iterable.class));
60+
61+
Map<ComputerSet<?, DoubleType>, String> uniqueNames = ComputerSetProcessorUtils.getUniqueNames(sets);
62+
63+
Collection<String> names = uniqueNames.values();
64+
Collection<String> copy = new HashSet<>(names);
65+
66+
for (String s : names) {
67+
copy.remove(s);
68+
Assert.assertTrue("Duplicated name.", !copy.contains(s));
69+
}
70+
71+
int i = -1;
72+
for (ComputerSet<?, DoubleType> computerSet : sets) {
73+
if (i == -1) {
74+
Assert.assertTrue("No suffix is needed.",
75+
computerSet.getClass().getSimpleName().equals(uniqueNames.get(computerSet)));
76+
i++;
77+
} else {
78+
String tmp = computerSet.getClass().getSimpleName();
79+
tmp = tmp + "[" + i + "]";
80+
Assert.assertTrue("Incorrect suffix.", tmp.equals(uniqueNames.get(computerSet)));
81+
}
82+
}
83+
}
84+
85+
}
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2014 - 2016 Board of Regents of the University of
6+
* Wisconsin-Madison, University of Konstanz and Brian Northan.
7+
* %%
8+
* Redistribution and use in source and binary forms, with or without
9+
* modification, are permitted provided that the following conditions are met:
10+
*
11+
* 1. Redistributions of source code must retain the above copyright notice,
12+
* this list of conditions and the following disclaimer.
13+
* 2. Redistributions in binary form must reproduce the above copyright notice,
14+
* this list of conditions and the following disclaimer in the documentation
15+
* and/or other materials provided with the distribution.
16+
*
17+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
21+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27+
* POSSIBILITY OF SUCH DAMAGE.
28+
* #L%
29+
*/
30+
package net.imagej.ops.features.sets.processors;
31+
32+
import java.util.ArrayList;
33+
import java.util.Arrays;
34+
import java.util.List;
35+
36+
import net.imagej.ops.Ops.Stats.Max;
37+
import net.imagej.ops.Ops.Stats.Mean;
38+
import net.imagej.ops.features.sets.ComputerSet;
39+
import net.imagej.ops.features.sets.FirstOrderStatsComputerSet;
40+
import net.imagej.ops.features.sets.tables.DefaultComputerSetTableService;
41+
import net.imagej.table.GenericTable;
42+
import net.imglib2.type.numeric.real.DoubleType;
43+
import net.imglib2.type.numeric.real.FloatType;
44+
45+
import org.junit.Test;
46+
47+
/**
48+
* Test for the {@link IterableComputerSetProcessor}.
49+
*
50+
* @author Tim-Oliver Buchholz, University of Konstanz
51+
*
52+
*/
53+
public class IterableComputerSetProcessorTest extends AbstractComputerSetProcessorTest {
54+
55+
@SuppressWarnings({ "rawtypes", "unchecked" })
56+
@Test
57+
public void allComputersAreActiveTest() {
58+
FirstOrderStatsComputerSet<Iterable, DoubleType> stats = ops.op(FirstOrderStatsComputerSet.class,
59+
Iterable.class);
60+
61+
IterableComputerSetProcessor<FloatType, DoubleType> processor = ops.op(IterableComputerSetProcessor.class,
62+
Iterable.class, new ComputerSet[] { stats }, new DefaultComputerSetTableService<>());
63+
64+
GenericTable result = processor.calculate(getTestImage2D());
65+
66+
List<ComputerSet<?, DoubleType>> computerSets = new ArrayList<>();
67+
computerSets.add(stats);
68+
checkAllResultTableForOneComputerSet(result, computerSets, 0);
69+
}
70+
71+
@SuppressWarnings({ "rawtypes", "unchecked" })
72+
@Test
73+
public void someComputersAreActiveTest() {
74+
FirstOrderStatsComputerSet<Iterable, DoubleType> stats = ops.op(FirstOrderStatsComputerSet.class,
75+
Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class }));
76+
77+
IterableComputerSetProcessor<FloatType, DoubleType> processor = ops.op(IterableComputerSetProcessor.class,
78+
Iterable.class, new ComputerSet[] { stats }, new DefaultComputerSetTableService<>());
79+
80+
GenericTable result = processor.calculate(getTestImage2D());
81+
82+
List<ComputerSet<?, DoubleType>> computerSets = new ArrayList<>();
83+
computerSets.add(stats);
84+
checkAllResultTableForOneComputerSet(result, computerSets, 0);
85+
}
86+
87+
@SuppressWarnings({ "rawtypes", "unchecked" })
88+
@Test
89+
public void multiComputerSetProcessingTest() {
90+
FirstOrderStatsComputerSet<Iterable, DoubleType> stats = ops.op(FirstOrderStatsComputerSet.class,
91+
Iterable.class);
92+
FirstOrderStatsComputerSet<Iterable, DoubleType> stats1 = ops.op(FirstOrderStatsComputerSet.class,
93+
Iterable.class, Arrays.asList(new Class[] { Mean.class, Max.class }));
94+
95+
IterableComputerSetProcessor<FloatType, DoubleType> processor = ops.op(IterableComputerSetProcessor.class,
96+
Iterable.class, new ComputerSet[] { stats, stats1 }, new DefaultComputerSetTableService<>());
97+
98+
final GenericTable result = processor.calculate(getTestImage2D());
99+
100+
final List<ComputerSet<?, DoubleType>> computerSets = new ArrayList<>();
101+
computerSets.add(stats);
102+
computerSets.add(stats1);
103+
checkResultTableForManyComputerSets(result, computerSets, 0);
104+
}
105+
106+
}

0 commit comments

Comments
 (0)