feat: Test running overhaul, switch to Prettier & reformat everything (#1407)

* chore: Switch to Node 20 + Vitest

* chore: migrate to vitest mock functions

* chore: code style (switch to prettier)

* test: re-enable long-running test

Seems the switch to Node 20 and Vitest has vastly improved the code's and / or the test's runtime!

see #1193

* chore: code style

* chore: fix failing tests

* Updated Documentation in README.md

* Update contribution guidelines to state usage of Prettier

* fix: set prettier printWidth back to 80

* chore: apply updated code style automatically

* fix: set prettier line endings to lf again

* chore: apply updated code style automatically

---------

Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
This commit is contained in:
Roland Hummel
2023-10-03 23:08:19 +02:00
committed by GitHub
parent 0ca18c2b2c
commit 86d333ee94
392 changed files with 5849 additions and 16622 deletions

View File

@ -1,10 +1,10 @@
class Sudoku {
// Sudoku Class to hold the board and related functions
constructor (board) {
constructor(board) {
this.board = board
}
findEmptyCell () {
findEmptyCell() {
// Find a empty cell in the board (returns [-1, -1] if all cells are filled)
for (let i = 0; i < 9; i++) {
for (let j = 0; j < 9; j++) {
@ -14,7 +14,7 @@ class Sudoku {
return [-1, -1]
}
check ([y, x], value) {
check([y, x], value) {
// checks if the value to be added in the board is an acceptable value for the cell
// checking through the row
@ -29,8 +29,8 @@ class Sudoku {
// checking through the 3x3 block of the cell
const secRow = Math.floor(y / 3)
const secCol = Math.floor(x / 3)
for (let i = (secRow * 3); i < ((secRow * 3) + 3); i++) {
for (let j = (secCol * 3); j < ((secCol * 3) + 3); j++) {
for (let i = secRow * 3; i < secRow * 3 + 3; i++) {
for (let j = secCol * 3; j < secCol * 3 + 3; j++) {
if (y !== i && x !== j && this.board[i][j] === value) return false
}
}
@ -38,7 +38,7 @@ class Sudoku {
return true
}
solve () {
solve() {
const [y, x] = this.findEmptyCell()
// checking if the board is complete
@ -56,20 +56,23 @@ class Sudoku {
return false
}
getSection (row, [start, end]) {
getSection(row, [start, end]) {
return this.board[row].slice(start, end)
}
printBoard (output = (...v) => console.log(...v)) {
printBoard(output = (...v) => console.log(...v)) {
// helper function to display board
for (let i = 0; i < 9; i++) {
if (i % 3 === 0 && i !== 0) {
output('- - - - - - - - - - - -')
}
output(
...this.getSection(i, [0, 3]), ' | ',
...this.getSection(i, [3, 6]), ' | ',
...this.getSection(i, [6, 9]))
...this.getSection(i, [0, 3]),
' | ',
...this.getSection(i, [3, 6]),
' | ',
...this.getSection(i, [6, 9])
)
}
}
}