def manual_test(to_test): test_type = 1 test_cases = [ {'in': [], 'out': (0, [])}, {'in': [1], 'out': (0, [1])}, {'in': [2, 3], 'out': (0, [2, 3])}, {'in': [3, 2], 'out': (1, [2, 3])}, {'in': [3, 3], 'out': (0, [3, 3])}, {'in': [3, 6, 1, 0], 'out': (5, [0, 1, 3, 6])}, # 2+2+1 {'in': [6, 7, 8, 9, 10], 'out': (0, [6, 7, 8, 9, 10])}, # sorted {'in': [5, 4, 3, 2, 1], 'out': (10, [1, 2, 3, 4, 5])}, # 4+3+2+1 = (5-1)*(5)/2 = 10 {'in': [3, 4, 10, 12, 12], 'out': (0, [3, 4, 10, 12, 12])}, # 0+0+0+0 {'in': [10, 9, 1, 12, 10], 'out': (4, [1, 9, 10, 10, 12])}, # 2+1+0+1 {'in': [-12, -12, -12, -12, -12], 'out': (0, [-12, -12, -12, -12, -12])}, {'in': [-12, -2, 12, 1, -100], 'out': (5, [-100, -12, -2, 1, 12])}, # 1+1+2+1 ] for case in test_cases: input_arg = case['in'] output = to_test(input_arg) expected_output = case['out'] if output != expected_output: msg = err_msg( test_type, to_test.__name__, input_arg, output, expected_output ) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def stress_test(to_test, test_against): test_type = 2 total_tests = 100 min_n, max_n = 1, 200 min_val, max_val = -10, 10 for _ in range(total_tests): n = random.randint(min_n, max_n) matrix1 = [] for _ in range(n): li = [] for _ in range(n): li.append(random.randint(min_val, max_val)) matrix1.append(li) matrix2 = [] for _ in range(n): li = [] for _ in range(n): li.append(random.randint(min_val, max_val)) matrix2.append(li) input_arg = (matrix1, matrix2) output = to_test(*input_arg) expected_output = test_against(*input_arg) if output != expected_output: msg = err_msg(test_type, to_test.__name__, input_arg, output, expected_output) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def manual_test(to_test): test_type = 1 test_cases = [{ 'in': (0, 0), 'out': 0 }, { 'in': (0, 1), 'out': 0 }, { 'in': [1, 0], 'out': 0 }, { 'in': [-1, 0], 'out': 0 }, { 'in': [1, 1], 'out': 1 }, { 'in': [-221, 1], 'out': -221 }, { 'in': [1, 3321], 'out': 3321 }, { 'in': [9, 11], 'out': 99 }, { 'in': [-12, 50], 'out': -600 }, { 'in': [100, -2], 'out': -200 }, { 'in': [2, 3], 'out': 6 }, { 'in': [5, 5], 'out': 25 }] for case in test_cases: input_arg = case['in'] output = to_test(*input_arg) expected_output = case['out'] if output != expected_output: msg = err_msg(test_type, to_test.__name__, input_arg, output, expected_output) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def stress_test(to_test, test_against): test_type = 2 min_num, max_num = -1000, 1000 for num1 in range(min_num, max_num + 1): for num2 in range(min_num, max_num + 1): input_arg = (num1, num2) output = to_test(*input_arg) expected_output = test_against(*input_arg) if output != expected_output: msg = err_msg(test_type, to_test.__name__, input_arg, output, expected_output) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def manual_test(to_test): test_type = 1 test_cases = [ { 'in': ([[1]], [[1]]), 'out': ([[1]]) }, { 'in': ([[1, 2], [2, 1]], [[3, 0], [-1, 2]]), 'out': ([[1, 4], [5, 2]]) }, { 'in': ([[1, 2, 3], [-1, -3, 0], [2, 3, 5]], [[3, 2, 1], [1, 6, -1], [1, 3, 5]]), 'out': ([[8, 23, 14], [-6, -20, 2], [14, 37, 24]]) }, { 'in': ([[1, 2, 3, 4], [4, 2, 0, 10], [11, 0, 12, 6], [2, 7, 9, 1]], [[9, 12, 0, 11], [8, 5, 10, 5], [2, 2, 9, 5], [8, 1, 9, 0]]), 'out': ([[63, 32, 83, 36], [132, 68, 110, 54], [171, 162, 162, 181], [100, 78, 160, 102]]) }, { 'in': ([[1, 2, 3, 4, 5], [5, 4, 2, 0, 10], [11, 2, 12, 1, 6], [2, 1, 10, 1, 1], [2, 1, 10, 1, 1]], [[9, 2, -1, -11, 5], [8, -5, -10, 5, 0], [2, -2, -9, 5, 10], [8, -1, 9, 0, 1], [8, -1, 9, 0, 1]]), 'out': ([[103, -23, 33, 14, 44], [161, -24, 27, -25, 55], [195, -19, -76, -51, 182], [62, -23, -84, 33, 112], [62, -23, -84, 33, 112]]) }, ] for case in test_cases: input_arg = case['in'] output = to_test(*input_arg) expected_output = case['out'] if output != expected_output: msg = err_msg(test_type, to_test.__name__, input_arg, output, expected_output) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def stress_test(to_test, test_against): test_type = 2 total_tests = 1000 min_len, max_len = 0, 1000 min_num, max_num = -10000, 10000 test_type = 2 for _ in range(total_tests): arr_len = random.randint(min_len, max_len) arr = [random.randint(min_num, max_num) for i in range(arr_len)] output = to_test(arr) expected_output = test_against(arr) if output != expected_output: msg = err_msg( test_type, to_test.__name__, arr, output, expected_output ) raise NameError(msg) return pass_msg(test_type, to_test.__name__)
def manual_test(to_test): test_cases = [{ 'in': [], 'out': [] }, { 'in': [4], 'out': [4] }, { 'in': [-1, 1], 'out': [-1, 1] }, { 'in': [1, -1], 'out': [-1, 1] }, { 'in': [2, 2, 2], 'out': [2, 2, 2] }, { 'in': [1, 5, 3], 'out': [1, 3, 5] }, { 'in': [3, 1, 7, 2], 'out': [1, 2, 3, 7] }, { 'in': [9, 2, 1, 32, 10, 12], 'out': [1, 2, 9, 10, 12, 32] }, { 'in': [0, -1, -4, 2, -2, -1, 4], 'out': [-4, -2, -1, -1, 0, 2, 4] }] test_type = 1 for case in test_cases: output = to_test(case['in']) if output != case['out']: msg = err_msg(test_type, to_test.__name__, case['in'], output, case['out']) raise NameError(msg) return pass_msg(test_type, to_test.__name__)