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 ] ) )
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() ] )\ )
def test_add_raise( self ): dag = Dag() self.assertRaises( Exception, dag.add, -1, "filename" ) self.assertRaises( Exception, dag.add, 2, "filename" ) self.assertRaises( Exception, dag.add, 3, "filename" ) dag.add( 1, "filename" ) self.assertRaises( Exception, dag.add, 3, "filename" ) self.assertRaises( Exception, dag.add, 4, "filename" )
def test_1(self): dag = Dag() # . a # . b # . c self._a = dag.add(1, "a") self._b = dag.add(1, "b") self._c = dag.add(1, "c") tSorter = TopologicalSorter(dag) self.assertEqual(self._a.getColor(), DfsNode.White) self.assertEqual(self._b.getColor(), DfsNode.White) self.assertEqual(self._c.getColor(), DfsNode.White) self.assertEqual([i.getData() for i in tSorter.getNodes()], ["b", "c", "a"])
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 ] ) )
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]))
def update(self, depth, header): return Dag.add(self, depth, header)
def add(self, depth, header): node = Dag.add(self, depth, header) node.setIncludedRecursively(True) return node
def update( self, depth, header ): return Dag.add( self, depth, header )
def add( self, depth, header ): node = Dag.add( self, depth, header ) node.setIncludedRecursively( True ) return node