feat(js): m03 rules with fixtures and tests

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
Lucas WintherandClaude Sonnet 5.5 committed 2026-10-28 23:41:34 +01:00
1 parent e9c41fed03
commit 2e39f23bb3
7 files changed
+1570

No files matched your search

+453
View File
@@ -0,0 +1,453 @@
{
"function": "turn",
"cases": [
{
"name": "turn-normal-perpendicular",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
},
"Up"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Up",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "turn-same-direction-is-fine",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
},
"Right"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "turn-reverse-rejected",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
},
"Left"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "turn-replaces-pending-turn",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Up",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
},
"Down"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Down",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "turn-against-last-moved-dir",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Up",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
},
"Left"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Up",
"apple": null,
"seed": 1,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "turn-ignored-when-paused",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Paused",
"frame": 0
},
"Up"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Paused",
"frame": 0
}
},
{
"name": "turn-ignored-when-game-over",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "GameOver",
"frame": 0
},
"Up"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "GameOver",
"frame": 0
}
},
{
"name": "turn-ignored-when-won",
"args": [
{
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Won",
"frame": 0
},
"Up"
],
"expected": {
"width": 5,
"height": 5,
"snake": [
{
"x": 2,
"y": 2
},
{
"x": 1,
"y": 2
},
{
"x": 0,
"y": 2
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 1,
"score": 0,
"status": "Won",
"frame": 0
}
}
]
}