Add vitest setup and puzzleUtils tests

This commit is contained in:
2026-02-09 22:51:00 +01:00
parent bdb7839293
commit c609075987
4 changed files with 2118 additions and 3 deletions

2046
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,8 @@
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
"preview": "vite preview",
"test": "vitest"
},
"dependencies": {
"fireworks-js": "^2.10.8",
@@ -16,7 +17,10 @@
},
"devDependencies": {
"@vitejs/plugin-vue": "^5.0.4",
"@vue/test-utils": "^2.4.6",
"jsdom": "^28.0.0",
"vite": "^5.1.4",
"vite-plugin-pwa": "^0.20.5"
"vite-plugin-pwa": "^0.20.5",
"vitest": "^4.0.18"
}
}

View File

@@ -0,0 +1,51 @@
import { describe, it, expect } from 'vitest'
import { calculateHints } from './puzzleUtils'
describe('puzzleUtils', () => {
it('calculateHints correctly calculates hints for a simple grid', () => {
const grid = [
[1, 0, 1],
[1, 1, 1],
[0, 1, 0]
]
// Row 0: 1, then space, then 1 -> [1, 1]
// Row 1: 1, 1, 1 -> [3]
// Row 2: space, 1, space -> [1]
// Col 0: 1, 1, 0 -> [2]
// Col 1: 0, 1, 1 -> [2] ? Wait. Col 1 is 0, 1, 1. So space, 1, 1 -> [2].
// Let's trace col 1 manually:
// r0,c1 = 0
// r1,c1 = 1 -> count=1
// r2,c1 = 1 -> count=2
// end -> push 2.
// So Col 1 is [2].
// Wait, my manual trace above for col 1:
// grid[0][1] is 0.
// grid[1][1] is 1.
// grid[2][1] is 1.
// Yes, [2].
// Col 2: 1, 1, 0 -> [2].
const expected = {
rowHints: [[1, 1], [3], [1]],
colHints: [[2], [2], [2]]
}
expect(calculateHints(grid)).toEqual(expected)
})
it('calculateHints handles empty rows/cols', () => {
const grid = [
[0, 0, 0],
[0, 0, 0],
[0, 0, 0]
]
const expected = {
rowHints: [[0], [0], [0]],
colHints: [[0], [0], [0]]
}
expect(calculateHints(grid)).toEqual(expected)
})
})

16
vitest.config.js Normal file
View File

@@ -0,0 +1,16 @@
import { defineConfig } from 'vitest/config'
import vue from '@vitejs/plugin-vue'
import path from 'path'
export default defineConfig({
plugins: [vue()],
test: {
globals: true,
environment: 'jsdom',
},
resolve: {
alias: {
'@': path.resolve(__dirname, './src')
}
}
})