VectEquals implements Predicate<Field<T>> { @Override public boolean resolve(final Field<T> field) { final Scalar<T>[] fcoords = this.first.coords(); final Scalar<T>[] scoords = this.second.coords(); return fcoords.length == scoords.length && VectEquals.arraysEqual(fcoords, scoords, field); } VectEquals(final Vect<T> first, final Vect<T> second); @Override boolean resolve(final Field<T> field);  }
@Test public void resolvesToTrueWhenEqual() { final List<Scalar<Double>> coords = Lists.newArrayList( new Scalars<>(1 + new Random().nextInt(VectEqualsTest.COORDS_LENGTH)) ); MatcherAssert.assertThat( new VectEquals<>( new FixedVector<>(coords), new FixedVector<>(coords) ).resolve(new Decimal()), Matchers.is(true) ); }
@Test public void resolvesToFalseWhenNotEqual() { final List<Scalar<Double>> coords = Lists.newArrayList( new Scalars<>(2 + new Random().nextInt(VectEqualsTest.COORDS_LENGTH)) ); final List<Scalar<Double>> second = Lists.newArrayList(coords); second.remove(0); second.add(0, new Different<>(coords.get(0))); MatcherAssert.assertThat( new VectEquals<>( new FixedVector<>(coords), new FixedVector<>(second) ).resolve(new Decimal()), Matchers.is(false) ); }
@Test public void resolvesToFalseWhenNotSameDimension() { final List<Scalar<Double>> coords = Lists.newArrayList( new Scalars<>(2 + new Random().nextInt(VectEqualsTest.COORDS_LENGTH)) ); final List<Scalar<Double>> second = Lists.newArrayList(coords); second.remove(second.size() - 1); MatcherAssert.assertThat( new VectEquals<>( new FixedVector<>(coords), new FixedVector<>(second) ).resolve(new Decimal()), Matchers.is(false) ); }