2023-10-03 23:08:19 +02:00
|
|
|
import {
|
|
|
|
|
ternarySearchRecursive,
|
|
|
|
|
ternarySearchIterative
|
|
|
|
|
} from '../TernarySearch'
|
2021-07-24 22:48:18 +08:00
|
|
|
|
|
|
|
|
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:', () => {
|
2023-10-03 23:08:19 +02:00
|
|
|
const indexNumber = ternarySearchIterative(
|
|
|
|
|
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
|
|
|
|
|
12
|
|
|
|
|
)
|
2021-07-24 22:48:18 +08:00
|
|
|
expect(indexNumber).toBe(-1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('should return the index of a string in an array of strings:', () => {
|
2023-10-03 23:08:19 +02:00
|
|
|
const indexNumber = ternarySearchRecursive(
|
|
|
|
|
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
|
|
|
|
'Cathrynli'
|
|
|
|
|
)
|
2021-07-24 22:48:18 +08:00
|
|
|
expect(indexNumber).toBe(1)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('should return the index of a string in an array of strings:', () => {
|
2023-10-03 23:08:19 +02:00
|
|
|
const indexNumber = ternarySearchRecursive(
|
|
|
|
|
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
|
|
|
|
'Josuke'
|
|
|
|
|
)
|
2021-07-24 22:48:18 +08:00
|
|
|
expect(indexNumber).toBe(2)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
test('should return the index of a string in an array of strings:', () => {
|
2023-10-03 23:08:19 +02:00
|
|
|
const indexNumber = ternarySearchRecursive(
|
|
|
|
|
['Ali', 'Cathrynli', 'Josuke', 'Thomas'],
|
|
|
|
|
'Angela'
|
|
|
|
|
)
|
2021-07-24 22:48:18 +08:00
|
|
|
expect(indexNumber).toBe(-1)
|
|
|
|
|
})
|