def testConstructor(self): n = prioritize.Node() assert None == n.item assert set() == n.parents assert [] == n.children n = prioritize.Node('a') assert 'a' == n.item assert set() == n.parents assert [] == n.children
def testAddParent(self): c = prioritize.Node('c') n = c.addParent('p') assert isinstance(n,prioritize.Node) assert n in c.parents assert c in n.children d = prioritize.Node('d') n = c.addParent(d) assert d == n assert d in c.parents assert c in d.children assert 2 == len(c.parents) n = c.addParent(d) assert d == n assert 2 == len(c.parents)
def testAddChild(self): p = prioritize.Node('a') n = p.addChild('c') assert isinstance(n,prioritize.Node) assert n in p.children assert p in n.parents d = prioritize.Node('d') n = p.addChild(d) assert d == n assert d in p.children assert p in d.parents assert 2 == len(p.children) n = p.addChild(d) assert d == n assert 2 == len(p.children) assert 1 == len(d.parents)
def testFindChild(self): a = prioritize.Node('a') b = prioritize.Node('b') c = prioritize.Node('c') d = prioritize.Node('d') e = prioritize.Node('e') f = prioritize.Node('f') top = prioritize.Node('0') top.addChild(a) a.addChild(b) a.addChild(c) b.addChild(d) c.addChild(d) b.addChild(e) d.addChild(f) assert a == top.findChild('a') assert a == a.findChild('a') assert b == top.findChild('b') assert c == top.findChild('c') assert d == top.findChild('d') assert e == top.findChild('e') assert f == top.findChild('f') assert None == top.findChild(1) assert None == f.findChild('a') assert None == b.findChild('a')
def testStr(self): n = prioritize.Node() assert "<node: set([])<- None ->[]>" == str(n) n.addChild('a') assert "<node: set([])<- None ->['a']>" == str(n) n.addParent('a') assert "<node: set(['a'])<- None ->['a']>" == str(n) n.addChild('b') assert "<node: set(['a'])<- None ->['a', 'b']>" == str(n) for p in ('b',3,'B','c', 1,'C','d',2,'D',): n.addParent(p) pdisp = set((x.item for x in n.parents)) assert str(n).startswith("<node: %s<-"%pdisp),"Expected '%s', got '%s'"%("<node: %s<-"%pdisp,str(n)) n = prioritize.Node() for c in (9,'A','a','b',3,'B','c', 1,'C','d',2,'D',): n.addChild(p) cdisp = [x.item for x in n.children] assert str(n).endswith("%s>"%cdisp)
def testFindChild(): a = prioritize.Node('a') b = prioritize.Node('b') c = prioritize.Node('c') d = prioritize.Node('d') e = prioritize.Node('e') a.addChild(b) a.addChild(c) b.addChild(d) c.addChild(d) a.addChild(e) assert None == a.findChild('nope') assert None == b.findChild('e') assert None == b.findChild('a') assert a == a.findChild('a') assert b == a.findChild('b') assert c == a.findChild('c') assert d == a.findChild('d') assert e == a.findChild('e') c.addChild(e) e.addChild(a) assert a == c.findChild('a') assert None == b.findChild('a')