Skip to content

Instantly share code, notes, and snippets.

@dmoney
Created June 23, 2015 02:20
Show Gist options
  • Save dmoney/3b6842bb951f151152d4 to your computer and use it in GitHub Desktop.
Save dmoney/3b6842bb951f151152d4 to your computer and use it in GitHub Desktop.
import unittest
TREE = (1, (2, None, None), (3, (4, None, None), (5, None, None)))
EXPECTED_REVERSED = (1, (3, (5, None, None), (4, None, None)), (2, None, None))
def reversed(tree):
if tree is None:
return None
else:
val, left, right = tree
return (val, reversed(right), reversed(left))
class TestReversed(unittest.TestCase):
def test_reversed(self):
self.assertEqual(reversed(TREE), EXPECTED_REVERSED)
def test_reversed_not_same(self):
self.assertNotEqual(reversed(TREE), TREE)
def test_reversed_reversed(self):
self.assertEqual(reversed(reversed(TREE)), TREE)
def test_reversed_asymmetric(self):
self.assertEqual(reversed((1, None, (2, None, None))),
(1, (2, None, None), None))
if __name__ == '__main__':
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment