diff --git a/.travis.yml b/.travis.yml index 9ac4963..d59aab4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,8 @@ script: - awesome_bot README.md --allow-dupe --allow-redirect - python Algorithm_tests/sorting_tests/test_sorting.py - python Algorithm_tests/graphtheory_tests/bellman_ford_test.py - - python Algorithm_tests/search_tests/test_binarysearch.py + - python Algorithm_tests/other_tests/test_binarysearch.py - python Algorithm_tests/math_tests/intersection_test.py - python Algorithm_tests/math_tests/union_test.py - python Algorithm_tests/cryptology_tests/ceasar_test.py + - python Algorithm_tests/other_tests/test_intervalscheduling.py diff --git a/Algorithm_tests/other_tests/test_intervalscheduling.py b/Algorithm_tests/other_tests/test_intervalscheduling.py index c2cf0a4..a23d7e3 100644 --- a/Algorithm_tests/other_tests/test_intervalscheduling.py +++ b/Algorithm_tests/other_tests/test_intervalscheduling.py @@ -4,97 +4,60 @@ # For importing from different folders # OBS: This is supposed to be done with automated testing, hence relative to folder we want to import from -#sys.path.append('Algorithms/other') +sys.path.append('Algorithms/other') # If run from local: -sys.path.append('../../Algorithms/other') +#sys.path.append('../../Algorithms/other') -from binarysearch import binarysearch_iterative, binarysearch_recursive +from interval_scheduling import interval_scheduling -class test_binarysearch(unittest.TestCase): +class test_intervalscheduling(unittest.TestCase): def setUp(self): # test cases we wish to run - self.L1 = [1, 3, 5, 8, 10, 12] - self.L1_target = 5 - self.L1_correct = True, 2 + self.R1 = [(0, 5), (3, 6),(5, 10)] + self.R1_correct = [(0,5), (5,10)] - self.L2 = [1, 3, 5, 8, 10, 12] - self.L2_target = 6 - self.L2_correct = False, None + self.R2 = [] + self.R2_correct = [] - self.L3 = [1,1,1,1,1,1,1,1] - self.L3_target = 1 - self.L3_correct = True, (0+len(self.L3)-1)//2 + self.R3 = [(0, 3), (3,6), (6,9), (9, 10)] + self.R3_correct = [(0, 3), (3,6), (6,9), (9, 10)] - self.L4 = [1, 3, 6, 11, 16, 21, 25, 27] - self.L4_target = 27 - self.L4_correct = True, len(self.L4)-1 + self.R4 = [(1, 3), (0, 2), (1, 4), (2, 5)] + self.R4_correct = [(0,2), (2,5)] - self.L5 = [1, 3, 6, 11, 16, 21, 27] - self.L5_target = 1 - self.L5_correct = True, 0 + self.R5 = [(0,3)] + self.R5_correct = [(0,3)] - self.L6 = [] - self.L6_target = 10 - self.L6_correct = False, None - self.L7 = [11,12,15,19,23,41,173,298] - self.L7_target = 12 - self.L7_correct = True, 1 + def test_intervalscheduling_basic(self): + O = [] + O = interval_scheduling(self.R1, O) + self.assertEqual(O, self.R1_correct) + def test_intervalscheduling_empty(self): + O = [] + O = interval_scheduling(self.R2, O) + self.assertEqual(O, self.R2_correct) - def test_binarysearch_basic(self): - L1_result_iterative = binarysearch_iterative(self.L1, self.L1_target) - L1_result_recursive = binarysearch_recursive(self.L1, self.L1_target, 0, len(self.L1)-1) + def test_intervalscheduling_take_all(self): + O = [] + O = interval_scheduling(self.R3, O) + self.assertEqual(O, self.R3_correct) - self.assertEqual(L1_result_iterative, self.L1_correct) - self.assertEqual(L1_result_recursive, self.L1_correct) + def test_intervalscheduling_unsorted(self): + O = [] + O = interval_scheduling(self.R4, O) + self.assertEqual(O, self.R4_correct) - def test_binarysearch_nonexistant(self): - L2_result_iterative = binarysearch_iterative(self.L2, self.L2_target) - L2_result_recursive = binarysearch_recursive(self.L2, self.L2_target, 0, len(self.L1)-1) - - self.assertEqual(L2_result_iterative, self.L2_correct) - self.assertEqual(L2_result_recursive, self.L2_correct) - - def test_binarysearch_identical(self): - L3_result_iterative = binarysearch_iterative(self.L3, self.L3_target) - L3_result_recursive = binarysearch_recursive(self.L3, self.L3_target, 0, len(self.L3) - 1) - - self.assertEqual(L3_result_iterative, self.L3_correct) - self.assertEqual(L3_result_recursive, self.L3_correct) - - def test_binarysearch_lastvalue(self): - L4_result_iterative = binarysearch_iterative(self.L4, self.L4_target) - L4_result_recursive = binarysearch_recursive(self.L4, self.L4_target, 0, len(self.L4) - 1) - - self.assertEqual(L4_result_iterative, self.L4_correct) - self.assertEqual(L4_result_recursive, self.L4_correct) - - def test_binarysearch_firstvalue(self): - L5_result_iterative = binarysearch_iterative(self.L5, self.L5_target) - L5_result_recursive = binarysearch_recursive(self.L5, self.L5_target, 0, len(self.L5) - 1) - - self.assertEqual(L5_result_iterative, self.L5_correct) - self.assertEqual(L5_result_recursive, self.L5_correct) - - def test_binarysearch_empty(self): - L6_result_iterative = binarysearch_iterative(self.L6, self.L6_target) - L6_result_recursive = binarysearch_recursive(self.L6, self.L6_target, 0, len(self.L6) - 1) - - self.assertEqual(L6_result_iterative, self.L6_correct) - self.assertEqual(L6_result_recursive, self.L6_correct) - - def test_binarysearch_standard(self): - L7_result_iterative = binarysearch_iterative(self.L7, self.L7_target) - L7_result_recursive = binarysearch_recursive(self.L7, self.L7_target, 0, len(self.L7) - 1) - - self.assertEqual(L7_result_iterative, self.L7_correct) - self.assertEqual(L7_result_recursive, self.L7_correct) + def test_intervalscheduling_one_element(self): + O = [] + O = interval_scheduling(self.R5, O) + self.assertEqual(O, self.R5_correct) if __name__ == '__main__': - print("Running sorting tests:") + print("Running Interval Scheduling tests:") unittest.main() \ No newline at end of file diff --git a/Algorithms/other/__pycache__/interval_scheduling.cpython-38.pyc b/Algorithms/other/__pycache__/interval_scheduling.cpython-38.pyc new file mode 100644 index 0000000..de7c31b Binary files /dev/null and b/Algorithms/other/__pycache__/interval_scheduling.cpython-38.pyc differ diff --git a/Algorithms/other/interval_scheduling.py b/Algorithms/other/interval_scheduling.py index f8b9852..67d6381 100644 --- a/Algorithms/other/interval_scheduling.py +++ b/Algorithms/other/interval_scheduling.py @@ -20,21 +20,21 @@ def interval_scheduling(R, O): return O -def interval_scheduling_complicated_version(R, O): - while R: # keep going while R still has elements - (si, fi) = R[0] - O.append((si,fi)) - idx = 0 - - while idx < len(R): - (sj, fj) = R[idx] - - if fi > sj: - R.remove(R[idx]) - idx -= 1 - - idx += 1 - return O +# def interval_scheduling_complicated_version(R, O): +# while R: # keep going while R still has elements +# (si, fi) = R[0] +# O.append((si,fi)) +# idx = 0 +# +# while idx < len(R): +# (sj, fj) = R[idx] +# +# if fi > sj: +# R.remove(R[idx]) +# idx -= 1 +# +# idx += 1 +# return O if __name__ == '__main__': # run small example