From 7362f9fad7657e445ab114c98a6c2c9890f1db16 Mon Sep 17 00:00:00 2001 From: Khanh Dang Date: Mon, 23 May 2022 18:45:30 +0700 Subject: [PATCH] Testing Function interpolation_search() --- algorithms/searches/interpolation_search.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/algorithms/searches/interpolation_search.py b/algorithms/searches/interpolation_search.py index 7b765c4..b7128c1 100644 --- a/algorithms/searches/interpolation_search.py +++ b/algorithms/searches/interpolation_search.py @@ -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(',')]