Beispiel #1
0
    def get_graph_a():
        n1 = GNode("a")
        n2 = GNode("b")
        n3 = GNode("c")
        n4 = GNode("d")
        n5 = GNode("e")

        n1.add_child_s([n3, n4, n5])
        n2.add_child_s([n3, n4, n5])
        n3.add_child_s([n1, n2, n4, n5])
        n4.add_child_s([n1, n2, n3, n5])
        n5.add_child_s([n1, n2, n3, n4])

        return n1, {n1, n2, n3, n4, n5}
    def generate_mission_graph():
        a = Start()
        b = GNode([], [], "b")
        c = Key(name="c")
        d = GNode([], [], "d")
        e = End()
        f = Lock(name="f")
        g = GNode([], [], "g")

        a.add_child_s(b)
        a.add_child_s(c)
        a.add_child_s(d)
        b.add_child_s(e)
        c.add_child_s(f)
        c.add_child_s(g)
        f.add_key_s(c)
        c.add_lock_s(f)

        return a, {a, b, c, d, e, f, g}
Beispiel #3
0
    def test_mutable_default_argument_bug(self):
        gnode1 = GNode("")
        gnode2 = GNode("")
        bad_node0 = GNode("BadNode0")
        gnode1.add_child_s(bad_node0)
        self.assertEqual(len(gnode2.child_s), 0)

        start1 = Start()
        start2 = Start()
        bad_node1 = GNode("BadNode1")
        start1.add_child_s(bad_node1)
        self.assertEqual(len(start2.child_s), 0)

        end1 = End()
        end2 = End()
        bad_node2 = GNode("BadNode2")
        end1.add_parent_s(bad_node2)
        self.assertEqual(len(end2.parent_s), 0)

        key1 = Key()
        key2 = Key()
        bad_node3 = GNode("BadNode3")
        key1.add_child_s(bad_node3)
        bad_node4 = GNode("BadNode4")
        key1.add_parent_s(bad_node4)
        self.assertEqual(len(key2.child_s), 0)
        self.assertEqual(len(key2.parent_s), 0)

        lock1 = Lock()
        lock2 = Lock()
        bad_node5 = GNode("BadNode5")
        lock1.add_child_s(bad_node5)
        bad_node6 = GNode("BadNode6")
        lock1.add_parent_s(bad_node6)
        self.assertEqual(len(lock2.child_s), 0)
        self.assertEqual(len(lock2.parent_s), 0)
Beispiel #4
0
    def get_man_graph():
        a = Start()
        b = GNode("b")
        c = GNode("c")
        d = GNode("d")
        e = GNode("e")
        f = End()
        g = GNode("g")
        h = GNode("h")
        i = GNode("i")

        a.add_child_s([b, c, d])
        b.add_child_s(e)
        c.add_child_s([f, g, h, i])
        h.add_child_s(i)

        return a, {a, b, c, d, e, f, g, h, i}
Beispiel #5
0
    def get_graph_b():
        n1 = GNode("a")
        n2 = GNode("b")
        n3 = GNode("c")
        n4 = GNode("d")
        n5 = GNode("e")
        n6 = GNode("f")
        n7 = GNode("g")
        n8 = GNode("h")
        n9 = GNode("i")
        n10 = GNode("j")

        n1.add_child_s([n2, n3])
        n2.add_child_s(n4)
        n3.add_child_s([n4, n5])
        n5.add_child_s(n6)
        n6.add_child_s(n7)
        n7.add_child_s([n8, n9])
        n8.add_child_s(n10)
        n9.add_child_s(n10)

        return n1, {n1, n2, n3, n4, n5, n6, n7, n8, n9, n10}
Beispiel #6
0
    def get_triangle_graph():
        a = GNode("a")
        b = GNode("b")
        c = GNode("c")
        d = GNode("d")
        a.add_child_s(b)
        b.add_child_s(c)
        c.add_child_s(a)
        a.add_child_s(d)
        b.add_child_s(d)
        c.add_child_s(d)

        return a, {a, b, c, d}
Beispiel #7
0
    def get_house_graph():
        a = GNode("a")
        b = GNode("b")
        c = GNode("c")
        d = GNode("d")
        e = GNode("e")
        a.add_child_s(b)
        b.add_child_s(c)
        c.add_child_s(d)
        d.add_child_s(a)
        c.add_child_s(e)
        e.add_child_s(a)
        e.add_child_s(d)

        return a, {a, b, c, d, e}
Beispiel #8
0
    def test_find_all_nodes_topological_sort(self):
        top_sort = "topological-sort"

        n0 = GNode("0")
        n1 = GNode("1")
        n2 = GNode("2")
        n3 = GNode("3")
        n4 = GNode("4")
        n5 = GNode("5")
        n5.add_child_s([n0, n2, n4])
        n2.add_child_s(n3)
        n3.add_child_s(n1)
        n4.add_child_s([n0, n1])
        nodes = Node.find_all_nodes(n5, method=top_sort)
        self.assertTrue(
            self.assert_ordered(nodes, [(n5, [n4, n3, n2, n1, n0]),
                                        (n4, [n0, n1]), (n2, [n3, n1]),
                                        (n3, [n1]), (n0, []), (n1, [])]))

        n0 = GNode("0")
        n1 = GNode("1")
        n2 = GNode("2")
        n3 = GNode("3")
        n4 = GNode("4")
        n5 = GNode("5")
        n0.add_child_s([n1, n2, n3])
        n1.add_child_s(n4)
        n2.add_child_s(n5)
        n3.add_child_s(n1)
        n4.add_child_s(n2)
        nodes = Node.find_all_nodes(n0, method=top_sort)
        self.assertTrue(
            self.assert_ordered(nodes, [(n0, [n1, n2, n3, n4, n5]),
                                        (n1, [n4, n2, n5]), (n2, [n5]),
                                        (n3, [n1, n4, n2, n5]), (n4, [n2, n5]),
                                        (n5, [])]))