Add a top nav and Orbit Arcade with Snake (0.76.0)
pauljd/davidson-ci: Davidson CI / quality (push) Failing after 1m36s
pauljd/davidson-ci: Davidson CI / ai-review (push) Failing after 1m22s

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-11-02 14:22:35 +00:00
co-authored by Claude Opus 5.5
parent cd57325500
commit 2630215430
13 changed files with 348 additions and 34 deletions
@@ -0,0 +1,65 @@
package tv.orbit.classic
import org.junit.Assert.*
import org.junit.Test
import java.util.Random
class SnakeGameTest {
private val random = Random(1)
private fun game(vararg cells: Pair<Int, Int>, food: Pair<Int, Int> = 9 to 9, heading: SnakeDirection = SnakeDirection.Right) =
SnakeGame(10, 10, cells.map { SnakeCell(it.first, it.second) }, heading, heading, SnakeCell(food.first, food.second))
@Test fun itMovesForwardKeepingItsLength() {
val moved = game(3 to 5, 2 to 5, 1 to 5).step(random)
assertEquals(listOf(SnakeCell(4, 5), SnakeCell(3, 5), SnakeCell(2, 5)), moved.body)
assertTrue(moved.alive)
}
@Test fun eatingGrowsScoresAndPlacesNewFoodClearOfTheBody() {
val fed = game(3 to 5, 2 to 5, food = 4 to 5).step(random)
assertEquals(3, fed.body.size)
assertEquals(10, fed.score)
assertNotEquals(SnakeCell(4, 5), fed.food)
assertFalse(fed.food in fed.body)
}
@Test fun aWallEndsTheGame() {
assertFalse(game(9 to 5, 8 to 5).step(random).alive)
}
@Test fun hittingItselfEndsTheGame() {
val coiled = game(3 to 3, 3 to 4, 2 to 4, 2 to 3, 2 to 2, heading = SnakeDirection.Up).turn(SnakeDirection.Left)
assertFalse(coiled.step(random).alive)
}
@Test fun followingItsOwnTailIsSafe() {
val loop = SnakeGame(10, 10, listOf(SnakeCell(3, 3), SnakeCell(3, 4), SnakeCell(4, 4), SnakeCell(4, 3)), SnakeDirection.Up, SnakeDirection.Right, SnakeCell(9, 9))
assertTrue(loop.step(random).alive)
}
@Test fun aTurnBackOnItselfIsIgnored() {
val game = game(3 to 5, 2 to 5)
assertEquals(SnakeDirection.Right, game.turn(SnakeDirection.Left).wanted)
assertEquals(SnakeDirection.Up, game.turn(SnakeDirection.Up).wanted)
}
@Test fun twoQuickTurnsCantReverseIt() {
// Up then left before it moves: left is judged against where it's really heading.
val game = game(3 to 5, 2 to 5).turn(SnakeDirection.Up).turn(SnakeDirection.Left)
assertEquals(SnakeDirection.Right, game.heading)
assertEquals(SnakeDirection.Up, game.wanted)
}
@Test fun itQuickensUpToALimit() {
assertEquals(150L, game(3 to 5, 2 to 5).tickMs)
assertTrue(game(3 to 5, 2 to 5).copy(score = 100).tickMs < 150L)
assertEquals(70L, game(3 to 5, 2 to 5).copy(score = 10_000).tickMs)
}
@Test fun aNewGameStartsWithFoodOffTheSnake() {
val start = SnakeGame.start(30, 22, Random(2))
assertEquals(4, start.body.size)
assertFalse(start.food in start.body)
assertTrue(start.alive)
}
}