"""
This file contains a number of function headers which have not yet been
implemented.  Try writing *recursive* implementations of these functions.
"""

def numbers_line(n):
  """
  Creates a string which places all of the numbers from 1 up to n in a line
  with spaces between them.  For instance, numbers_line(3) should return
    "1 2 3"
  while numbers_line(1) returns
    "1"
  """
  raise NotImplementedError()

def odd_sum(n):
  """
  Sums the odd numbers from 1 up to n.  For instance, numbers_line(5) gives
  5+3+1=9.  This function assumes that it is given an odd number.
  """
  raise NotImplementedError()

def sum_list(lst):
  """
  Sums all of the numbers in a list.  For instance, sum_list([1,4,5]) gives
  1+4+5=10.  (Hint: you can use list slicing to separate one element of the
  list from the other elements.)
  """
  raise NotImplementedError()

def sum_of_digits(n):
  """
  Sum all of the digits in the number n.  For instance, sum_of_digits(415)
  returns 4+1+5=10.  sum_of_digits(7) returns 7.
  """
  raise NotImplementedError()

def dosido(s):
  """
  Swap each pair of characters in a string.  For instance, dosido("thimble")
  returns "htmilbe".
  """
  raise NotImplementedError()

def test_fn(fn, arg, expect):
  fn_name = fn.__name__
  try:
    result = fn(arg)
    if result != expect:
      print "Calling function %s with argument %s expected %s but got %s" % (fn_name, arg, expect, result)
  except NotImplementedError:
    print "Function %s is not implemented." % fn_name

def tests():
  test_fn(numbers_line, 3, "1 2 3")
  test_fn(numbers_line, 1, "1")
  test_fn(numbers_line, 6, "1 2 3 4 5 6")
  test_fn(odd_sum, 1, 1)
  test_fn(odd_sum, 5, 9)
  test_fn(odd_sum, 9, 25)
  test_fn(sum_list, [1,2,3], 6)
  test_fn(sum_list, [5,1,9], 15)
  test_fn(sum_list, [], 0)
  test_fn(sum_digits, 415, 10)
  test_fn(sum_digits, 1769, 23)
  test_fn(sum_digits, 0, 0)
  test_fn(dosido, "thimble", "htmilbe")
  test_fn(dosido, "a", "a")
  test_fn(dosido, "an", "na")
  test_fn(dosido, "cat", "act")
  test_fn(dosido, "computer science", "ocpmtures icneec")

if __name__ == '__main__':
  tests()

