Search in sources :

Example 1 with MiddleField

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);
    }
}
Also used : SmallField(core.field.SmallField) Field(core.field.Field) MiddleField(core.field.MiddleField) Randoms(lib.Randoms) MiddleField(core.field.MiddleField) SmallField(core.field.SmallField) Test(org.junit.jupiter.api.Test)

Aggregations

Field (core.field.Field)1 MiddleField (core.field.MiddleField)1 SmallField (core.field.SmallField)1 Randoms (lib.Randoms)1 Test (org.junit.jupiter.api.Test)1