Skip to content

Commit b87f96c

Browse files
authored
Add BotTest for movement bounds and preference (#42)
1 parent e468472 commit b87f96c

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package sample.models;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
import static org.junit.jupiter.api.Assertions.assertTrue;
5+
6+
import org.junit.jupiter.api.Test;
7+
8+
class BotTest {
9+
10+
@Test
11+
void singleCellGridStaysPut() {
12+
Bot bot = new Bot(1);
13+
assertEquals(MoveEnum.Stay, bot.determineMovement());
14+
}
15+
16+
@Test
17+
void determinedMovesNeverLeaveTheGrid() {
18+
Bot bot = new Bot(3);
19+
for (int i = 0; i < 500; i++) {
20+
bot.move(bot.determineMovement());
21+
assertTrue(bot.getX() >= 0 && bot.getX() < 3);
22+
assertTrue(bot.getY() >= 0 && bot.getY() < 3);
23+
}
24+
}
25+
26+
@Test
27+
void prefersTheOnlyUnvisitedNeighbor() {
28+
Bot bot = new Bot(2);
29+
bot.relocate(0, 0);
30+
bot.move(MoveEnum.Right);
31+
bot.move(MoveEnum.Left);
32+
for (int i = 0; i < 50; i++) {
33+
assertEquals(MoveEnum.Down, bot.determineMovement());
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)