Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structural Testing File interpolation_search.py #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions algorithms/searches/interpolation_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,29 @@ def __assert_sorted(collection):
raise ValueError('Collection must be sorted')
return True

import unittest
class Testinterpolation_search(unittest.TestCase):
def testMCC(self):
self.assertEqual(None, interpolation_search([2, 5, 7, 8], 12))
self.assertEqual(None, interpolation_search([2, 5, 7, 8], 0))
self.assertEqual(1, interpolation_search([2, 5, 7, 8], 5))
self.assertEqual(2, interpolation_search([3, 6, 12, 14, 17], 12))
self.assertEqual(1, interpolation_search([3, 6, 12, 14, 17], 6))


def testAllDUpath(self):
self.assertEqual(None, interpolation_search([2, 5, 7, 8], 12))
self.assertEqual(None, interpolation_search([2, 5, 7, 8], 0))
self.assertEqual(1, interpolation_search([2, 5, 7, 8], 5))
self.assertEqual(2, interpolation_search([3, 6, 12, 14, 17], 12))
self.assertEqual(1, interpolation_search([3, 6, 12, 14, 17], 6))
self.assertEqual(3, interpolation_search([5, 7, 11, 15, 19], 15))


if __name__ == '__main__':
import sys

unittest.main()

user_input = raw_input('Enter numbers separated by comma:\n').strip()
collection = [int(item) for item in user_input.split(',')]
Expand Down