Decimal extends AbstractOrderedField<Double> implements MetricSpaceField<Double> { @Override public boolean equals(final Scalar<Double> first, final Scalar<Double> second) { return Math.abs( this.actual(first) - this.actual(second) ) < Decimal.TOLERANCE; } Decimal();  Decimal(final OrderedRandom<Double> rand); @Override Scalar<Double> random(); @Override boolean equals(final Scalar<Double> first, final Scalar<Double> second); @Override InnerProduct<Double> product();  }
@Test public void delegatesActualValueForScalars() { final Decimal field = new Decimal(); final SpyScalar<Double> scalar = new SpyScalar<>(new Scalar.Default<>(0.)); field.actual(scalar); MatcherAssert.assertThat( "Expecting call to value method with field as parameter", scalar.field().isPresent() && scalar.field().get().equals(field) ); }
@Test public void delegatesRandomization() { final MkOrderedRandom<Double> rand = new MkOrderedRandom<>(); final Decimal field = new Decimal(rand); final Default<Double> zero = new Scalar.Default<>(0.); field.between(zero, zero); field.greater(zero); field.lower(zero); final Optional<List<Double>> params = rand.between(); MatcherAssert.assertThat( "Expecting call to between method with zero as parameters", params.isPresent() && params.get().get(0).equals(0.) && params.get().get(1).equals(0.) ); MatcherAssert.assertThat( "Expecting call to greater method with zero as parameter", rand.greater().isPresent() && rand.greater().get().equals(0.) ); MatcherAssert.assertThat( "Expecting call to lower method with zero as parameter", rand.lower().isPresent() && rand.lower().get().equals(0.) ); }