Skip to content
This repository has been archived by the owner on Apr 29, 2020. It is now read-only.

Commit

Permalink
Tests for Binary Search (#57)
Browse files Browse the repository at this point in the history
Tests for Binary Search recursive
  • Loading branch information
soummyaah authored and aktech committed Apr 14, 2016
1 parent 5a58a2f commit 83cfac5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
17 changes: 15 additions & 2 deletions pydsa/tests/test_binary_search.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
from pydsa.binary_search import binary_search
from random import randint


def test_binary_search():
a = [randint(1, 10) for i in range(10)]
item = randint(1, 10)
a = sorted(a)
ans = binary_search(a, item)
if(ans == -1):
if(ans == -1):
assert item not in a
else:
else:
assert a[ans] == item


def test_binary_search_recursive():
a = [randint(1, 10) for i in range(10)]
item = randint(1, 10)
a = sorted(a)
ans_through_method_1 = binary_search(a, item, True)
ans_through_method_2 = binary_search(a, item, True, 0, len(a) - 1)
if(ans_through_method_1 == ans_through_method_2 == -1):
assert item not in a
else:
assert a[ans_through_method_1] == item == a[ans_through_method_2]
13 changes: 0 additions & 13 deletions pydsa/tests/test_binary_search_recursive.py

This file was deleted.

0 comments on commit 83cfac5

Please sign in to comment.