├── arithmetic_arranger.py ├── README.md ├── main.py ├── pyproject.toml └── test_module.py /arithmetic_arranger.py: -------------------------------------------------------------------------------- 1 | def arithmetic_arranger(problems): 2 | 3 | 4 | return arranged_problems -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Arithmetic Formatter 2 | 3 | This is the boilerplate for the Arithmetic Formatter project. Instructions for building your project can be found at https://www.freecodecamp.org/learn/scientific-computing-with-python/scientific-computing-with-python-projects/arithmetic-formatter 4 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | # This entrypoint file to be used in development. Start by reading README.md 2 | from pytest import main 3 | 4 | from arithmetic_arranger import arithmetic_arranger 5 | 6 | 7 | print(arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])) 8 | 9 | 10 | # Run unit tests automatically 11 | main(['-vv']) 12 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "fcc-arithmetic-formatter" 3 | version = "0.1.0" 4 | description = "" 5 | authors = ["Your Name "] 6 | 7 | [tool.poetry.dependencies] 8 | python = "^3.8" 9 | pytest = "^6.2.4" 10 | 11 | [tool.poetry.dev-dependencies] 12 | 13 | [build-system] 14 | requires = ["poetry-core>=1.0.0"] 15 | build-backend = "poetry.core.masonry.api" 16 | -------------------------------------------------------------------------------- /test_module.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from arithmetic_arranger import arithmetic_arranger 4 | 5 | test_cases = [ 6 | pytest.param( 7 | [['3801 - 2', '123 + 49']], 8 | ' 3801 123\n' 9 | '- 2 + 49\n' 10 | '------ -----', 11 | 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]', 12 | id='test_two_problems_arrangement1'), 13 | pytest.param( 14 | [['1 + 2', '1 - 9380']], 15 | ' 1 1\n' 16 | '+ 2 - 9380\n' 17 | '--- ------', 18 | 'Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]', 19 | id='test_two_problems_arrangement2'), 20 | pytest.param( 21 | [['3 + 855', '3801 - 2', '45 + 43', '123 + 49']], 22 | ' 3 3801 45 123\n' 23 | '+ 855 - 2 + 43 + 49\n' 24 | '----- ------ ---- -----', 25 | 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]', 26 | id='test_four_problems_arrangement'), 27 | pytest.param( 28 | [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']], 29 | ' 11 3801 1 123 1\n' 30 | '+ 4 - 2999 + 2 + 49 - 9380\n' 31 | '---- ------ --- ----- ------', 32 | 'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]', 33 | id='test_five_problems_arrangement'), 34 | pytest.param( 35 | [['44 + 815', '909 - 2', '45 + 43', '123 + 49', 36 | '888 + 40', '653 + 87']], 37 | 'Error: Too many problems.', 38 | 'Expected calling "arithmetic_arranger()" with more than five problems to return "Error: Too many problems."', 39 | id='test_too_many_problems'), 40 | pytest.param( 41 | [['3 / 855', '3801 - 2', '45 + 43', '123 + 49']], 42 | "Error: Operator must be '+' or '-'.", 43 | '''Expected calling "arithmetic_arranger()" with a problem that uses the "/" operator to return "Error: Operator must be '+' or '-'."''', 44 | id='test_incorrect_operator'), 45 | pytest.param( 46 | [['24 + 85215', '3801 - 2', '45 + 43', '123 + 49']], 47 | 'Error: Numbers cannot be more than four digits.', 48 | 'Expected calling "arithmetic_arranger()" with a problem that has a number over 4 digits long to return "Error: Numbers cannot be more than four digits."', 49 | id='test_too_many_digits'), 50 | pytest.param( 51 | [['98 + 3g5', '3801 - 2', '45 + 43', '123 + 49']], 52 | 'Error: Numbers must only contain digits.', 53 | 'Expected calling "arithmetic_arranger()" with a problem that contains a letter character in the number to return "Error: Numbers must only contain digits."', 54 | id='test_only_digits'), 55 | pytest.param( 56 | [['3 + 855', '988 + 40'], True], 57 | ' 3 988\n' 58 | '+ 855 + 40\n' 59 | '----- -----\n' 60 | ' 858 1028', 61 | 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.', 62 | id='test_two_problems_with_solutions'), 63 | pytest.param( 64 | [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True], 65 | ' 32 1 45 123 988\n' 66 | '- 698 - 3801 + 43 + 49 + 40\n' 67 | '----- ------ ---- ----- -----\n' 68 | ' -666 -3800 88 172 1028', 69 | 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.', 70 | id='test_five_problems_with_solutions'), 71 | ] 72 | 73 | 74 | @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases) 75 | def test_template(arguments, expected_output, fail_message): 76 | actual = arithmetic_arranger(*arguments) 77 | assert actual == expected_output, fail_message 78 | --------------------------------------------------------------------------------