Ejemplo n.º 1
0
class TestAdding(unittest.TestCase):
    def setUp(self):
        self._list = names
        self.chunk_size = 5
        self.graph = TreeGraph()
        node_chunks = chunks(self.chunk_size, self._list)
        last = None
        for depth, node_list in enumerate(node_chunks):
            for count, node in enumerate(node_list):
                parent = last[count] if last else Node
                self.graph.add_node(node, depth, parent=parent)
            last = node_list

    def test_init(self):
        assert sum([len(i) for i in self.graph.nodes]) == len(self._list)
        assert len([len(i) for i in self.graph.nodes]) == self.chunk_size
        assert self.graph.to_dict()["Sophia"] == {
            'Hannah': {'Elizabeth': {'Alexis': {'Lauren': None}}}}
Ejemplo n.º 2
0
class TestAdding2(unittest.TestCase):
    def setUp(self):
        self.graph = TreeGraph()
        self.nodes = names

    def test_add(self):
        root = self.nodes.pop(0)
        self.graph.add_node(root, 0)
        depth = 1
        parent = root
        for count, i in enumerate(self.nodes):
            self.graph.add_node(i, depth, parent=parent)
            if (count + 1) % 10 == 0:
                depth += 1
                parent = i

        _dict = self.graph.to_dict()
        _keys = _dict["Sophia"]["Emily"]["Hannah"]["Brooklyn"].keys()
        assert len(_keys) == 10
Ejemplo n.º 3
0
 def setUp(self):
     self._list = names
     self.chunk_size = 5
     self.graph = TreeGraph()
     node_chunks = chunks(self.chunk_size, self._list)
     last = None
     for depth, node_list in enumerate(node_chunks):
         for count, node in enumerate(node_list):
             parent = last[count] if last else Node
             self.graph.add_node(node, depth, parent=parent)
         last = node_list
Ejemplo n.º 4
0
    def setUp(self):
        self.graph = TreeGraph()
        self.graph.add_node("Bob", 0)
        self.graph.add_node("Alice", 0)

        self.graph.add_node("Tom", 1, parents=["Bob", "Alice"])
        self.graph.add_node("Alex", 1, parents=["Bob", "Alice"])

        for i in ("Sophia", "Emma", "Olivia", "Isabella"):
            self.graph.add_node(i, 2, parent="Tom")

        for i in ("Lillian", "Evelyn", "Elizabeth"):
            self.graph.add_node(i, 2, parent="Alex")
Ejemplo n.º 5
0
class TestReadable(unittest.TestCase):
    def setUp(self):
        self.graph = TreeGraph()
        self.graph.add_node("Bob", 0)
        self.graph.add_node("Alice", 0)

        self.graph.add_node("Tom", 1, parents=["Bob", "Alice"])
        self.graph.add_node("Alex", 1, parents=["Bob", "Alice"])

        for i in ("Sophia", "Emma", "Olivia", "Isabella"):
            self.graph.add_node(i, 2, parent="Tom")

        for i in ("Lillian", "Evelyn", "Elizabeth"):
            self.graph.add_node(i, 2, parent="Alex")

    def test_add(self):
        _dict = self.graph.to_dict()
        assert "Bob" in _dict.keys()
        assert "Alice" in _dict.keys()
        assert _dict["Bob"].keys() == _dict["Alice"].keys()
Ejemplo n.º 6
0
 def setUp(self):
     self.graph = TreeGraph()
     self.nodes = names