def test_link_doubleLinkList_head(self): dll = list.DoubleLinkList() dll.add_head(1) dll.add_head(2) dll.add_head(3) actual = timer.run_timed_result(str, dll) expected = "3,2,1" self.assertEqual(actual, expected, "test_link_dllHead.1") actual = timer.run_timed_result(dll.peak_head) expected = 3 self.assertEqual(actual, expected, "test_link_dllHead.2") actual = actual = timer.run_timed_result(dll.pop_head) expected = 3 self.assertEqual(actual, expected, "test_link_dllHead.3") actual = timer.run_timed_result(str, dll) expected = "2,1" self.assertEqual(actual, expected, "test_link_dllHead.4")
def test_link_doubleLinkList_tail(self): dll = list.DoubleLinkList() dll.add_tail(1) dll.add_tail(2) dll.add_tail(3) actual = timer.run_timed_result(str, dll) expected = "1,2,3" self.assertEqual(actual, expected, "test_link_dllTail.1") actual = timer.run_timed_result(dll.peek_tail) expected = 3 self.assertEqual(actual, expected, "test_link_dllTail.2") actual = actual = timer.run_timed_result(dll.pop_tail) expected = 3 self.assertEqual(actual, expected, "test_link_dllTail.3") actual = timer.run_timed_result(str, dll) expected = "1,2" self.assertEqual(actual, expected, "test_link_dllTail.4")
def test_get_fib_recursive(self): actual = timer.run_timed_result(fib.get_fib_recursive, 1) self.assertEqual(actual, 1, 'get_fib_recursive(1)') actual = timer.run_timed_result(fib.get_fib_recursive, 2) self.assertEqual(actual, 1, 'get_fib_recursive(2)') actual = timer.run_timed_result(fib.get_fib_recursive, 3) self.assertEqual(actual, 2, 'get_fib_recursive(3)') actual = timer.run_timed_result(fib.get_fib_recursive, 4) self.assertEqual(actual, 3, 'get_fib_recursive(4)') actual = timer.run_timed_result(fib.get_fib_recursive, 5) self.assertEqual(actual, 5, 'get_fib_recursive(5)') actual = timer.run_timed_result(fib.get_fib_recursive, 16) self.assertEqual(actual, 987, 'get_fib_recursive(16)') actual = timer.run_timed_result(fib.get_fib_recursive, 24) self.assertEqual(actual, 46368, 'get_fib_recursive(24)')
def test_get_fib_var2(self): actual = timer.run_timed_result(fib.get_fib_var2, 1) self.assertEqual(actual, 1, 'get_fib_var2(1)') actual = timer.run_timed_result(fib.get_fib_var2, 2) self.assertEqual(actual, 1, 'get_fib_var2(2)') actual = timer.run_timed_result(fib.get_fib_var2, 3) self.assertEqual(actual, 2, 'get_fib_var2(3)') actual = timer.run_timed_result(fib.get_fib_var2, 4) self.assertEqual(actual, 3, 'get_fib_var2(4)') actual = timer.run_timed_result(fib.get_fib_var2, 5) self.assertEqual(actual, 5, 'get_fib_var2(5)') actual = timer.run_timed_result(fib.get_fib_var2, 16) self.assertEqual(actual, 987, 'get_fib_var2(16)') actual = timer.run_timed_result(fib.get_fib_var2, 24) self.assertEqual(actual, 46368, 'get_fib_var2(24)')
def test_get_fib_array(self): actual = timer.run_timed_result(fib.get_fib_array, 1) self.assertEqual(actual, 1, 'get_fib_array(1)') actual = timer.run_timed_result(fib.get_fib_array, 2) self.assertEqual(actual, 1, 'get_fib_array(2)') actual = timer.run_timed_result(fib.get_fib_array, 3) self.assertEqual(actual, 2, 'get_fib_array(3)') actual = timer.run_timed_result(fib.get_fib_array, 4) self.assertEqual(actual, 3, 'get_fib_array(4)') actual = timer.run_timed_result(fib.get_fib_array, 5) self.assertEqual(actual, 5, 'get_fib_array(5)') actual = timer.run_timed_result(fib.get_fib_array, 16) self.assertEqual(actual, 987, 'get_fib_array(16)') actual = timer.run_timed_result(fib.get_fib_array, 24) self.assertEqual(actual, 46368, 'get_fib_array(24)')
def test_python_sort(self): actual = timer.run_timed_result(sort.python_sort, unOrderedList.copy()) expected = orderedList self.assertEqual(actual, expected, 'python_sort')
def execute(): cmd = args.CommandHandler() if cmd.is_command("convert_from_base_10"): timer.run_timed_result(base.convert_from_base_10, cmd.arg(2, "27"), int(cmd.arg(3, "2"))) if cmd.is_command("convert_to_base_10"): timer.run_timed_result(base.convert_to_base_10, cmd.arg(2, "11011"), int(cmd.arg(3, "2"))) if cmd.is_command("get_fib_recursive"): timer.run_timed_result(fib.get_fib_recursive, int(cmd.arg(2, "16"))) if cmd.is_command("get_fib_array"): timer.run_timed_result(fib.get_fib_array, int(cmd.arg(2, "16"))) if cmd.is_command("get_fib_vars"): timer.run_timed_result(fib.get_fib_vars, int(cmd.arg(2, "16"))) if cmd.is_command("get_fib_var2"): timer.run_timed_result(fib.get_fib_var2, int(cmd.arg(2, "16"))) if cmd.is_command("get_factors"): timer.run_timed_result(fact.get_factors, int(cmd.arg(2, "121"))) if cmd.is_command("get_factorial"): timer.run_timed_result(fact.get_factorial, int(cmd.arg(2, "10"))) if cmd.is_command("is_factorial"): timer.run_timed_result(fact.is_factorial, int(cmd.arg(2, "87178291200"))) if cmd.is_command("is_prime"): timer.run_timed_result(prime.is_prime, int(cmd.arg(2, "997"))) if cmd.is_command("get_primes"): timer.run_timed_result(prime.get_primes, int(cmd.arg(2, "900")), int(cmd.arg(3, "999")), bool(cmd.arg(4, False))) if cmd.is_command("isPrime"): p = prime.Prime() timer.run_timed_result(p.compute_primes, int(cmd.arg(2, "997")), bool(cmd.arg(4, True))) timer.run_timed_result(p.is_prime, int(cmd.arg(2, "997")), bool(cmd.arg(3, True))) if cmd.is_command("getPrimes"): p = prime.Prime() timer.run_timed_result(p.compute_primes, int(cmd.arg(3, "999")), bool(cmd.arg(4, True))) timer.run_timed_result(p.get_primes, int(cmd.arg(2, "900")), int(cmd.arg(3, "999")), bool(cmd.arg(4, True))) if cmd.is_command("binary_search"): timer.run_timed_result(search.binary_search, cmd.arg(2, orderedList).split(","), cmd.arg(3, "10")) if cmd.is_command("bubble_sort"): timer.run_timed_result(sort.print_bubble_sort, cmd.arg(2, unOrderedList).split(",")) if cmd.is_command("merge_sort"): timer.run_timed_result(sort.merge_sort, cmd.arg(2, unOrderedList).split(",")) if cmd.is_command("python_sort"): timer.run_timed_result(sort.python_sort, cmd.arg(2, unOrderedList).split(",")) if not cmd.is_handled(): help_text = cmd.get_help( "---- CS Algorithms in Python, MIT, (c) 2019, JTankersley ----", "run <function> [<value>]", "./run.sh get_factors 40302") print(f"{help_text}")
def test_binary_search(self): actual = timer.run_timed_result(search.binary_search, orderedList, 15) expected = 10 self.assertEqual(actual, expected, 'binary_search')
def test_is_factorial(self): actual = timer.run_timed_result(fact.is_factorial, 87178291200) expected = True self.assertEqual(actual, expected, "is_factorial")
def test_get_factorial(self): actual = timer.run_timed_result(fact.get_factorial, 10) expected = 362880 self.assertEqual(actual, expected, "get_factorial")
def test_get_factors(self): actual = timer.run_timed_result(fact.get_factors, 121) expected = [1, 11] self.assertEqual(actual, expected, "get_factors")
def test_run_timed_result(self): actual = timer.run_timed_result(wait_time, 1) expected = 1 self.assertEqual(actual, expected, 'run_timed_result')