Skip to content

Commit

Permalink
added test cases for ternary search
Browse files Browse the repository at this point in the history
  • Loading branch information
Divyanshmandhan-1 committed Jan 28, 2021
1 parent 7a1e725 commit ef63e53
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions algorithms/search/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from .binary_search import *
from .ternary_search import *
from .first_occurrence import *
from .last_occurrence import *
from .linear_search import *
Expand Down
10 changes: 10 additions & 0 deletions tests/test_search.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from algorithms.search import (
binary_search, binary_search_recur,
ternary_search,
first_occurrence,
last_occurrence,
linear_search,
Expand Down Expand Up @@ -41,6 +42,15 @@ def test_binary_search(self):
self.assertEqual(11, binary_search_recur(array, 0, 11, 6))
self.assertEqual(-1, binary_search_recur(array, 0, 11, 7))
self.assertEqual(-1, binary_search_recur(array, 0, 11, -1))

def test_ternary_search(self):
array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6]
self.assertEqual(10, ternary_search(0, 11, 5, array))
self.assertEqual(3, ternary_search(0, 10, 3, array))
self.assertEqual(-1, ternary_search(0, 10, 5, array))
self.assertEqual(-1, ternary_search(0, 11, 7, array))
self.assertEqual(-1, ternary_search(0, 11, -1, array))


def test_last_occurrence(self):
array = [1, 2, 3, 3, 3, 3, 4, 4, 4, 4, 5, 6, 6, 6]
Expand Down

0 comments on commit ef63e53

Please sign in to comment.