curds: Add a way to get a nodes nth child
Signed-off-by: Anna Schumaker <Anna@NoWheyCreamery.com>
This commit is contained in:
parent
35e02b5732
commit
7aa2244f97
|
@ -45,3 +45,8 @@ class PlaylistNode:
|
|||
|
||||
def n_children(self):
|
||||
return len(self.children)
|
||||
|
||||
def nth_child(self, n):
|
||||
if n < len(self.children):
|
||||
return self.children[n]
|
||||
return None
|
||||
|
|
|
@ -93,6 +93,23 @@ class TestPlaylistNode(unittest.TestCase):
|
|||
self.assertEqual(a.next, b)
|
||||
self.assertEqual(b.prev, a)
|
||||
|
||||
def test_node_nth_child(self):
|
||||
root = node.PlaylistNode()
|
||||
a = node.PlaylistNode("a")
|
||||
b = node.PlaylistNode("b")
|
||||
c = node.PlaylistNode("c")
|
||||
|
||||
root.append_child(a)
|
||||
root.append_child(b)
|
||||
a.append_child(c)
|
||||
|
||||
self.assertEqual( root.nth_child(0), a)
|
||||
self.assertEqual( root.nth_child(1), b)
|
||||
self.assertIsNone(root.nth_child(2))
|
||||
|
||||
self.assertEqual( a.nth_child(0), c)
|
||||
self.assertIsNone(a.nth_child(1))
|
||||
|
||||
def test_node_parent(self):
|
||||
root = node.PlaylistNode()
|
||||
a = node.PlaylistNode("a")
|
||||
|
|
Loading…
Reference in New Issue