title: How do I correct this AssertionError in my unit tests?
body: <p>I'm working on an arithmetic arranger problem.</p>
  <p>The program arranges and returns the problem as shown below in the console output. It is a function that accepts two parameters: a list where each item is an addition or subtraction problem, and an optional second argument that, when true, displays each answer beneath the dashes under each problem.</p>
  <p>To me, it looks like the program is failing 1 out of the 6 tests in the test_module file.</p>
  <p>Here's the console output when I run the program, the error is shown here:</p>
  <pre><code> python main.py
     32      3801      50      123        12
  + 698    -    2    + 50    -  49    + 3600
  -----    ------    ----    -----    ------
    730      3799     100       74      3612
  F.....
  ======================================================================
  FAIL: test_arrangement (test_module.UnitTests)
  ----------------------------------------------------------------------
  Traceback (most recent call last):
    File &quot;/home/runner/boilerplate-arithmetic-formatter-4/test_module.py&quot;, line 10, in test_arrangement
      self.assertEqual(actual, expected, 'Expected different output when calling &quot;arithmetic_arranger()&quot; with [&quot;3 + 855&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;]')
  AssertionError: '    [36 chars]   -    2    + 43    +  49\n-----    ------    ----    -----\n' != '    [36 chars]   -    2    + 43    +  49\n-----    ------    ----    -----'
        3      3801      45      123
    + 855    -    2    + 43    +  49
  - -----    ------    ----    -----
  ?                                 -
  + -----    ------    ----    ----- : Expected different output when calling &quot;arithmetic_arranger()&quot; with [&quot;3 + 855&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;]
  
  ----------------------------------------------------------------------
  Ran 6 tests in 0.002s
  
  FAILED (failures=1)
  </code></pre>
  <p>Here are the contents of my main.py file:</p>
  <pre><code>from arithmetic_arranger import arithmetic_arranger
  from unittest import main
  
  
  print(arithmetic_arranger([&quot;32 + 698&quot;, &quot;3801 - 2&quot;, &quot;50 + 50&quot;, &quot;123 - 49&quot;, &quot;12 + 3600&quot;], True))
  
  
  # Run unit tests automatically
  main(module='test_module', exit=False)
  </code></pre>
  <p>Here are the contents of my arithmetic_arranger file:</p>
  <pre><code>def arithmetic_arranger(problems, results):
    if len(problems) &gt; 5:
      return 'Error: Too many problems.'
    
    top = []
    bottom = []
    dashes = []
    spaces = '    '
    answers = []
  
  # [&quot;32 + 698&quot;, &quot;3801 - 2&quot;, &quot;50 + 50&quot;, &quot;123 - 49&quot;, &quot;12 + 3600&quot;]
  
    for problem in problems:
      first = '  ' + problem.split()[0]
      second = problem.split(' ', 1)[1]
      length_first = len(first)
      length_second = len(second)
      difference_first = length_first - length_second
      difference_second = length_second - length_first
  
      width_first = len(problem.split()[0])
      width_second = len(problem.split()[2])
  
      if width_first &gt; 4 or width_second &gt; 4:
        return &quot;Error: Numbers cannot be more than four digits.&quot;
        
      if second[0] != '+' and second[0] != '-':
        return &quot;Error: Operator must be '+' or '-'.&quot;
      
      if first.lstrip().isdigit() != True or second[2:].isdigit() != True:
        return 'Error: Numbers must only contain digits.'
      
      if difference_first &gt; 0:
        second = second[0] + ' ' * (difference_first + 1) + second[2:]
      elif difference_second &gt; 0:
        first = ' ' * difference_second + first
  
      # Optional condition to display answers under problems:
      if results:
        if second[0] == '+':
          answer = int(first) + int(second[2:])
        else:
          answer = int(first) - int(second[2:])
  
        answer_to_string = str(answer)
        length_result = len(answer_to_string)
        answer_to_string = '  ' + answer_to_string
        length_maximum = max([len(first.lstrip()), len(second[1:].lstrip())])
  
        if length_maximum &gt; length_result:
          answer_to_string = ' ' * (length_maximum - length_result) + answer_to_string
        elif length_maximum &lt; length_result:
          answer_to_string = answer_to_string[1:]
  
        answers.append(answer_to_string)
  
    # Append variables to lists
      top.append(first)
      bottom.append(second)
      dashes.append('-' * len(second))
  
    # Set spacing
      spaced_top = spaces.join(top)
      spaced_bottom = spaces.join(bottom)
      spaced_dashes = spaces.join(dashes)
      spaced_answers = spaces.join(answers)
    
    return spaced_top + '\n' + spaced_bottom + '\n' + spaced_dashes + '\n' + spaced_answers
  </code></pre>
  <p>Here are the contents of my test_module.py file:</p>
  <pre><code>import unittest
  from arithmetic_arranger import arithmetic_arranger
  
  
  # the test case
  class UnitTests(unittest.TestCase):
      def test_arrangement(self):
          actual = arithmetic_arranger([&quot;3 + 855&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;], False)
          expected = &quot;    3      3801      45      123\n+ 855    -    2    + 43    +  49\n-----    ------    ----    -----&quot;
          self.assertEqual(actual, expected, 'Expected different output when calling &quot;arithmetic_arranger()&quot; with [&quot;3 + 855&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;]')
  
          actual = arithmetic_arranger([&quot;11 + 4&quot;, &quot;3801 - 2999&quot;, &quot;1 + 2&quot;, &quot;123 + 49&quot;, &quot;1 - 9380&quot;], False)
          expected = &quot;  11      3801      1      123         1\n+  4    - 2999    + 2    +  49    - 9380\n----    ------    ---    -----    ------&quot;
          self.assertEqual(actual, expected, 'Expected different output when calling &quot;arithmetic_arranger()&quot; with [&quot;11 + 4&quot;, &quot;3801 - 2999&quot;, &quot;1 + 2&quot;, &quot;123 + 49&quot;, &quot;1 - 9380&quot;]')
  
      def test_too_many_problems(self):
          actual = arithmetic_arranger([&quot;44 + 815&quot;, &quot;909 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;, &quot;888 + 40&quot;, &quot;653 + 87&quot;], True)
          expected = &quot;Error: Too many problems.&quot;
          self.assertEqual(actual, expected, 'Expected calling &quot;arithmetic_arranger()&quot; with more than five problems to return &quot;Error: Too many problems.&quot;')
  
      def test_incorrect_operator(self):
          actual = arithmetic_arranger([&quot;3 / 855&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;], True)
          expected = &quot;Error: Operator must be '+' or '-'.&quot;
          self.assertEqual(actual, expected, '''Expected calling &quot;arithmetic_arranger()&quot; with a problem that uses the &quot;/&quot; operator to return &quot;Error: Operator must be '+' or '-'.&quot;''')
          
      def test_too_many_digits(self):
          actual = arithmetic_arranger([&quot;24 + 85215&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;], True)
          expected = &quot;Error: Numbers cannot be more than four digits.&quot;
          self.assertEqual(actual, expected, 'Expected calling &quot;arithmetic_arranger()&quot; with a problem that has a number over 4 digits long to return &quot;Error: Numbers cannot be more than four digits.&quot;')
  
      def test_only_digits(self):
          actual = arithmetic_arranger([&quot;98 + 3g5&quot;, &quot;3801 - 2&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;], True)
          expected = &quot;Error: Numbers must only contain digits.&quot;
          self.assertEqual(actual, expected, 'Expected calling &quot;arithmetic_arranger()&quot; with a problem that contains a letter character in the number to return &quot;Error: Numbers must only contain digits.&quot;')
  
      def test_solutions(self):
          actual = arithmetic_arranger([&quot;32 - 698&quot;, &quot;1 - 3801&quot;, &quot;45 + 43&quot;, &quot;123 + 49&quot;], True)
          expected = &quot;   32         1      45      123\n- 698    - 3801    + 43    +  49\n-----    ------    ----    -----\n -666     -3800      88      172&quot;
          self.assertEqual(actual, expected, 'Expected solutions to be correctly displayed in output when calling &quot;arithmetic_arranger()&quot; with arithmetic problems and a second argument of `True`.')
  
  
  if __name__ == &quot;__main__&quot;:
      unittest.main()
  </code></pre>