Advertisement
Guest User

Untitled

a guest
May 25th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.64 KB | None | 0 0
  1. import unittest
  2.  
  3.  
  4. def append_to(element, to=[]):
  5.     """
  6.    Append an element to a list.
  7.    If not list provided, create a new list containing only the element.
  8.  
  9.    :param element: the thing to append
  10.    :param to: the list to append it to
  11.    :return: the list with the appended thing
  12.    """
  13.     to.append(element)
  14.     return to
  15.  
  16.  
  17. class TestAppendTo(unittest.TestCase):
  18.     def test_append_to(self):
  19.         r = append_to('a')
  20.         self.assertListEqual(r, ['a'])
  21.  
  22.     def test_append_to_two(self):
  23.         r = append_to('b')
  24.         append_to('c', r)
  25.         self.assertListEqual(r, ['b', 'c'])
  26.  
  27.  
  28. unittest.main(exit=False)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement