143 lines
3.9 KiB
Java
143 lines
3.9 KiB
Java
package ch.fritteli.maze.generator.model;
|
|
|
|
import ch.fritteli.maze.generator.model.Direction;
|
|
import ch.fritteli.maze.generator.model.Walls;
|
|
import io.vavr.collection.Stream;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
|
|
|
class WallsTest {
|
|
@Test
|
|
void testConstruct() {
|
|
// arrange / act
|
|
final Walls sut = new Walls();
|
|
|
|
// assert
|
|
assertThat(sut)
|
|
.returns(false, v -> v.isSet(Direction.TOP))
|
|
.returns(false, v -> v.isSet(Direction.RIGHT))
|
|
.returns(false, v -> v.isSet(Direction.BOTTOM))
|
|
.returns(false, v -> v.isSet(Direction.LEFT));
|
|
}
|
|
|
|
@Test
|
|
void testSet() {
|
|
// arrange
|
|
final Walls sut = new Walls();
|
|
|
|
//act
|
|
sut.set(Direction.RIGHT);
|
|
|
|
// assert
|
|
assertThat(sut)
|
|
.returns(false, v -> v.isSet(Direction.TOP))
|
|
.returns(true, v -> v.isSet(Direction.RIGHT))
|
|
.returns(false, v -> v.isSet(Direction.BOTTOM))
|
|
.returns(false, v -> v.isSet(Direction.LEFT));
|
|
|
|
//act: Setting twice has no effect
|
|
sut.set(Direction.RIGHT);
|
|
|
|
// assert
|
|
assertThat(sut)
|
|
.returns(false, v -> v.isSet(Direction.TOP))
|
|
.returns(true, v -> v.isSet(Direction.RIGHT))
|
|
.returns(false, v -> v.isSet(Direction.BOTTOM))
|
|
.returns(false, v -> v.isSet(Direction.LEFT));
|
|
}
|
|
|
|
@Test
|
|
void testSetAll() {
|
|
// arrange
|
|
final Walls sut = new Walls();
|
|
|
|
//act
|
|
sut.setAll();
|
|
|
|
// assert
|
|
assertThat(sut)
|
|
.returns(true, v -> v.isSet(Direction.TOP))
|
|
.returns(true, v -> v.isSet(Direction.RIGHT))
|
|
.returns(true, v -> v.isSet(Direction.BOTTOM))
|
|
.returns(true, v -> v.isSet(Direction.LEFT));
|
|
}
|
|
|
|
@Test
|
|
void testHarden() {
|
|
// arrange
|
|
final Walls sut = new Walls();
|
|
sut.set(Direction.TOP);
|
|
sut.set(Direction.RIGHT);
|
|
|
|
// act
|
|
sut.harden(Direction.TOP);
|
|
|
|
// assert
|
|
assertThat(sut)
|
|
.returns(true, v -> v.isSet(Direction.TOP))
|
|
.returns(true, v -> v.isSet(Direction.RIGHT))
|
|
.returns(false, v -> v.isSet(Direction.BOTTOM))
|
|
.returns(false, v -> v.isSet(Direction.LEFT));
|
|
|
|
// act: try to clear hardened wall
|
|
final boolean result = sut.clear(Direction.TOP);
|
|
|
|
// assert: TOP wall is still set
|
|
assertThat(result).isFalse();
|
|
assertThat(sut.isSet(Direction.TOP)).isTrue();
|
|
|
|
// act / assert: try to harden un-set wall
|
|
assertThatExceptionOfType(IllegalStateException.class).isThrownBy(() -> sut.harden(Direction.LEFT));
|
|
}
|
|
|
|
@Test
|
|
void testUnharden() {
|
|
// arrange
|
|
final Walls sut = new Walls();
|
|
sut.setAll();
|
|
sut.harden(Direction.TOP);
|
|
|
|
// pre-assert: TOP can't be cleared while hardened
|
|
assertThat(sut.clear(Direction.TOP)).isFalse();
|
|
|
|
// act
|
|
sut.unharden(Direction.TOP);
|
|
|
|
// assert: TOP can be cleared
|
|
assertThat(sut.clear(Direction.TOP)).isTrue();
|
|
}
|
|
|
|
@Test
|
|
void testGetUnhardenedSet() {
|
|
// arrange
|
|
final Walls sut = new Walls();
|
|
|
|
// act
|
|
Stream<Direction> result = sut.getUnhardenedSet();
|
|
|
|
// assert
|
|
assertThat(result).isEmpty();
|
|
|
|
// arrange: set some directions
|
|
sut.set(Direction.TOP);
|
|
sut.set(Direction.LEFT);
|
|
|
|
// act
|
|
result = sut.getUnhardenedSet();
|
|
|
|
// assert
|
|
assertThat(result).containsExactly(Direction.TOP, Direction.LEFT);
|
|
|
|
// arrange: harden a direction
|
|
sut.harden(Direction.TOP);
|
|
|
|
// act
|
|
result = sut.getUnhardenedSet();
|
|
|
|
// assert
|
|
assertThat(result).containsExactly(Direction.LEFT);
|
|
}
|
|
}
|