|
54 | 54 | import java.util.Arrays; |
55 | 55 | import java.util.Iterator; |
56 | 56 | import java.util.List; |
| 57 | +import java.util.function.BiFunction; |
57 | 58 | import java.util.function.Function; |
58 | 59 |
|
59 | 60 | public class ProvenanceTest extends AbstractTestEnvironment implements |
@@ -117,6 +118,11 @@ public Thing apply(Double[] doubles) { |
117 | 118 | } |
118 | 119 | } |
119 | 120 |
|
| 121 | + @OpMethod(names = "test.create.thing", type = BiFunction.class) |
| 122 | + public static Thing createThingWithNullable(Double d1, @Nullable Double d2) { |
| 123 | + return new Thing(d2 == null ? d1 : d1 + d2); |
| 124 | + } |
| 125 | + |
120 | 126 | static class Thing { |
121 | 127 |
|
122 | 128 | private Double d; |
@@ -518,6 +524,34 @@ public void testAdaptationWithDependencies() { |
518 | 524 | Assertions.assertEquals(1, ops.history().executionsUpon(actual).size()); |
519 | 525 | } |
520 | 526 |
|
| 527 | + @Test |
| 528 | + public void testReducedOpRecovery() { |
| 529 | + // Get the Op |
| 530 | + Function<Double, Thing> f = ops // |
| 531 | + .op("test.create.thing") // |
| 532 | + .inType(Double.class) // |
| 533 | + .outType(Thing.class) // |
| 534 | + .function(); |
| 535 | + // Assert only one execution |
| 536 | + Thing actual = f.apply(4.0); |
| 537 | + Thing expected = new Thing(4.0); |
| 538 | + Assertions.assertEquals(expected.d, actual.d); |
| 539 | + Assertions.assertEquals(1, ops.history().executionsUpon(actual).size()); |
| 540 | + // Get the signature from the Op |
| 541 | + String signature = Ops.signature(f); |
| 542 | + // Generate the Op from the signature and the Op type |
| 543 | + Nil<Function<Thing, Thing>> special = new Nil<>() {}; |
| 544 | + Function<Thing, Thing> fromString = ops // |
| 545 | + .opFromSignature(signature, special); |
| 546 | + // Assert Op similarity |
| 547 | + Assertions.assertTrue(wrappedOpEquality(f, fromString)); |
| 548 | + // Assert only one execution |
| 549 | + actual = f.apply(4.0); |
| 550 | + Assertions.assertEquals(expected.d, actual.d); |
| 551 | + Assertions.assertEquals(1, ops.history().executionsUpon(actual).size()); |
| 552 | + |
| 553 | + } |
| 554 | + |
521 | 555 | // -- Helper Methods -- // |
522 | 556 |
|
523 | 557 | /** |
|
0 commit comments