title: Automated Testing Reverse String in Python 3
body: <p>I am trying to create a function that can test two different functions. </p>
  
  <p>I am naming my test function test_reverse, to automate testing of strReverseI and strReverseR (see the code for these below)</p>
  
  <p>strReverseI and strReverseR will be arguments to test_reverse.</p>
  
  <p>test_reverse will have one parameter, f, a function (either strReverseR or strReverseI) </p>
  
  <p>test_reverse will call f repeatedly, for a series of test cases, and compare the result returned by either strReverseR or strReverseI to the expected result. 
  test_reverse should report for each test case whether the actual result matches the expected result, e.g., </p>
  
  <pre><code>Checking strReverseR('testing123')...its value '321gnitset' is correct!
  Checking strReverseI('a')... Error: has wrong value 'a', expected 'b'. 
  </code></pre>
  
  <p>Function test_reverse should return None. </p>
  
  <p>Test cases and expected results should be stored in a tuple of tuples defined in test_reverse. test_reverse should include at least the following tests: </p>
  
  <pre><code>(
  ('', ''),
  ('a', 'a'),
  ('aaaa', 'aaaa'),
  ('abc', 'cba'),
  ('hello', 'olleh'), ('racecar', 'racecar'), 
  ('testing123', '321gnitset'), ('#CIS 210', '012 SIC#'), ('a', 'b') 
  )
  </code></pre>
  
  <p>Here is the code I have so far… strReverseR and strReverseI work perfectly, I am not just needing to figure out test_reverse:</p>
  
  <pre><code>import doctest
  
  def strReverseI(s):
  '''
  (str) -&gt; (str)
  Returns the reverse of the string input. This function finds 
  the reverse string via an interative implementation.
  
  
  NOTE TO MYSELF: I could also have chosen to do a while loop being
  
  (s[n:] != ''):
  
  This is using a while loop and as long as the slice of the string 
  is not an empty string,
  it will continue to run the loop. As soon as the slice becomes an 
  empty string,
  it will stop the loop and you will have the reverse string.
  
  Examples:
  
  &gt;&gt;&gt; strReverseI('hello, world')
  'dlrow ,olleh'
  &gt;&gt;&gt; strReverseR('')
  ''
  &gt;&gt;&gt; strReverseR('a')
  'a'
  '''
      result = ""
      n = 0
      for i in range(1, len(s) + 1):
          result += s[len(s) - i]
      return result
  
  def strReverseR(s):
  '''
  (str) -&gt; (str)
  Returns the reverse of the string input. This function finds 
  the reverse string via recuersion. The base case would be an empty 
  string so the function would still return out an empty string and 
  not have any errors.
  After we can confirm the string is not empty,
   we return the last element of the string, followed by
  the string without that last element/character. Since this 
  continues to call upon itself, it will continue to cut the string
  of the "last" element to grow the reverse string. 
  
  Examples:
  
  &gt;&gt;&gt; strReverseR('hello, world')
  'dlrow ,olleh'
  &gt;&gt;&gt; strReverseR('')
  ''
  &gt;&gt;&gt; strReverseR('a')
  'a'
  ''' 
      if s == '':
          return s
      result = s[-1] + strReverseR(s[0:-1])
      return result
  
  def test_reverse(f):
  '''
  function -&gt;
  
  '''
      if f('hi') == 'ih':
          print("success")
      else:
          print("failed")
      return None
  </code></pre>
  
  <p><strong>Note</strong> Yes, this is something I am working on for a school hw assignment. I am not expecting anyone to write it for me. I am just really confused on this last part and would love some insight on how to move forward. Any examples, and explanations would be so helpful. Thanks.</p>
  
  <p><strong>Update</strong> I have been working on this more and this is along the lines of what I think I need to do, if you could help a bit with this that would be great!               </p>
  
  <pre><code>def test_reverse(f):
  '''
  function -&gt;
  
  '''
  
  list = (
          ('', ''),
          ('a', 'a'),
          ('aaaa', 'aaaa'),
          ('abc', 'cba'),
          ('hello', 'olleh'), ('racecar', 'racecar'),
          ('testing123', '321gnitset'), ('#CIS 210', '012 SIC#'), ('a', 'b')
          )
  
  for x in list:
  
      #f(i[0]) = [1])
  
      if f(i[0] == [1]):
  
          print("Checking", f,"... its value", "is correct!")
  
      else:
  
          print("Checking", f, "... Error: has wrong value")
  
  return None
  </code></pre>
  
  <p>def main():
      '''calls string reverse test func 2 times'''
      test_reverse(p5.strReverseR)
      print()
      test_reverse(p5.strReverseI)
      return None</p>