feat(js): m04 random and spawn with fixtures and tests

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-28 23:42:36 +01:00
co-authored by Claude Sonnet 5.5
parent 2e39f23bb3
commit 08b462d5cc
11 changed files with 1332 additions and 0 deletions
+452
View File
@@ -0,0 +1,452 @@
{
"function": "spawnApple",
"cases": [
{
"name": "spawn-picks-a-free-cell-and-advances-seed",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 0,
"score": 0,
"status": "Playing",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": {
"x": 1,
"y": 1
},
"seed": 1831565813,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "spawn-other-seed-picks-other-cell",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": {
"x": 2,
"y": 1
},
"seed": 1831565814,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "spawn-with-one-free-cell",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 0,
"y": 0
},
{
"x": 1,
"y": 0
},
{
"x": 2,
"y": 0
},
{
"x": 2,
"y": 1
},
{
"x": 1,
"y": 1
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 7,
"score": 0,
"status": "Playing",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 0,
"y": 0
},
{
"x": 1,
"y": 0
},
{
"x": 2,
"y": 0
},
{
"x": 2,
"y": 1
},
{
"x": 1,
"y": 1
}
],
"dir": "Right",
"nextDir": "Right",
"apple": {
"x": 0,
"y": 1
},
"seed": 1831565820,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "spawn-on-full-board",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 0,
"y": 0
},
{
"x": 1,
"y": 0
},
{
"x": 2,
"y": 0
},
{
"x": 2,
"y": 1
},
{
"x": 1,
"y": 1
},
{
"x": 0,
"y": 1
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Playing",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 0,
"y": 0
},
{
"x": 1,
"y": 0
},
{
"x": 2,
"y": 0
},
{
"x": 2,
"y": 1
},
{
"x": 1,
"y": 1
},
{
"x": 0,
"y": 1
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Won",
"frame": 0
}
},
{
"name": "spawn-apple-present-unchanged",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": {
"x": 2,
"y": 1
},
"seed": 5,
"score": 0,
"status": "Playing",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": {
"x": 2,
"y": 1
},
"seed": 5,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "spawn-paused-unchanged",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Paused",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Paused",
"frame": 0
}
},
{
"name": "spawn-gameover-unchanged",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "GameOver",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "GameOver",
"frame": 0
}
},
{
"name": "spawn-won-unchanged",
"args": [
{
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Won",
"frame": 0
}
],
"expected": {
"width": 3,
"height": 2,
"snake": [
{
"x": 1,
"y": 0
},
{
"x": 0,
"y": 0
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 5,
"score": 0,
"status": "Won",
"frame": 0
}
}
]
}