Created
October 27, 2017 03:29
-
-
Save the-vampiire/9e10be12dafaaa36eeea48ee3ca2b313 to your computer and use it in GitHub Desktop.
My first unit testing program
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Write your own unit tests and testing environment | |
| def unit_test(function_to_test, test_input, expected_output): | |
| function_output = function_to_test(test_input) | |
| try: | |
| assert function_output == expected_output | |
| print(unit_test_response(True, test_input, function_output, expected_output)) | |
| except AssertionError: | |
| print(unit_test_response(False, test_input, function_output, expected_output)) | |
| def unit_test_response(correct, test_input, function_output, expected_output): | |
| score = "Correct" if correct else "Incorrect" | |
| return "{0}\nInput: {1}\nExpected Output: {2}\nFunction Output: {3}\n".format(score, test_input, function_output, expected_output) | |
| def run_unit_tests(test_list, function_to_test): | |
| for test_tuple in test_list: | |
| test_input, expected_output = test_tuple | |
| unit_test(function_to_test, test_input, expected_output) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment