예제 #1
0
    def test_one_node_twice(self):
        dag = Dag()

        # filename_1_1
        #   filename_2_1
        #      filename_1_1
        #         filename_3_1

        filename_1_1 = DagNode("filename_1_1")
        filename_2_1 = DagNode("filename_2_1")
        filename_3_1 = DagNode("filename_3_1")

        dag.add(1, "filename_1_1")
        dag.add(2, "filename_2_1")
        dag.add(3, "filename_1_1")
        dag.add(4, "filename_3_1")

        self.assertEqual(
            dag.get("filename_1_1").getChildren(),
            set([filename_2_1, filename_3_1]))
        self.assertEqual(
            dag.get("filename_1_1").getParents(), set([dag.getRoot()]))

        self.assertEqual(dag.get("filename_2_1").getChildren(), set())
        self.assertEqual(
            dag.get("filename_2_1").getParents(), set([filename_1_1]))

        self.assertEqual(dag.get("filename_3_1").getChildren(), set())
        self.assertEqual(
            dag.get("filename_3_1").getParents(), set([filename_1_1]))
예제 #2
0
    def test_addChild(self):
        node1 = DagNode(11)
        node2 = DagNode(22)

        node1.addChild(node2)
        self.assertTrue(node2 in node1.getChildren())

        node2.addChild(node1)
        self.assertTrue(node1 in node2.getChildren())
예제 #3
0
    def test_addParent(self):
        node1 = DagNode(11)
        node2 = DagNode(22)

        node1.addParent(node2)
        self.assertTrue(node2 in node1.getParents())

        node2.addParent(node1)
        self.assertTrue(node1 in node2.getParents())
예제 #4
0
    def test_equal(self):
        a11 = DagNode(11)
        b11 = DagNode(11)

        a22 = DagNode(22)
        b22 = DagNode(22)

        self.assertTrue(a11 == b11)
        self.assertTrue(a22 == b22)

        self.assertFalse(a11 == a22)
        self.assertFalse(b11 == b22)
예제 #5
0
    def test_addParent( self ):
        node1 = DagNode( 11 )
        node2 = DagNode( 22 )

        node1.addParent( node2 )
        self.assertTrue( node2 in node1.getParents() )

        node2.addParent( node1 )
        self.assertTrue( node1 in node2.getParents() )
예제 #6
0
    def test_addChild( self ):
        node1 = DagNode( 11 )
        node2 = DagNode( 22 )

        node1.addChild( node2 )
        self.assertTrue( node2 in node1.getChildren() )

        node2.addChild( node1 )
        self.assertTrue( node1 in node2.getChildren() )
예제 #7
0
    def test_add_3(self):
        dag = Dag()

        # filename_1_1
        #   filename_2_1
        #     filename_3_1
        #   filename_2_2
        #     filename_3_1

        filename_1_1 = DagNode("filename_1_1")
        filename_2_1 = DagNode("filename_2_1")
        filename_3_1 = DagNode("filename_3_1")
        filename_2_2 = DagNode("filename_2_2")

        dag.add(1, "filename_1_1")
        dag.add(2, "filename_2_1")
        dag.add(3, "filename_3_1")
        dag.add(2, "filename_2_2")
        dag.add(3, "filename_3_1")

        self.assertEqual(dag.getRoot().getChildren(), set([filename_1_1]))

        self.assertEqual(
            dag.get("filename_1_1").getChildren(),
            set([filename_2_1, filename_2_2]))
        self.assertEqual(
            dag.get("filename_1_1").getParents(), set([dag.getRoot()]))

        self.assertEqual(
            dag.get("filename_2_1").getChildren(), set([
                filename_3_1,
            ]))
        self.assertEqual(
            dag.get("filename_2_1").getParents(), set([filename_1_1]))

        self.assertEqual(
            dag.get("filename_2_2").getChildren(), set([
                filename_3_1,
            ]))
        self.assertEqual(
            dag.get("filename_2_2").getParents(), set([filename_1_1]))

        self.assertEqual(dag.get("filename_3_1").getChildren(), set())
        self.assertEqual(
            dag.get("filename_3_1").getParents(),
            set([filename_2_1, filename_2_2]))
예제 #8
0
    def test_add_2(self):
        dag = Dag()

        # filename_1_1
        #   filename_2_1
        #     filename_leaf
        # filename_leaf

        filename_1_1 = DagNode("filename_1_1")
        filename_2_1 = DagNode("filename_2_1")
        filename_leaf = DagNode("filename_leaf")

        dag.add(1, "filename_1_1")
        dag.add(2, "filename_2_1")
        dag.add(3, "filename_leaf")
        dag.add(1, "filename_leaf")

        self.assertEqual(dag.getRoot().getChildren(),
                         set([filename_1_1, filename_leaf]))

        self.assertEqual(
            dag.get("filename_1_1").getChildren(), set([filename_2_1]))
        self.assertEqual(
            dag.get("filename_1_1").getParents(), set([dag.getRoot()]))

        self.assertEqual(
            dag.get("filename_2_1").getChildren(), set([
                filename_leaf,
            ]))
        self.assertEqual(
            dag.get("filename_2_1").getParents(), set([filename_1_1]))

        self.assertEqual(dag.get("filename_leaf").getChildren(), set())
        self.assertEqual( \
            dag.get( "filename_leaf" ).getParents()\
            , set( [ filename_2_1, dag.getRoot() ] )\
        )
예제 #9
0
    def test_init(self):
        node = DagNode(11)

        self.assertEqual(node.getData(), 11)
        self.assertEqual(len(node.getChildren()), 0)
        self.assertEqual(len(node.getParents()), 0)
예제 #10
0
    def test_isLeaf( self ):
        node1 = DagNode( 11 )
        node2 = DagNode( 22 )
        node3 = DagNode( 33 )

        self.assertTrue( node1.isLeaf() )
        self.assertTrue( node2.isLeaf() )
        self.assertTrue( node3.isLeaf() )

        node1.addChild( node2 )
        self.assertFalse( node1.isLeaf() )
        self.assertTrue( node2.isLeaf() )

        node3.addChild( node1 )
        self.assertFalse( node1.isLeaf() )
예제 #11
0
    def test_isLeaf(self):
        node1 = DagNode(11)
        node2 = DagNode(22)
        node3 = DagNode(33)

        self.assertTrue(node1.isLeaf())
        self.assertTrue(node2.isLeaf())
        self.assertTrue(node3.isLeaf())

        node1.addChild(node2)
        self.assertFalse(node1.isLeaf())
        self.assertTrue(node2.isLeaf())

        node3.addChild(node1)
        self.assertFalse(node1.isLeaf())
예제 #12
0
    def __init__(self, value):
        DagNode.__init__(self, value)

        self._included = False
        self._counter = 0
        self._reason = "File included in precompiled header"
예제 #13
0
    def test_isRoot( self ):
        node1 = DagNode( 11 )
        node2 = DagNode( 22 )
        node3 = DagNode( 33 )

        self.assertTrue( node1.isRoot() )

        node1.addChild( node2 )
        self.assertTrue( node1.isRoot() )

        node3.addChild( node1 )
        self.assertTrue( node1.isRoot() )

        node1.addParent( node3 )
        self.assertFalse( node1.isRoot() )
예제 #14
0
    def test_init( self ):
        node = DagNode( 11 )

        self.assertEqual( node.getData(), 11 )
        self.assertEqual( len( node.getChildren() ), 0 )
        self.assertEqual( len( node.getParents() ), 0 )
예제 #15
0
    def test_setColorRecursively( self ):
        node1 = DagNode( 11 )
        node2 = DagNode( 22 )
        node3 = DagNode( 33 )

        node1.addChild( node2 );
        node2.addChild( node3 );

        self.assertEqual( node1.getColor(), DfsNode.White )
        self.assertEqual( node2.getColor(), DfsNode.White )
        self.assertEqual( node3.getColor(), DfsNode.White )

        node1.setColorRecursively( DfsNode.Black )

        self.assertEqual( node1.getColor(), DfsNode.Black )
        self.assertEqual( node2.getColor(), DfsNode.Black )
        self.assertEqual( node3.getColor(), DfsNode.Black )
예제 #16
0
    def test_setColorRecursively(self):
        node1 = DagNode(11)
        node2 = DagNode(22)
        node3 = DagNode(33)

        node1.addChild(node2)
        node2.addChild(node3)

        self.assertEqual(node1.getColor(), DfsNode.White)
        self.assertEqual(node2.getColor(), DfsNode.White)
        self.assertEqual(node3.getColor(), DfsNode.White)

        node1.setColorRecursively(DfsNode.Black)

        self.assertEqual(node1.getColor(), DfsNode.Black)
        self.assertEqual(node2.getColor(), DfsNode.Black)
        self.assertEqual(node3.getColor(), DfsNode.Black)
예제 #17
0
    def test_isRoot(self):
        node1 = DagNode(11)
        node2 = DagNode(22)
        node3 = DagNode(33)

        self.assertTrue(node1.isRoot())

        node1.addChild(node2)
        self.assertTrue(node1.isRoot())

        node3.addChild(node1)
        self.assertTrue(node1.isRoot())

        node1.addParent(node3)
        self.assertFalse(node1.isRoot())
예제 #18
0
    def __init__( self, value ):
        DagNode.__init__( self, value )

        self._included = False
        self._counter = 0
        self._reason = "File included in precompiled header"