forked from TheAlgorithms/JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTernarySearch.test.js
36 lines (29 loc) · 1.44 KB
/
TernarySearch.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)
expect(indexNumber).toBe(2)
})
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], 8)
expect(indexNumber).toBe(7)
})
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], 0)
expect(indexNumber).toBe(-1)
})
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)
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')
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')
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')
expect(indexNumber).toBe(-1)
})