GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — merge: Add proper tests for binary search (#987) · Algorithms-Learn/JavaScript@298ab33

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • Search
    • BinarySearch.js
    • test
      • BinarySearch.test.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎Search/BinarySearch.js‎

Copy file name to clipboardExpand all lines: Search/BinarySearch.js
-39Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -50,42 +50,3 @@ function binarySearchIterative (arr, x, low = 0, high = arr.length - 1) {
5050
}
5151

5252
export { binarySearchIterative, binarySearchRecursive }
53-
54-
/* ---------------------------------- Test ---------------------------------- */
55-
56-
// const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
57-
// const stringArr = [
58-
// 'Alpha',
59-
// 'Bravo',
60-
// 'Charlie',
61-
// 'Delta',
62-
// 'Echo',
63-
// 'Foxtrot',
64-
// 'Golf',
65-
// 'Hotel',
66-
// 'India',
67-
// 'Juliet',
68-
// 'Kilo',
69-
// 'Lima',
70-
// 'Mike',
71-
// 'November',
72-
// 'Oscar',
73-
// 'Papa',
74-
// 'Quebec',
75-
// 'Romeo',
76-
// 'Sierra',
77-
// 'Tango',
78-
// 'Uniform',
79-
// 'Victor',
80-
// 'Whiskey',
81-
// 'X-Ray',
82-
// 'Yankee',
83-
// 'Zulu'
84-
// ]
85-
86-
// binarySearchRecursive(arr, 3)
87-
// binarySearchIterative(arr, 7)
88-
// binarySearchRecursive(arr, 13)
89-
// binarySearchIterative(stringArr, 'Charlie')
90-
// binarySearchRecursive(stringArr, 'Zulu')
91-
// binarySearchIterative(stringArr, 'Sierra')
Collapse file

‎Search/test/BinarySearch.test.js‎

Copy file name to clipboard
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import { binarySearchIterative, binarySearchRecursive } from '../BinarySearch'
2+
3+
const arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
4+
const stringArr = [
5+
'Alpha',
6+
'Bravo',
7+
'Charlie',
8+
'Delta',
9+
'Echo',
10+
'Foxtrot',
11+
'Golf',
12+
'Hotel',
13+
'India',
14+
'Juliet',
15+
'Kilo',
16+
'Lima',
17+
'Mike',
18+
'November',
19+
'Oscar',
20+
'Papa',
21+
'Quebec',
22+
'Romeo',
23+
'Sierra',
24+
'Tango',
25+
'Uniform',
26+
'Victor',
27+
'Whiskey',
28+
'X-Ray',
29+
'Yankee',
30+
'Zulu'
31+
]
32+
33+
describe('Binary Search', () => {
34+
const funcs = [binarySearchIterative, binarySearchRecursive]
35+
for (const func of funcs) {
36+
test('expect to return the index of the item in the array', () => {
37+
expect(func(arr, 3)).toBe(2)
38+
})
39+
test('expect to return -1 if not in array', () => {
40+
expect(func(arr, 11)).toBe(-1)
41+
})
42+
test('expect to return the index of the item in the array', () => {
43+
expect(func(stringArr, 'Charlie')).toBe(2)
44+
})
45+
test('expect to return -1 if not in array', () => {
46+
expect(func(stringArr, 'Zoft')).toBe(-1)
47+
})
48+
}
49+
})

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.