mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
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:
@@ -3,11 +3,22 @@ import { Combinations } from '../AllCombinationsOfSizeK'
|
||||
describe('AllCombinationsOfSizeK', () => {
|
||||
it('should return 3x2 matrix solution for n = 3 and k = 2', () => {
|
||||
const test1 = new Combinations(3, 2)
|
||||
expect(test1.findCombinations()).toEqual([[1, 2], [1, 3], [2, 3]])
|
||||
expect(test1.findCombinations()).toEqual([
|
||||
[1, 2],
|
||||
[1, 3],
|
||||
[2, 3]
|
||||
])
|
||||
})
|
||||
|
||||
it('should return 6x2 matrix solution for n = 4 and k = 2', () => {
|
||||
const test2 = new Combinations(4, 2)
|
||||
expect(test2.findCombinations()).toEqual([[1, 2], [1, 3], [1, 4], [2, 3], [2, 4], [3, 4]])
|
||||
expect(test2.findCombinations()).toEqual([
|
||||
[1, 2],
|
||||
[1, 3],
|
||||
[1, 4],
|
||||
[2, 3],
|
||||
[2, 4],
|
||||
[3, 4]
|
||||
])
|
||||
})
|
||||
})
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
import { generateParentheses } from '../generateParentheses'
|
||||
|
||||
test('generate all valid parentheses of input 3', () => {
|
||||
expect(generateParentheses(3)).toStrictEqual(['((()))', '(()())', '(())()', '()(())', '()()()'])
|
||||
expect(generateParentheses(3)).toStrictEqual([
|
||||
'((()))',
|
||||
'(()())',
|
||||
'(())()',
|
||||
'()(())',
|
||||
'()()()'
|
||||
])
|
||||
})
|
||||
|
||||
@@ -14,6 +14,8 @@ describe('NQueens', () => {
|
||||
})
|
||||
|
||||
it('should throw RangeError for negative size board', () => {
|
||||
expect(() => { return new NQueens(-1) }).toThrow(RangeError)
|
||||
expect(() => {
|
||||
return new NQueens(-1)
|
||||
}).toThrow(RangeError)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -7,14 +7,18 @@ describe('RatInAMaze', () => {
|
||||
for (const value of values) {
|
||||
// we deliberately want to check whether this constructor call fails or not
|
||||
// eslint-disable-next-line no-new
|
||||
expect(() => { new RatInAMaze(value) }).toThrow()
|
||||
expect(() => {
|
||||
new RatInAMaze(value)
|
||||
}).toThrow()
|
||||
}
|
||||
})
|
||||
|
||||
it('should fail for an empty array', () => {
|
||||
// we deliberately want to check whether this constructor call fails or not
|
||||
// eslint-disable-next-line no-new
|
||||
expect(() => { new RatInAMaze([]) }).toThrow()
|
||||
expect(() => {
|
||||
new RatInAMaze([])
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('should fail for a non-square array', () => {
|
||||
@@ -25,7 +29,9 @@ describe('RatInAMaze', () => {
|
||||
|
||||
// we deliberately want to check whether this constructor call fails or not
|
||||
// eslint-disable-next-line no-new
|
||||
expect(() => { new RatInAMaze(array) }).toThrow()
|
||||
expect(() => {
|
||||
new RatInAMaze(array)
|
||||
}).toThrow()
|
||||
})
|
||||
|
||||
it('should fail for arrays containing invalid values', () => {
|
||||
@@ -34,7 +40,9 @@ describe('RatInAMaze', () => {
|
||||
for (const value of values) {
|
||||
// we deliberately want to check whether this constructor call fails or not
|
||||
// eslint-disable-next-line no-new
|
||||
expect(() => { new RatInAMaze(value) }).toThrow()
|
||||
expect(() => {
|
||||
new RatInAMaze(value)
|
||||
}).toThrow()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -51,13 +59,20 @@ describe('RatInAMaze', () => {
|
||||
})
|
||||
|
||||
it('should work for a simple 3x3 maze', () => {
|
||||
const maze = new RatInAMaze([[1, 1, 0], [0, 1, 0], [0, 1, 1]])
|
||||
const maze = new RatInAMaze([
|
||||
[1, 1, 0],
|
||||
[0, 1, 0],
|
||||
[0, 1, 1]
|
||||
])
|
||||
expect(maze.solved).toBe(true)
|
||||
expect(maze.path).toBe('RDDR')
|
||||
})
|
||||
|
||||
it('should work for a simple 2x2 that can not be solved', () => {
|
||||
const maze = new RatInAMaze([[1, 0], [0, 1]])
|
||||
const maze = new RatInAMaze([
|
||||
[1, 0],
|
||||
[0, 1]
|
||||
])
|
||||
expect(maze.solved).toBe(false)
|
||||
expect(maze.path).toBe('')
|
||||
})
|
||||
|
||||
@@ -28,7 +28,9 @@ describe('Sudoku', () => {
|
||||
it('should create a valid board successfully', () => {
|
||||
// we deliberately want to check whether this constructor call fails or not
|
||||
// eslint-disable-next-line no-new
|
||||
expect(() => { new Sudoku(data) }).not.toThrow()
|
||||
expect(() => {
|
||||
new Sudoku(data)
|
||||
}).not.toThrow()
|
||||
})
|
||||
|
||||
it('should find an empty cell', () => {
|
||||
|
||||
Reference in New Issue
Block a user