Skip to content

Instantly share code, notes, and snippets.

@eungju
Created September 7, 2009 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eungju/182615 to your computer and use it in GitHub Desktop.
Save eungju/182615 to your computer and use it in GitHub Desktop.
import unittest
def has_branches(tree):
return len(tree) >= 1
def depth(tree):
if has_branches(tree):
return 1 + max(map(depth, tree))
else:
return 1
class DepthTest(unittest.TestCase):
def testHasBraches(self):
tree = []
self.assertFalse(has_branches(tree))
def testNoChildren(self):
tree = []
self.assertEquals(1, depth(tree))
def testAChild(self):
tree = [[]]
self.assertEquals(2, depth(tree))
def testChildren(self):
tree = [[],[[]]]
self.assertEquals(3, depth(tree))
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment