def test_x010_H0Tree_lot_of_nodes_just_a_node(self): """The graph contains lot of nodes at the same phy: results a H0Tree with just one node for each connected component""" h = H() g = G() nn = [g.add_node() for _ in xrange(3)] for i in xrange(len(nn) - 1): nn[i].connect(nn[i + 1]) hh = [h.add_node()] self.assertTrue(h.same(compute_H0Tree(g))) for i in xrange(len(nn) - 1): for j in xrange(0, len(nn), 2): nn[i].connect(nn[j]) self.assertTrue(h.same(compute_H0Tree(g))) mm = [g.add_node() for _ in xrange(5)] for i in xrange(len(mm) - 1): mm[i].connect(mm[i + 1]) hh += [h.add_node()] self.assertTrue(h.same(compute_H0Tree(g))) """Now we build another island at 1 and connect it to the two connected components""" ss = [g.add_node(1) for _ in xrange(4)] for i in xrange(len(ss) - 1): ss[i].connect(ss[i + 1]) nn[0].connect(ss[1]) mm[2].connect(ss[3]) hh[0].parent = hh[1].parent = h.add_node(1) self.assertTrue(h.same(compute_H0Tree(g)))
def test_0000_base_graph(self): g = G() h = H() self.assertTrue(h.same(compute_H0Tree(g))) g.add_node() h.add_node() self.assertTrue(h.same(compute_H0Tree(g)))
def test_0010_H0Tree_roots_collaps(self): """It is the "V" case and some variations of "reverse V" """ h = H() g = G() N = [g.add_node(0), g.add_node(1), g.add_node(1)] N[0].connect(N[1]) N[0].connect(N[2]) h.add_node(0).parent = h.add_node(1) self.assertTrue(h.same(compute_H0Tree(g))) h = H() g = G() N = [ g.add_node(0), g.add_node(0.5), g.add_node(-.1), g.add_node(0.5), g.add_node(1), g.add_node(1) ] N[0].connect(N[1]) N[2].connect(N[3]) N[1].connect(N[4]) N[3].connect(N[5]) N[4].connect(N[5]) h.add_node(0).parent = h.add_node(-.1).parent = h.add_node(1) dump_H0(h) hh = compute_H0Tree(g) dump_H0(hh) self.assertTrue(h.same(hh))
def test_0000_base(self): self.assertIsNone(compute_H0Tree(None)) self.assertRaises(ValueError, compute_H0Tree, "pippo") self.assertRaises(ValueError, compute_H0Tree, 1) self.assertRaises(ValueError, compute_H0Tree, []) self.assertRaises(ValueError, compute_H0Tree, {}) self.assertIsNotNone(compute_H0Tree(G()))
def test_0010_H0Tree_graph(self): g = H() h = H() for x in [g, h]: r = x.add_node(0) n = x.add_node(-2) n.parent = x.add_node(-0.8) n.parent.parent = r x.add_node(-1).parent = x.add_node(-1.2).parent = r self.assertTrue(h.same(compute_H0Tree(g))) g.add_node(1) self.assertFalse(h.same(compute_H0Tree(g))) h.add_node(1) self.assertTrue(h.same(compute_H0Tree(g)))
def test_x005_H0Tree_node_self_connected(self): """The graph contains a node connected to itself: results a H0Tree with just one node""" h = H() g = G() n = g.add_node() n.connect(n) h.add_node() self.assertTrue(h.same(compute_H0Tree(g)))
def test_0000_H0Tree_compute_more_connected(self): x = H() r = x.add_node(0) n = x.add_node(-2) n.parent = x.add_node(-0.8) n.parent.parent = r x.add_node(-1).parent = x.add_node(-1.2).parent = r x.add_node(1) self.assertIsNotNone(compute_H0Tree(x))
def test_0000_H0Tree_more_connected(self): g = H() g.add_node(0) g.add_node(1) g.add_node(1) self.assertTrue(g.same(compute_H0Tree(g)))