Skip to content

Commit fef259a

Browse files
gselzerhinerm
authored andcommitted
Test passing Hints via OpBuilder call
1 parent 75fab76 commit fef259a

2 files changed

Lines changed: 87 additions & 2 deletions

File tree

scijava/scijava-ops/src/test/java/org/scijava/ops/hints/AdaptationHintTest.java

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,26 @@ public void testAdaptation() {
4040
} catch( IllegalArgumentException e) {
4141
assertTrue(e.getCause() instanceof OpMatchingException);
4242
}
43-
43+
}
44+
45+
@Test
46+
public void testAdaptationPerCallHints() {
47+
// make sure we can find the Op when adaptation is allowed
48+
Hints hints = new DefaultHints();
49+
hints.setHint(Adaptation.ALLOWED);
50+
@SuppressWarnings("unused")
51+
Computers.Arity1<Double[], Double[]> adaptable = ops.op(
52+
"test.adaptation.hints").inType(Double[].class).outType(Double[].class)
53+
.computer(hints);
54+
// make sure we cannot find the Op when adaptation is not allowed
55+
hints.setHint(Adaptation.FORBIDDEN);
56+
try {
57+
ops.op("test.adaptation.hints").inType(Double[].class).outType(
58+
Double[].class).computer(hints);
59+
throw new IllegalStateException("This op call should not match!");
60+
} catch( IllegalArgumentException e) {
61+
assertTrue(e.getCause() instanceof OpMatchingException);
62+
}
4463
}
4564

4665
@OpHints(hints = {Adaptation.FORBIDDEN})
@@ -66,7 +85,26 @@ public void testNonAdaptableOp() {
6685
} catch( IllegalArgumentException e) {
6786
assertTrue(e.getCause() instanceof OpMatchingException);
6887
}
69-
88+
}
89+
90+
@Test
91+
public void testNonAdaptableOpPerCallHints() {
92+
// make sure we can find the Op when adaptation is allowed
93+
Hints hints = new DefaultHints();
94+
hints.setHint(Adaptation.ALLOWED);
95+
@SuppressWarnings("unused")
96+
Function<Double[], Double[]> adaptable = ops.op(
97+
"test.adaptation.unadaptable").inType(Double[].class).outType(Double[].class)
98+
.function(hints);
99+
// make sure that we cannot match the Op via adaptation even when adaptation
100+
// is allowed (since it declares itself to be unadaptable)
101+
try {
102+
ops.op("test.adaptation.unadaptable").inType(Double[].class).outType(
103+
Double[].class).computer(hints);
104+
throw new IllegalStateException("This op call should not match!");
105+
} catch( IllegalArgumentException e) {
106+
assertTrue(e.getCause() instanceof OpMatchingException);
107+
}
70108
}
71109

72110
}

scijava/scijava-ops/src/test/java/org/scijava/ops/hints/SimplificationHintTest.java

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,29 @@ public void testSimplification() {
4646

4747
}
4848

49+
@Test
50+
public void testSimplificationPerCallHints() {
51+
// make sure we can find the Op when adaptation is allowed
52+
Hints hints = new DefaultHints();
53+
hints.setHint(Simplification.ALLOWED);
54+
@SuppressWarnings("unused")
55+
Function<Integer[], Integer[]> adaptable = ops.op(
56+
"test.simplification.hints").inType(Integer[].class).outType(
57+
Integer[].class).function(hints);
58+
// make sure we cannot find the Op when adaptation is not allowed
59+
hints.setHint(Simplification.FORBIDDEN);
60+
try {
61+
ops.op("test.simplification.hints").inType(Integer[].class).outType(
62+
Integer[].class).function(hints);
63+
throw new IllegalStateException(
64+
"Simplification is forbidden - this op call should not match!");
65+
}
66+
catch (IllegalArgumentException e) {
67+
assertTrue(e.getCause() instanceof OpMatchingException);
68+
}
69+
70+
}
71+
4972
@OpHints(hints = { Simplification.FORBIDDEN })
5073
@OpField(names = "test.simplification.unsimplifiable")
5174
public final Function<Double[], Double[]> nonAdaptableOp = (
@@ -76,4 +99,28 @@ public void testUnsimplifiableOp() {
7699

77100
}
78101

102+
@Test
103+
public void testUnsimplifiableOpPerCallHints() {
104+
// make sure we can find the Op when adaptation is allowed
105+
Hints hints = new DefaultHints();
106+
hints.setHint(Simplification.ALLOWED);
107+
@SuppressWarnings("unused")
108+
Function<Double[], Double[]> adaptable = ops.op(
109+
"test.simplification.unsimplifiable").inType(Double[].class).outType(
110+
Double[].class).function(hints);
111+
// make sure that we cannot match the Op via adaptation even when
112+
// simplification
113+
// is allowed (since it declares itself to be unsimplifiable)
114+
try {
115+
ops.op("test.simplification.unsimplifiable").inType(Integer[].class)
116+
.outType(Integer[].class).function(hints);
117+
throw new IllegalStateException(
118+
"The only relevant Op is not simplifiable - this op call should not match!");
119+
}
120+
catch (IllegalArgumentException e) {
121+
assertTrue(e.getCause() instanceof OpMatchingException);
122+
}
123+
124+
}
125+
79126
}

0 commit comments

Comments
 (0)