Add vitest setup and puzzleUtils tests
This commit is contained in:
2046
package-lock.json
generated
2046
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -5,7 +5,8 @@
|
|||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"test": "vitest"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"fireworks-js": "^2.10.8",
|
"fireworks-js": "^2.10.8",
|
||||||
@@ -16,7 +17,10 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vitejs/plugin-vue": "^5.0.4",
|
"@vitejs/plugin-vue": "^5.0.4",
|
||||||
|
"@vue/test-utils": "^2.4.6",
|
||||||
|
"jsdom": "^28.0.0",
|
||||||
"vite": "^5.1.4",
|
"vite": "^5.1.4",
|
||||||
"vite-plugin-pwa": "^0.20.5"
|
"vite-plugin-pwa": "^0.20.5",
|
||||||
|
"vitest": "^4.0.18"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
51
src/utils/puzzleUtils.spec.js
Normal file
51
src/utils/puzzleUtils.spec.js
Normal 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
16
vitest.config.js
Normal 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')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user