feat(js): m01 util and m02 model with tests, fixtures, purity audit

Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
Lucas Winther
2026-10-28 23:38:29 +01:00
co-authored by Claude Sonnet 5.5
parent 5be3cebe71
commit 22c221a042
14 changed files with 508 additions and 4 deletions
+45
View File
@@ -0,0 +1,45 @@
{
"function": "delta",
"cases": [
{
"name": "up",
"args": [
"Up"
],
"expected": {
"x": 0,
"y": -1
}
},
{
"name": "down",
"args": [
"Down"
],
"expected": {
"x": 0,
"y": 1
}
},
{
"name": "left",
"args": [
"Left"
],
"expected": {
"x": -1,
"y": 0
}
},
{
"name": "right",
"args": [
"Right"
],
"expected": {
"x": 1,
"y": 0
}
}
]
}
+67
View File
@@ -0,0 +1,67 @@
{
"function": "initialState",
"cases": [
{
"name": "seed-7",
"args": [
7
],
"expected": {
"width": 20,
"height": 20,
"snake": [
{
"x": 10,
"y": 10
},
{
"x": 9,
"y": 10
},
{
"x": 8,
"y": 10
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 7,
"score": 0,
"status": "Playing",
"frame": 0
}
},
{
"name": "seed-is-stored-as-given",
"args": [
4294967295
],
"expected": {
"width": 20,
"height": 20,
"snake": [
{
"x": 10,
"y": 10
},
{
"x": 9,
"y": 10
},
{
"x": 8,
"y": 10
}
],
"dir": "Right",
"nextDir": "Right",
"apple": null,
"seed": 4294967295,
"score": 0,
"status": "Playing",
"frame": 0
}
}
]
}
+33
View File
@@ -0,0 +1,33 @@
{
"function": "opposite",
"cases": [
{
"name": "up",
"args": [
"Up"
],
"expected": "Down"
},
{
"name": "down",
"args": [
"Down"
],
"expected": "Up"
},
{
"name": "left",
"args": [
"Left"
],
"expected": "Right"
},
{
"name": "right",
"args": [
"Right"
],
"expected": "Left"
}
]
}
+61
View File
@@ -0,0 +1,61 @@
{
"function": "pointEquals",
"cases": [
{
"name": "same-point",
"args": [
{
"x": 3,
"y": 4
},
{
"x": 3,
"y": 4
}
],
"expected": true
},
{
"name": "different-x",
"args": [
{
"x": 3,
"y": 4
},
{
"x": 2,
"y": 4
}
],
"expected": false
},
{
"name": "different-y",
"args": [
{
"x": 3,
"y": 4
},
{
"x": 3,
"y": 5
}
],
"expected": false
},
{
"name": "swapped-coordinates",
"args": [
{
"x": 3,
"y": 4
},
{
"x": 4,
"y": 3
}
],
"expected": false
}
]
}