mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00

* test: added for Linear Search Algorithm * Update Search/LinearSearch.js Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com> --------- Co-authored-by: Hridyanshu7 <himank7794@gmail.com> Co-authored-by: Lars Müller <34514239+appgurueu@users.noreply.github.com>
36 lines
692 B
JavaScript
36 lines
692 B
JavaScript
import { Search as linearSearch } from '../LinearSearch'
|
|
|
|
const tests = [
|
|
{
|
|
test: {
|
|
arr: [1, 2, 300, 401, 450, 504, 800, 821, 855, 900, 1002],
|
|
target: 900
|
|
},
|
|
expectedValue: 9
|
|
},
|
|
{
|
|
test: {
|
|
arr: [1, 104, 110, 4, 44, 55, 56, 78],
|
|
target: 104
|
|
},
|
|
expectedValue: 1
|
|
},
|
|
{
|
|
test: {
|
|
arr: [-4, 5, 50, 77, 821, 85, 99, 100],
|
|
target: 192
|
|
},
|
|
expectedValue: -1
|
|
}
|
|
]
|
|
|
|
describe('Linear Search', () => {
|
|
it.each(tests)(
|
|
'linearSearch($test.arr, $test.target) => $expectedValue',
|
|
({ test, expectedValue }) => {
|
|
const { arr, target } = test
|
|
expect(linearSearch(arr, target)).toBe(expectedValue)
|
|
}
|
|
)
|
|
})
|