use of core.field.MiddleField in project solution-finder by knewjade.
the class FieldComparatorTest method compare.
@Test
void compare() throws Exception {
Randoms randoms = new Randoms();
FieldComparator comparator = new FieldComparator();
for (int count = 0; count < 10000; count++) {
// same field
int height = randoms.nextInt(1, 6);
Field field1 = new SmallField();
Field field2 = new MiddleField();
int maxBlock = randoms.nextInt(1, 15);
for (int block = 0; block < maxBlock; block++) {
int x = randoms.nextInt(10);
int y = randoms.nextInt(height);
field1.setBlock(x, y);
field2.setBlock(x, y);
}
assertThat(comparator.compare(field1, field2)).isEqualTo(0);
assertThat(comparator.compare(field2, field1)).isEqualTo(0);
// 1block different field
int x = randoms.nextInt(10);
int y = randoms.nextInt(height);
if (field1.isEmpty(x, y))
field1.setBlock(x, y);
else
field1.removeBlock(x, y);
// assert is not 0 & reversed sign
assertThat(comparator.compare(field1, field2) * comparator.compare(field2, field1)).isLessThan(0);
}
}
Aggregations