Scientific Computing With Python - Arithmetir Formatter

I have the same problem, but I can’t find any spacing issues in my output:

================================ FAILURES ================================
_____________ test_template[test_two_problems_arrangement1] ______________

arguments = [['3801 - 2', '123 + 49']]
expected_output = '  3801      123\n-    2    +  49\n------    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n-    2    +  49    \n------    -----    ' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         + -    2    +  49    
E         ?                ++++
E         - ------    -----
E         + ------    -----    
E         ?                ++++

test_module.py:77: AssertionError```
========================== test session starts ===========================
platform linux -- Python 3.8.11, pytest-6.2.4, py-1.10.0, pluggy-0.13.1 -- /nix/store/d281rmpa8y4pbaw8dxmc0wa11kvnhdjr-python3-3.8.11/bin/python
cachedir: .pytest_cache
rootdir: /home/runner/Arithmetic-Formatter
collected 10 items                                                       

test_module.py::test_template[test_two_problems_arrangement1] FAILED [ 10%]
test_module.py::test_template[test_two_problems_arrangement2] FAILED [ 20%]
test_module.py::test_template[test_four_problems_arrangement] FAILED [ 30%]
test_module.py::test_template[test_five_problems_arrangement] FAILED [ 40%]
test_module.py::test_template[test_too_many_problems] PASSED       [ 50%]
test_module.py::test_template[test_incorrect_operator] PASSED      [ 60%]
test_module.py::test_template[test_too_many_digits] PASSED         [ 70%]
test_module.py::test_template[test_only_digits] PASSED             [ 80%]
test_module.py::test_template[test_two_problems_with_solutions] FAILED [ 90%]
test_module.py::test_template[test_five_problems_with_solutions] FAILED [100%]

================================ FAILURES ================================
_____________ test_template[test_two_problems_arrangement1] ______________

arguments = [['3801 - 2', '123 + 49']]
expected_output = '  3801      123\n-    2    +  49\n------    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3801 - 2", "123 + 49"]
E       assert '  3801      123    \n-    2    +  49    \n------    -----    ' == '  3801      123\n-    2    +  49\n------    -----'
E         -   3801      123
E         +   3801      123    
E         ?                ++++
E         - -    2    +  49
E         + -    2    +  49    
E         ?                ++++
E         - ------    -----
E         + ------    -----    
E         ?                ++++

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
  3801      123    
-    2    +  49    
------    -----    
_____________ test_template[test_two_problems_arrangement2] ______________

arguments = [['1 + 2', '1 - 9380']]
expected_output = '  1         1\n+ 2    - 9380\n---    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["1 + 2", "1 - 9380"]
E       assert '  1         1    \n+ 2    - 9380    \n---    ------    ' == '  1         1\n+ 2    - 9380\n---    ------'
E         -   1         1
E         +   1         1    
E         ?              ++++
E         - + 2    - 9380
E         + + 2    - 9380    
E         ?              ++++
E         - ---    ------
E         + ---    ------    
E         ?              ++++

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
  1         1    
+ 2    - 9380    
---    ------    
_____________ test_template[test_four_problems_arrangement] ______________

arguments = [['3 + 855', '3801 - 2', '45 + 43', '123 + 49']]
expected_output = '    3      3801      45      123\n+ 855    -    2    + 43    +  49\n-----    ------    ----    -----'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["3 + 855", "3801 - 2", "45 + 43", "123 + 49"]
E       assert ('    3      3801      45      123    \n'\n '+ 855    -    2    + 43    +  49    \n'\n '-----    ------    ----    -----    ') == ('    3      3801      45      123\n'\n '+ 855    -    2    + 43    +  49\n'\n '-----    ------    ----    -----')
E         -     3      3801      45      123
E         +     3      3801      45      123    
E         ?                                 ++++
E         - + 855    -    2    + 43    +  49
E         + + 855    -    2    + 43    +  49    
E         ?                                 ++++
E         - -----    ------    ----    -----
E         + -----    ------    ----    -----    
E         ?                                 ++++

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
    3      3801      45      123    
+ 855    -    2    + 43    +  49    
-----    ------    ----    -----    
_____________ test_template[test_five_problems_arrangement] ______________

arguments = [['11 + 4', '3801 - 2999', '1 + 2', '123 + 49', '1 - 9380']]
expected_output = '  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------'
fail_message = 'Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected different output when calling "arithmetic_arranger()" with ["11 + 4", "3801 - 2999", "1 + 2", "123 + 49", "1 - 9380"]
E       assert ('  11      3801      1      123         1    \n'\n '+  4    - 2999    + 2    +  49    - 9380    \n'\n '----    ------    ---    -----    ------    ') == ('  11      3801      1      123         1\n'\n '+  4    - 2999    + 2    +  49    - 9380\n'\n '----    ------    ---    -----    ------')
E         -   11      3801      1      123         1
E         +   11      3801      1      123         1    
E         ?                                         ++++
E         - +  4    - 2999    + 2    +  49    - 9380
E         + +  4    - 2999    + 2    +  49    - 9380    
E         ?                                         ++++
E         - ----    ------    ---    -----    ------
E         + ----    ------    ---    -----    ------    
E         ?                                         ++++

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
  11      3801      1      123         1    
+  4    - 2999    + 2    +  49    - 9380    
----    ------    ---    -----    ------    
____________ test_template[test_two_problems_with_solutions] _____________

arguments = [['3 + 855', '988 + 40'], True]
expected_output = '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.
E       assert None == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         +None
E         -'    3      988\n+ 855    +  40\n-----    -----\n  858     1028'

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
    3      988    
+ 855    +  40    
-----    -----    
  858     1028    
____________ test_template[test_five_problems_with_solutions] ____________

arguments = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
expected_output = '   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.
E       assert None == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         +None
E         -'   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'

test_module.py:77: AssertionError
-------------------------- Captured stdout call --------------------------
   32         1      45      123      988    
- 698    - 3801    + 43    +  49    +  40    
-----    ------    ----    -----    -----    
 -666     -3800      88      172     1028    
======================== short test summary info =========================
FAILED test_module.py::test_template[test_two_problems_arrangement1] - ...
FAILED test_module.py::test_template[test_two_problems_arrangement2] - ...
FAILED test_module.py::test_template[test_four_problems_arrangement] - ...
FAILED test_module.py::test_template[test_five_problems_arrangement] - ...
FAILED test_module.py::test_template[test_two_problems_with_solutions]
FAILED test_module.py::test_template[test_five_problems_with_solutions]
====================== 6 failed, 4 passed in 0.25s =======================

This says that you have an extra four spaces at the end of this line.

1 Like

You were right, thank you!

Could you please help me to understand these 2 errors left?

====================== FAILURES ======================
__ test_template[test_two_problems_with_solutions] ___

arguments = [['3 + 855', '988 + 40'], True]
expected_output = '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with ["3 + 855", "988 + 40"] and a second argument of `True`.
E       assert None == '    3      988\n+ 855    +  40\n-----    -----\n  858     1028'
E         +None
E         -'    3      988\n+ 855    +  40\n-----    -----\n  858     1028'

test_module.py:77: AssertionError
---------------- Captured stdout call ----------------
    3      988
+ 855    +  40
-----    -----
  858     1028
__ test_template[test_five_problems_with_solutions] __

arguments = [['32 - 698', '1 - 3801', '45 + 43', '123 + 49', '988 + 40'], True]
expected_output = '   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'
fail_message = 'Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.'

    @pytest.mark.parametrize('arguments,expected_output,fail_message', test_cases)
    def test_template(arguments, expected_output, fail_message):
        actual = arithmetic_arranger(*arguments)
>       assert actual == expected_output, fail_message
E       AssertionError: Expected solutions to be correctly displayed in output when calling "arithmetic_arranger()" with five arithmetic problems and a second argument of `True`.
E       assert None == ('   32         1      45      123      988\n'\n '- 698    - 3801    + 43    +  49    +  40\n'\n '-----    ------    ----    -----    -----\n'\n ' -666     -3800      88      172     1028')
E         +None
E         -'   32         1      45      123      988\n- 698    - 3801    + 43    +  49    +  40\n-----    ------    ----    -----    -----\n -666     -3800      88      172     1028'

test_module.py:77: AssertionError
---------------- Captured stdout call ----------------
   32         1      45      123      988
- 698    - 3801    + 43    +  49    +  40
-----    ------    ----    -----    -----
 -666     -3800      88      172     1028
============== short test summary info ===============
FAILED test_module.py::test_template[test_two_problems_with_solutions]
FAILED test_module.py::test_template[test_five_problems_with_solutions]
============ 2 failed, 8 passed in 0.20s =============```

I could be wrong, but doesn’t +None mean that you aren’t returning anything? I had similar where I had a print displaying the correct output, but i wasn’t returning the output so it failed the tests. But it could be something else.

1 Like

You were right!

Hahaha look what happend, I had an indentation where it shouldn’t be, so the “return” statement weren’t running if the second argument of the function was “True”.

  if res==True:
    arranged_problems=linea1+"\n"+linea2+"\n"+linea3+"\n"+linea4
    print(arranged_problems)
  else:
    arranged_problems=linea1+"\n"+linea2+"\n"+linea3
    print(arranged_problems)

    return arranged_problems

Thank you!!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.