Skip to content

Commit d3d2c39

Browse files
committed
Add BinaryRealTypeMath test coverage
More methods are tested and we now test using all op aliases
1 parent 5109235 commit d3d2c39

1 file changed

Lines changed: 64 additions & 10 deletions

File tree

‎imagej/imagej-ops2/src/test/java/net/imagej/ops2/math/BinaryRealTypeMathTest.java‎

Lines changed: 64 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import net.imagej.ops2.AbstractOpTest;
3535
import net.imglib2.type.numeric.integer.IntType;
3636
import org.junit.jupiter.api.Test;
37+
import org.scijava.ops.engine.math.MathOps;
3738

3839
/**
3940
* Tests {@link BinaryRealTypeMath}.
@@ -42,24 +43,77 @@
4243
*/
4344
public class BinaryRealTypeMathTest extends AbstractOpTest {
4445

46+
private static final IntType A = new IntType(25);
47+
private static final IntType B = new IntType(25);
4548
@Test
4649
public void testAddF() {
47-
IntType a = new IntType(25);
48-
IntType b = new IntType(45);
49-
IntType c = ops.binary("math.add").input(a, b).outType(IntType.class).apply();
50-
assertEquals(c.get(), a.get() + b.get());
50+
for (String opName : MathOps.ADD.split(", ")) {
51+
IntType c = ops.binary(opName).input(A, B).outType(IntType.class).apply();
52+
assertEquals(A.get() + B.get(), c.get());
53+
}
5154
}
5255

5356
@Test
5457
public void testAddC() {
55-
IntType a = new IntType(25);
56-
IntType b = new IntType(45);
57-
IntType c = new IntType();
58-
ops.binary("math.add").input(a, b).output(c).compute();
59-
assertEquals(c.get(), a.get() + b.get());
58+
for (String opName : MathOps.ADD.split(", ")) {
59+
IntType c = new IntType();
60+
ops.binary(opName).input(A, B).output(c).compute();
61+
assertEquals(A.get() + B.get(), c.get());
62+
}
6063
}
6164

62-
// FIXME: currently not working
65+
@Test
66+
public void testSubF() {
67+
for (String opName : MathOps.SUB.split(", ")) {
68+
IntType c = ops.binary(opName).input(A, B).outType(IntType.class).apply();
69+
assertEquals(A.get() - B.get(), c.get());
70+
}
71+
}
72+
73+
@Test
74+
public void testSubC() {
75+
for (String opName : MathOps.SUB.split(", ")) {
76+
IntType c = new IntType();
77+
ops.binary(opName).input(A, B).output(c).compute();
78+
assertEquals(A.get() - B.get(), c.get());
79+
}
80+
}
81+
82+
@Test
83+
public void testDivF() {
84+
for (String opName : MathOps.DIV.split(", ")) {
85+
IntType c = ops.binary(opName).input(A, B).outType(IntType.class).apply();
86+
assertEquals(A.get() / B.get(), c.get());
87+
}
88+
}
89+
90+
@Test
91+
public void testDivC() {
92+
for (String opName : MathOps.DIV.split(", ")) {
93+
IntType c = new IntType();
94+
ops.binary(opName).input(A, B).output(c).compute();
95+
assertEquals(A.get() / B.get(), c.get());
96+
}
97+
}
98+
99+
@Test
100+
public void testMulF() {
101+
for (String opName : MathOps.MUL.split(", ")) {
102+
IntType c = ops.binary(opName).input(A, B).outType(IntType.class).apply();
103+
assertEquals(A.get() * B.get(), c.get());
104+
}
105+
}
106+
107+
@Test
108+
public void testMulC() {
109+
for (String opName : MathOps.MUL.split(", ")) {
110+
IntType c = new IntType();
111+
ops.binary(opName).input(A, B).output(c).compute();
112+
assertEquals(A.get() * B.get(), c.get());
113+
}
114+
}
115+
116+
// FIXME: inplaces would be nice
63117
// @Test
64118
// public void testAddI() {
65119
// IntType a = new IntType(25);

0 commit comments

Comments
 (0)