''' test framework for string to nums beginner challenge Copy this, using the raw view (or download) to an editor of your choice and insert your function(s) at the top of the code ensuring the function you want to test takes one string argument and returns a list Edit the last line, the call to the test function test_funcs() and place the name of each function, without its trailing (), in the call to test_funcs, with commas between each function name if testing more than one function. ''' def test_funcs(*funcs): import traceback tests = [('1-5,7,9,10-13', [1, 2, 3, 4, 5, 7, 9, 10, 11, 12, 13]), ('5, 10-6, 4-8,3', [3, 4, 5, 6, 7, 8, 9, 10]), ('1023,675,43, 23400-23395, 5-12', [5,6,7,8,9,10,11,12,43,675,1023,23395,23396,23397,23398,23399,23400]), ('1, 3 -5, 6-, -, 7, -9 , 16 - 20,23', [1, 3, 4, 5, 7, 16, 17, 18, 19, 20, 23]), ('2, 4, num, ;5, a-b', [2, 4]) ] for func in funcs: print(f'\n\nTesting function: {func.__name__}\n') print('-----------') for test, assertion in tests: print(f'Testing: {test}') try: result = func(test) except ValueError as errmsg: print(errmsg) except Exception as e: print(f'ERROR: {traceback.format_exc()}') else: try: assert sorted(set(result)) == assertion except AssertionError: print( f'*** ERROR -> for {test}\n\texpected {assertion},\n\treceived {result}') else: print(result, end='') if result != sorted(set(result)): print(' ** result not ordered/unique') else: print() print('-----------') if __name__ == "__main__": def test_funcs(*funcs): import traceback tests = [('1-5,7,9,10-13', [1, 2, 3, 4, 5, 7, 9, 10, 11, 12, 13]), ('5, 10-6, 4-8,3', [3, 4, 5, 6, 7, 8, 9, 10]), ('1023,675,43, 23400-23395, 5-12', [5,6,7,8,9,10,11,12,43,675,1023,23395,23396,23397,23398,23399,23400]), ('1, 3 -5, 6-, -, 7, -9 , 16 - 20,23', [1, 3, 4, 5, 7, 16, 17, 18, 19, 20, 23]), ('2, 4, num, ;5, a-b', [2, 4]) ] for func in funcs: print(f'\n\nTesting function: {func.__name__}\n') print('-----------') for test, assertion in tests: print(f'Testing: {test}') try: result = func(test) except ValueError as errmsg: print(errmsg) except Exception as e: print(f'ERROR: {traceback.format_exc()}') else: try: assert sorted(set(result)) == assertion except AssertionError: print( f'*** ERROR -> for {test}\n\texpected {assertion},\n\treceived {result}') else: print(result, end='') if result != sorted(set(result)): print(' ** result not ordered/unique') else: print() print('-----------') if __name__ == "__main__": from seq import safe_adv_range test_funcs(safe_adv_range)