def test_bubble_sort(self): collection = utils.random_list(100, 1, 1000) result = sorting.bubble_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.reversed_sorted_list(1, 100) result = sorting.bubble_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted) collection = utils.sorted_list(1, 10000) result = sorting.bubble_sort(collection) is_sorted = sorting.isSorted(result) self.assertEqual(True, is_sorted)
def test_bubble_sort(self): bubble_sort(self.unsorted_array) self.assertEqual(self.unsorted_array, self.sorted_array)
def test_bubble_with_array_of_none_type_objects(self): arr_to_sort = [None, None, None, None, None] with self.assertRaises(TypeError) as context: self.assertRaises(TypeError, bubble_sort(arr_to_sort)) exception_message = str(context.exception) self.assertEqual('TypeError', exception_message)
def test_bubble_with_one_element_array(self): arr_to_sort = [1] sorted_array = bubble_sort(arr_to_sort) expected_result = [1] self.assertEqual(expected_result, sorted_array)
def test_bubble_with_equally_filled_array(self): arr_to_sort = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] sorted_array = bubble_sort(arr_to_sort) expected_result = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] self.assertEqual(expected_result, sorted_array)
def test_bubble_sort_m3_m2_m1_asc(): assert sorting.bubble_sort([-3, -2, -1], "asc") == [-3, -2, -1]
def test_bubble_sort_0_1_m1_desc(): assert sorting.bubble_sort([0, 1, -1], "desc") == [1, 0, -1]
def test_bubble_sort(self): S.bubble_sort(self.lst) self.assertEqual(self.lst, [1, 2, 3, 4, 5])
def test_bubble_sort(): numbers = random_list(max_numbers) sorting.bubble_sort(numbers) assert is_sorted(numbers)
#f.readline #f.tell #f.seek # open file is read binary / write binary os.chdir("/var/log") with open("syslog") as f: print cwd + "/test.txt" with open(cwd + "/test.txt", "w") as g: for line in f: print f.tell() print(line) g.write(line) with open(cwd + "/test.txt", "rw") as f: print f.read() os.chdir(cwd) if __name__ == '__main__': ll = [0, 2, 4, 6, 5, 3, 1, 8, 10, 9, 7] ll1 = [0, 2, 4, 6, 5, 14, 1, 8, 10, 9, 7] print isPostTraversalOfBST(ll) print isPostTraversalOfBST(ll1) temp = [-5, -86, 69, 73, -11, 17, 1, -74, 34, 3] temp = sorting.bubble_sort(temp) print "Sorted array" + str(temp) print " Case 1: sq sorted array : " + str(sortedSquareArray(temp)) temp = [5, -86, 69, 73, 11, 17, 1, 74, 34, 3] print " Case 2: sq un sorted array : " + str(sortedSquareArray(temp)) # parse_syslog()
def test_bubble_sort(self): for arr in random_arrays: self.assertEquals(bubble_sort(arr[0]), arr[1])
def test_bubble_sort(): data = populate_random_data() sorting.bubble_sort(data) assert sorted(data) == data
def test_bubble_sort(self): self.assertEqual(bubble_sort([]), []) self.assertEqual(bubble_sort([1, 1, 1, 1, 1]), [1, 1, 1, 1, 1]) self.assertEqual(bubble_sort([1, 3, 2, 11, 5]), [1, 2, 3, 5, 11]) self.assertEqual(bubble_sort([5, -1, 0, 2, 3]), [-1, 0, 2, 3, 5]) self.assertEqual(bubble_sort([3]), [3])
def test_bubble_sort(self): u_list = [8, 2, 6, 4, 5] s_list = [2, 4, 5, 6, 8] self.assertEqual(bubble_sort(u_list)['u_list'], s_list)
def test_bubble_sort(self): """Tests that test list is correctly sorted.""" self.assertEqual(sorted(self.test_list), bubble_sort(self.test_list))
def test_case_reverse(self): unsorted = [8, 7, 6, 5, 4, 3, 2, 1] sorted = [1, 2, 3, 4, 5, 6, 7, 8] result = sorting.bubble_sort(unsorted) self.assertEqual(result, sorted)
def test_case_same(self): unsorted = [1, 1, 1, 1] sorted = [1, 1, 1, 1] result = sorting.bubble_sort(unsorted) self.assertEqual(result, sorted)
def test_bubble_sort(self): data = [5, 7, 9, 1, 0, 6] assert bubble_sort(data) == [0, 1, 5, 6, 7, 9]
def test_bubble_sort(): out_list = sorting.bubble_sort(random_dll_list(max_number)) return is_sorted(out_list)
def test_bubble_sort(self): sorting.bubble_sort(self.list_a) sorting.bubble_sort(self.list_b) sorting.bubble_sort(self.list_c) sorting.bubble_sort(self.list_d) sorting.bubble_sort(self.list_one) sorting.bubble_sort(self.list_two) self.assertEqual(self.list_a, self.list_sorted) self.assertEqual(self.list_b, self.list_sorted) self.assertEqual(self.list_c, self.list_sorted) self.assertEqual(self.list_d, self.list_sorted) self.assertEqual(self.list_one, [1]) self.assertEqual(self.list_two, [-10, -5])
def test_bubble_sort_0_asc(): assert sorting.bubble_sort([0], "asc") == [0]
from recursion import sum_array, factorial, reverse, fibonacci from sorting import bubble_sort, merge_sort, quick_sort print(sum_array([1, 2, 3])) print(fibonacci(10)) print(factorial(5)) print(reverse("abcdef")) print(bubble_sort([5, 4, 1, 2, 4, 9])) print(merge_sort([1, 3, 2, 5, 4, 7, 6])) print(quick_sort([3, 2, 4, 5, 7, 6]))
def test_bubble_sort_m3_m2_m1_desc(): assert sorting.bubble_sort([-3, -2, -1], "desc") == [-1, -2, -3]
# open file is read binary / write binary os.chdir("/var/log") with open("syslog") as f: print cwd + "/test.txt" with open(cwd + "/test.txt","w") as g: for line in f: print f.tell() print(line) g.write(line) with open(cwd + "/test.txt","rw") as f: print f.read() os.chdir(cwd) if __name__ == '__main__': ll = [0, 2, 4, 6, 5, 3, 1, 8, 10, 9, 7 ] ll1 = [0, 2, 4, 6, 5, 14, 1, 8, 10, 9, 7 ] print isPostTraversalOfBST(ll) print isPostTraversalOfBST(ll1) temp = [-5,-86,69,73,-11,17,1,-74,34,3] temp = sorting.bubble_sort(temp) print "Sorted array" + str(temp) print " Case 1: sq sorted array : " + str(sortedSquareArray(temp)) temp = [5,-86,69,73,11,17,1,74,34,3] print " Case 2: sq un sorted array : " + str(sortedSquareArray(temp)) # parse_syslog()
def test_bubble_with_reverse_sorted_array(self): arr_to_sort = [10, 9, 8, 7, 6, 5, 4, 3, 2, 1] sorted_array = bubble_sort(arr_to_sort) expected_result = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] self.assertEqual(expected_result, sorted_array)
def test_bubble_sort(): numbers = random_list(max_numbers) lista1 = sorted(numbers) lista2 = sorting.bubble_sort(numbers) assert lista1 == lista2
def test_bubble_with_wrong_non_type_object_in_array(self): arr_to_sort = [1, 5, None, 235, 2, 51, 5, 1, 25, 2] with self.assertRaises(TypeError) as context: self.assertRaises(TypeError, bubble_sort(arr_to_sort)) exception_message = str(context.exception) self.assertEqual('TypeError', exception_message)
def test_bubble_sort(input_arr, expected_arr): sorting.bubble_sort(input_arr) assert input_arr == expected_arr
def test_bubble_sort_with_random_array(self): arr_to_sort = [1, 5, 1, 235, 2, 51, 5, 1, 25, 2] sorted_array = bubble_sort(arr_to_sort) expected_result = [1, 1, 1, 2, 2, 5, 5, 25, 51, 235] self.assertEqual(expected_result, sorted_array)
def test_bubble_sort(self): for ls in self._ls: assert sorting.bubble_sort(list(ls)) == sorted(ls)
def test_case_empty(self): unsorted = [] sorted = [] result = sorting.bubble_sort(unsorted) self.assertEqual(result, sorted)
def test_bubble_sort_1_2_3_asc(): assert sorting.bubble_sort([1, 2, 3], "asc") == [1, 2, 3]
def test_case_dupes(self): unsorted = [1, 3, 3, 5, 7, 2, 4, 6, 6, 8] sorted = [1, 2, 3, 3, 4, 5, 6, 6, 7, 8] result = sorting.bubble_sort(unsorted) self.assertEqual(result, sorted)
def test_bubble_sort_1_2_3_desc(): assert sorting.bubble_sort([1, 2, 3], "desc") == [3, 2, 1]
def test_bubble_sort(): numbers = random_list(max_numbers) sorting.bubble_sort(numbers) assert is_sorted(numbers)
def test_bubble_sort_3_2_1_asc(): assert sorting.bubble_sort([3, 2, 1], "asc") == [1, 2, 3]
def test_bubble_sort_3_2_1_desc(): assert sorting.bubble_sort([3, 2, 1], "desc") == [3, 2, 1]
from recursion import sum_array, factorial, reverse, fibonacci from sorting import bubble_sort, merge_sort, quick_sort assert sum_array([1,2,3]) == 6 assert factorial(5) == 120 assert reverse('hello world') == 'dlrow olleh' assert fibonacci(3) = 1 assert bubble_sort([1,3,5,2,4]) == [1, 2, 3, 4, 5] assert merge_sort([3,0,6,33,9]) == [0, 3, 6, 9, 33] assert quick_sort([3,1,7,54,2]) == [1, 2, 3, 7, 54]