Created
December 2, 2023 03:30
-
-
Save JeremyMorgan/cc1eb0e258cb9bfeed3efc4a0c203993 to your computer and use it in GitHub Desktop.
Test
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
import unittest | |
""" | |
This is a function to extract numbers from the string. | |
It is implemented in my main script that reads the entire input file and runs | |
this function against each line. | |
""" | |
from [YOURSCRIPT] import extract_numbers | |
class TestExtract(unittest.TestCase): | |
def test_extract(self): | |
""" | |
Test that it will extract numbers from the string | |
""" | |
test_cases = [ | |
{'input': '1abc2', 'expected_output': '12'}, | |
{'input': 'pqr3stu8vwx', 'expected_output': '38'}, | |
{'input': 'a1b2c3d4e5f', 'expected_output': '15'}, | |
{'input': 'treb7uchet', 'expected_output': '77'}, | |
{'input': 'two1nine', 'expected_output': '29'}, | |
{'input': 'eightwothree', 'expected_output': '83'}, | |
{'input': 'abcone2threexyz', 'expected_output': '13'}, | |
{'input': 'xtwone3four', 'expected_output': '24'}, | |
{'input': '4nineeightseven2', 'expected_output': '42'}, | |
{'input': 'zoneight234', 'expected_output': '14'}, | |
{'input': '7pqrstsixteen', 'expected_output': '76'},, | |
] | |
for test_case in test_cases: | |
result = extract_numbers(test_case['input']) | |
print(result) | |
self.assertEqual(result, test_case['expected_output']) | |
if __name__ == '__main__': | |
unittest.main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment