Skip to content

Commit 9e35d9a

Browse files
awalter17imagejan
authored andcommitted
Add tests for primitive table types and update ResultsTable test
1 parent 49a3b24 commit 9e35d9a

8 files changed

Lines changed: 812 additions & 18 deletions
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package net.imagej.table;
33+
34+
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertSame;
36+
37+
import org.junit.Test;
38+
39+
/**
40+
* Tests {@link DefaultBoolTable}.
41+
*
42+
* @author Alison Walter
43+
*/
44+
public class DefaultBoolTableTest {
45+
46+
private static final String[] HEADERS = { "Header1", "Header2", "Header3" };
47+
48+
private static final boolean[][] DATA = {
49+
{ true, true, true },
50+
{ true, true, false },
51+
{ true, false, true },
52+
{ true, false, false },
53+
{ false, true, true },
54+
{ false, true, false },
55+
{ false, false, true },
56+
{ false, false, false },
57+
};
58+
59+
@Test
60+
public void testStructure() {
61+
final BoolTable table = createTable();
62+
assertEquals(3, table.getColumnCount());
63+
assertEquals(8, table.getRowCount());
64+
for (final BoolColumn column : table) {
65+
assertEquals(8, column.size());
66+
}
67+
68+
for (int n = 0; n < table.getColumnCount(); n++) {
69+
assertEquals(table.get(n).getHeader(), HEADERS[n]);
70+
}
71+
72+
for (int c = 0; c < table.getColumnCount(); c++) {
73+
final BoolColumn columnByHeader = table.get(HEADERS[c]);
74+
final BoolColumn columnByIndex = table.get(c);
75+
assertSame(columnByHeader, columnByIndex);
76+
assertEquals(DATA.length, columnByHeader.size());
77+
for (int r = 0; r < table.getRowCount(); r++) {
78+
assertEquals(DATA[r][c], table.getValue(c, r));
79+
assertEquals(DATA[r][c], columnByHeader.getValue(r));
80+
}
81+
}
82+
}
83+
84+
@Test
85+
public void testGetColumnType() {
86+
final BoolTable table = createTable();
87+
final BoolColumn col = table.get(0);
88+
assertEquals(col.getType(), Boolean.class);
89+
}
90+
91+
// TODO - Add more tests.
92+
93+
// -- Helper methods --
94+
95+
private BoolTable createTable() {
96+
final BoolTable table = new DefaultBoolTable(DATA[0].length, DATA.length);
97+
98+
for (int c = 0; c < HEADERS.length; c++) {
99+
table.setColumnHeader(c, HEADERS[c]);
100+
}
101+
102+
for (int r = 0; r < DATA.length; r++) {
103+
for (int c = 0; c < DATA[r].length; c++) {
104+
table.setValue(c, r, DATA[r][c]);
105+
}
106+
}
107+
108+
return table;
109+
}
110+
111+
}
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package net.imagej.table;
33+
34+
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertSame;
36+
37+
import org.junit.Test;
38+
39+
/**
40+
* Tests {@link DefaultByteTable}.
41+
*
42+
* @author Alison Walter
43+
*/
44+
public class DefaultByteTableTest {
45+
46+
private static final String[] HEADERS = { "Header1", "Header2" };
47+
48+
private static final byte[][] DATA = {
49+
{ 127, -45 },
50+
{ -128, 0 },
51+
{ 64, 17 },
52+
{ -32, 6 },
53+
{ 4, 98 },
54+
{ -74, -104 },
55+
{ 12, 89 },
56+
};
57+
58+
@Test
59+
public void testStructure() {
60+
final ByteTable table = createTable();
61+
assertEquals(2, table.getColumnCount());
62+
assertEquals(7, table.getRowCount());
63+
for (final ByteColumn column : table) {
64+
assertEquals(7, column.size());
65+
}
66+
67+
for (int n = 0; n < table.getColumnCount(); n++) {
68+
assertEquals(table.get(n).getHeader(), HEADERS[n]);
69+
}
70+
71+
for (int c = 0; c < table.getColumnCount(); c++) {
72+
final ByteColumn columnByHeader = table.get(HEADERS[c]);
73+
final ByteColumn columnByIndex = table.get(c);
74+
assertSame(columnByHeader, columnByIndex);
75+
assertEquals(DATA.length, columnByHeader.size());
76+
for (int r = 0; r < table.getRowCount(); r++) {
77+
assertEquals(DATA[r][c], table.getValue(c, r));
78+
assertEquals(DATA[r][c], columnByHeader.getValue(r));
79+
}
80+
}
81+
}
82+
83+
@Test
84+
public void testGetColumnType() {
85+
final ByteTable table = createTable();
86+
final ByteColumn col = table.get(0);
87+
assertEquals(col.getType(), Byte.class);
88+
}
89+
90+
// TODO - Add more tests.
91+
92+
// -- Helper methods --
93+
94+
private ByteTable createTable() {
95+
final ByteTable table = new DefaultByteTable(DATA[0].length, DATA.length);
96+
97+
for (int c = 0; c < HEADERS.length; c++) {
98+
table.setColumnHeader(c, HEADERS[c]);
99+
}
100+
101+
for (int r = 0; r < DATA.length; r++) {
102+
for (int c = 0; c < DATA[r].length; c++) {
103+
table.setValue(c, r, DATA[r][c]);
104+
}
105+
}
106+
107+
return table;
108+
}
109+
110+
}
Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
/*
2+
* #%L
3+
* ImageJ software for multidimensional image processing and analysis.
4+
* %%
5+
* Copyright (C) 2009 - 2015 Board of Regents of the University of
6+
* Wisconsin-Madison, Broad Institute of MIT and Harvard, and Max Planck
7+
* Institute of Molecular Cell Biology and Genetics.
8+
* %%
9+
* Redistribution and use in source and binary forms, with or without
10+
* modification, are permitted provided that the following conditions are met:
11+
*
12+
* 1. Redistributions of source code must retain the above copyright notice,
13+
* this list of conditions and the following disclaimer.
14+
* 2. Redistributions in binary form must reproduce the above copyright notice,
15+
* this list of conditions and the following disclaimer in the documentation
16+
* and/or other materials provided with the distribution.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
* #L%
30+
*/
31+
32+
package net.imagej.table;
33+
34+
import static org.junit.Assert.assertEquals;
35+
import static org.junit.Assert.assertSame;
36+
37+
import org.junit.Test;
38+
39+
/**
40+
* Tests {@link DefaultCharTable}.
41+
*
42+
* @author Alison Walter
43+
*/
44+
public class DefaultCharTableTest {
45+
46+
private static final String[] HEADERS = { "Header1", "Header2", "Header3" };
47+
48+
private static final char[][] DATA = {
49+
{ 'a', 'B', 'c' },
50+
{ 'D', 'e', 'f' },
51+
{ 'g', 'h', 'I'},
52+
{ 'J', 'K', 'l' },
53+
{ 'm', 'N', 'O' },
54+
{ 'P', 'q', 'R' },
55+
{ 's', 't', 'u' },
56+
{ 'V', 'W', 'X' },
57+
{ 'y', '&', 'z'},
58+
};
59+
60+
@Test
61+
public void testStructure() {
62+
final CharTable table = createTable();
63+
assertEquals(3, table.getColumnCount());
64+
assertEquals(9, table.getRowCount());
65+
for (final CharColumn column : table) {
66+
assertEquals(9, column.size());
67+
}
68+
69+
for (int n = 0; n < table.getColumnCount(); n++) {
70+
assertEquals(table.get(n).getHeader(), HEADERS[n]);
71+
}
72+
73+
for (int c = 0; c < table.getColumnCount(); c++) {
74+
final CharColumn columnByHeader = table.get(HEADERS[c]);
75+
final CharColumn columnByIndex = table.get(c);
76+
assertSame(columnByHeader, columnByIndex);
77+
assertEquals(DATA.length, columnByHeader.size());
78+
for (int r = 0; r < table.getRowCount(); r++) {
79+
assertEquals(DATA[r][c], table.getValue(c, r));
80+
assertEquals(DATA[r][c], columnByHeader.getValue(r));
81+
}
82+
}
83+
}
84+
85+
@Test
86+
public void testGetColumnType() {
87+
final CharTable table = createTable();
88+
final CharColumn col = table.get(0);
89+
assertEquals(col.getType(), Character.class);
90+
}
91+
92+
// TODO - Add more tests.
93+
94+
// -- Helper methods --
95+
96+
private CharTable createTable() {
97+
final CharTable table = new DefaultCharTable(DATA[0].length, DATA.length);
98+
99+
for (int c = 0; c < HEADERS.length; c++) {
100+
table.setColumnHeader(c, HEADERS[c]);
101+
}
102+
103+
for (int r = 0; r < DATA.length; r++) {
104+
for (int c = 0; c < DATA[r].length; c++) {
105+
table.setValue(c, r, DATA[r][c]);
106+
}
107+
}
108+
109+
return table;
110+
}
111+
112+
}

0 commit comments

Comments
 (0)