Diff implements Scalar<T> { @Override public T value(final Field<T> field) { final FieldAddition<T> add = field.addition(); final T inverse = add.inverse(field.actual(this.soperand)); return add.add(field.actual(this.foperand), inverse); } Diff(final Scalar<T> first, final Scalar<T> second); Scalar<T> first(); Scalar<T> second(); @Override T value(final Field<T> field);  }
@Test public void diffDelegatesToFieldAddition() { final Scalar<Object> first = new Scalar.Default<>(new Object()); final Scalar<Object> second = new Scalar.Default<>(new Object()); final MkAddition<Object> add = new MkAddition<>(new Object()); final SpyField<Object> field = new SpyField<>( new MkField<Object>(new Object(), add) ); new Diff<>(first, second).value(field); MatcherAssert.assertThat( field.calls().additioned(), Matchers.is(true) ); MatcherAssert.assertThat( add.inverted(), Matchers.is(true) ); MatcherAssert.assertThat( add.added(), Matchers.greaterThan(0) ); }