Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit85a55da

Browse files
HRIDYANSHU054Hridyanshu7appgurueu
authored
test: added for Linear Search Algorithm (#1753)
* test: added for Linear Search Algorithm* Update Search/LinearSearch.jsCo-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>
1 parentd8588f9 commit85a55da

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

‎Search/LinearSearch.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* value within a list. It sequentially checks each element of the list
44
* for the target value until a match is found or until all the elements
55
* have been searched.
6+
*
7+
*@see https://en.wikipedia.org/wiki/Linear_search
68
*/
79
functionSearchArray(searchNum,ar,output=(v)=>console.log(v)){
810
constposition=Search(ar,searchNum)

‎Search/test/LinearSearch.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import{SearchaslinearSearch}from'../LinearSearch'
2+
3+
consttests=[
4+
{
5+
test:{
6+
arr:[1,2,300,401,450,504,800,821,855,900,1002],
7+
target:900
8+
},
9+
expectedValue:9
10+
},
11+
{
12+
test:{
13+
arr:[1,104,110,4,44,55,56,78],
14+
target:104
15+
},
16+
expectedValue:1
17+
},
18+
{
19+
test:{
20+
arr:[-4,5,50,77,821,85,99,100],
21+
target:192
22+
},
23+
expectedValue:-1
24+
}
25+
]
26+
27+
describe('Linear Search',()=>{
28+
it.each(tests)(
29+
'linearSearch($test.arr, $test.target) => $expectedValue',
30+
({ test, expectedValue})=>{
31+
const{ arr, target}=test
32+
expect(linearSearch(arr,target)).toBe(expectedValue)
33+
}
34+
)
35+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp