def test_majority_element_linear_search_generator_2(self): # generated pseudo-random majority element debug = False count = 0 numberOfTests = 1000 listLength = 20 for loop in range(0,numberOfTests): if debug: print(">>> Generator 2: ", loop, " list length: ", listLength) a = generator2(listLength) expected_result = 1 res = majority_element.majority_element_linear_search(a) count = count + res self.assertEqual(res, expected_result) self.assertEqual(count, numberOfTests)
def test_majority_element_divide_and_conquer_generator_2(self): # # use data generator and compare results between # M.E Linear Search & M.E. divide and conquer # # This generator2 creates random number, but ensure that a M.E. exists # so the expect results should be M.E. found # debug = False count = 0 numberOfGeneratedTests = 1000 listLength = 1000 for loop in range(0,numberOfGeneratedTests): if debug: print(">>> Generator 2: ", loop, " list length: ", listLength) a = generator2(listLength) expected_result = majority_element.majority_element_linear_search(a) res = majority_element.majority_element_divide_and_conquer(a) count = count + res self.assertEqual(res, expected_result) self.assertEqual(count, numberOfGeneratedTests)
def test_majority_element_linear_search_6(self): a = [1,2,3,4,5,8,8,8,8,8] expected_result = 0 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_4(self): a = [1,2,2] expected_result = 1 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_generator_1(self): # M.E. longer a = generator(20) expected_result = 0 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_9(self): # M.E. longer a = [8,1,8,2,8,3,8,4,8,5,8,6,7,7,7,7,7,8,8,8,8,8,8] expected_result = 1 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_9(self): # M.E. alternating reversed a = [8,1,8,2,8,3,8,4,8,5,8,6] expected_result = 1 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_8(self): # M.E. in first half a = [8,8,8,8,8,8,1,2,3,4,5] expected_result = 1 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)
def test_majority_element_linear_search_7(self): # M.E. in second half a = [1,2,3,4,5,8,8,8,8,8,8] expected_result = 1 self.assertEqual(majority_element.majority_element_linear_search(a), expected_result)