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:
@@ -1,15 +1,15 @@
|
||||
import { exponentialSearch } from '../ExponentialSearch'
|
||||
|
||||
test('The Exponential Search of the Array [2, 3, 4, 10, 40, 65, 78, 100] is 6 where the value = 78', () => {
|
||||
const arr = [2, 3, 4, 10, 40, 65, 78, 100]
|
||||
const value = 78
|
||||
const result = exponentialSearch(arr, arr.length, value)
|
||||
expect(result).toEqual(6)
|
||||
})
|
||||
|
||||
test('The Exponential Search of the Array [2, 3, 4, 10, 40, 65, 78, 100] is -1 where the value = 178', () => {
|
||||
const arr = [2, 3, 4, 10, 40, 65, 78, 100]
|
||||
const value = 178
|
||||
const result = exponentialSearch(arr, arr.length, value)
|
||||
expect(result).toEqual(-1)
|
||||
})
|
||||
import { exponentialSearch } from '../ExponentialSearch'
|
||||
|
||||
test('The Exponential Search of the Array [2, 3, 4, 10, 40, 65, 78, 100] is 6 where the value = 78', () => {
|
||||
const arr = [2, 3, 4, 10, 40, 65, 78, 100]
|
||||
const value = 78
|
||||
const result = exponentialSearch(arr, arr.length, value)
|
||||
expect(result).toEqual(6)
|
||||
})
|
||||
|
||||
test('The Exponential Search of the Array [2, 3, 4, 10, 40, 65, 78, 100] is -1 where the value = 178', () => {
|
||||
const arr = [2, 3, 4, 10, 40, 65, 78, 100]
|
||||
const value = 178
|
||||
const result = exponentialSearch(arr, arr.length, value)
|
||||
expect(result).toEqual(-1)
|
||||
})
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { fibonacciSearch } from '../FibonacciSearch'
|
||||
|
||||
test('fibonacciSearch([10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100], 90, arr.length) => 9', () => {
|
||||
const arr = [10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100]
|
||||
const target = 90
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(9)
|
||||
})
|
||||
|
||||
test('fibonacciSearch([1, 11, 55, 56, 78, 82, 104], 104, arr.length) => 6', () => {
|
||||
const arr = [1, 11, 55, 56, 78, 82, 104]
|
||||
const target = 104
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(6)
|
||||
})
|
||||
|
||||
test('fibonacciSearch([40, 45, 50, 80, 82, 85, 90, 100]. 190, arr.length) => -1', () => {
|
||||
const arr = [40, 45, 50, 80, 82, 85, 90, 100]
|
||||
const target = 190
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
import { fibonacciSearch } from '../FibonacciSearch'
|
||||
|
||||
test('fibonacciSearch([10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100], 90, arr.length) => 9', () => {
|
||||
const arr = [10, 22, 35, 40, 45, 50, 80, 82, 85, 90, 100]
|
||||
const target = 90
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(9)
|
||||
})
|
||||
|
||||
test('fibonacciSearch([1, 11, 55, 56, 78, 82, 104], 104, arr.length) => 6', () => {
|
||||
const arr = [1, 11, 55, 56, 78, 82, 104]
|
||||
const target = 104
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(6)
|
||||
})
|
||||
|
||||
test('fibonacciSearch([40, 45, 50, 80, 82, 85, 90, 100]. 190, arr.length) => -1', () => {
|
||||
const arr = [40, 45, 50, 80, 82, 85, 90, 100]
|
||||
const target = 190
|
||||
const res = fibonacciSearch(arr, target, arr.length)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import { interpolationSearch } from '../InterpolationSearch'
|
||||
|
||||
test('interpolationSearch([2, 6, 8, 14, 122, 169], 144) => -1', () => {
|
||||
const array = [2, 6, 8, 14, 122, 169]
|
||||
const key = 144
|
||||
const res = interpolationSearch(array, key)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
|
||||
test('interpolationSearch([2, 6, 8, 14, 122, 169], 122) => 4', () => {
|
||||
const array = [2, 6, 8, 14, 122, 169]
|
||||
const key = 122
|
||||
const res = interpolationSearch(array, key)
|
||||
expect(res).toEqual(4)
|
||||
})
|
||||
import { interpolationSearch } from '../InterpolationSearch'
|
||||
|
||||
test('interpolationSearch([2, 6, 8, 14, 122, 169], 144) => -1', () => {
|
||||
const array = [2, 6, 8, 14, 122, 169]
|
||||
const key = 144
|
||||
const res = interpolationSearch(array, key)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
|
||||
test('interpolationSearch([2, 6, 8, 14, 122, 169], 122) => 4', () => {
|
||||
const array = [2, 6, 8, 14, 122, 169]
|
||||
const key = 122
|
||||
const res = interpolationSearch(array, key)
|
||||
expect(res).toEqual(4)
|
||||
})
|
||||
|
||||
@@ -1,4 +1,7 @@
|
||||
import { ternarySearchRecursive, ternarySearchIterative } from '../TernarySearch'
|
||||
import {
|
||||
ternarySearchRecursive,
|
||||
ternarySearchIterative
|
||||
} from '../TernarySearch'
|
||||
|
||||
test('should return the index of a number in an array of numbers:', () => {
|
||||
const indexNumber = ternarySearchRecursive([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 3)
|
||||
@@ -16,21 +19,33 @@ test('should return the index of a number in an array of numbers:', () => {
|
||||
})
|
||||
|
||||
test('should return the index of a number in an array of numbers:', () => {
|
||||
const indexNumber = ternarySearchIterative([1, 2, 3, 4, 5, 6, 7, 8, 9, 10], 12)
|
||||
const indexNumber = ternarySearchIterative(
|
||||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
||||
12
|
||||
)
|
||||
expect(indexNumber).toBe(-1)
|
||||
})
|
||||
|
||||
test('should return the index of a string in an array of strings:', () => {
|
||||
const indexNumber = ternarySearchRecursive(['Ali', 'Cathrynli', 'Josuke', 'Thomas'], 'Cathrynli')
|
||||
const indexNumber = ternarySearchRecursive(
|
||||
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
||||
'Cathrynli'
|
||||
)
|
||||
expect(indexNumber).toBe(1)
|
||||
})
|
||||
|
||||
test('should return the index of a string in an array of strings:', () => {
|
||||
const indexNumber = ternarySearchRecursive(['Ali', 'Cathrynli', 'Josuke', 'Thomas'], 'Josuke')
|
||||
const indexNumber = ternarySearchRecursive(
|
||||
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
||||
'Josuke'
|
||||
)
|
||||
expect(indexNumber).toBe(2)
|
||||
})
|
||||
|
||||
test('should return the index of a string in an array of strings:', () => {
|
||||
const indexNumber = ternarySearchRecursive(['Ali', 'Cathrynli', 'Josuke', 'Thomas'], 'Angela')
|
||||
const indexNumber = ternarySearchRecursive(
|
||||
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
||||
'Angela'
|
||||
)
|
||||
expect(indexNumber).toBe(-1)
|
||||
})
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { jumpSearch } from '../JumpSearch'
|
||||
|
||||
test('jumpSearch([0, 0, 4, 7, 10, 23, 34, 40, 55, 68, 77, 90], 77) => 10', () => {
|
||||
const arr = [0, 0, 4, 7, 10, 23, 34, 40, 55, 68, 77, 90]
|
||||
const res = jumpSearch(arr, 77)
|
||||
expect(res).toEqual(10)
|
||||
})
|
||||
|
||||
test('jumpSearch([11, 12, 15, 65, 78, 90], 4) => -1', () => {
|
||||
const arr = [11, 12, 15, 65, 78, 90]
|
||||
const res = jumpSearch(arr, 4)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
|
||||
test('jumpSearch([11, 12, 15, 65, 78, 90], 11) => 0', () => {
|
||||
const arr = [11, 12, 15, 65, 78, 90]
|
||||
const res = jumpSearch(arr, 11)
|
||||
expect(res).toEqual(0)
|
||||
})
|
||||
import { jumpSearch } from '../JumpSearch'
|
||||
|
||||
test('jumpSearch([0, 0, 4, 7, 10, 23, 34, 40, 55, 68, 77, 90], 77) => 10', () => {
|
||||
const arr = [0, 0, 4, 7, 10, 23, 34, 40, 55, 68, 77, 90]
|
||||
const res = jumpSearch(arr, 77)
|
||||
expect(res).toEqual(10)
|
||||
})
|
||||
|
||||
test('jumpSearch([11, 12, 15, 65, 78, 90], 4) => -1', () => {
|
||||
const arr = [11, 12, 15, 65, 78, 90]
|
||||
const res = jumpSearch(arr, 4)
|
||||
expect(res).toEqual(-1)
|
||||
})
|
||||
|
||||
test('jumpSearch([11, 12, 15, 65, 78, 90], 11) => 0', () => {
|
||||
const arr = [11, 12, 15, 65, 78, 90]
|
||||
const res = jumpSearch(arr, 11)
|
||||
expect(res).toEqual(0)
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user