Beispiel #1
0
    def test_preorder_traverse(self):

        # first we want to do a preorder_traverse that sets IDs as preorder position
        params1 = {"pos": 1}
        [self.t1, params1] = TD.preorder_traverse(self.t1, params1, TD.set_position_to_id)
        self.assertEqual(params1["pos"], 7)
        self.assertEqual(self.t1["id"], 1)
        self.assertEqual(self.t1["label"], "f")

        # children of f
        self.assertEqual(len(self.t1["children"]), 2)
        self.assertEqual(self.t1["children"][0]["id"], 2)
        self.assertEqual(self.t1["children"][0]["label"], "d")
        self.assertEqual(self.t1["children"][1]["id"], 6)
        self.assertEqual(self.t1["children"][1]["label"], "e")

        # children of D
        self.assertEqual(len(self.t1["children"][0]["children"]), 2)
        self.assertEqual(self.t1["children"][0]["children"][0]["id"], 3)
        self.assertEqual(self.t1["children"][0]["children"][0]["label"], "a")

        self.assertEqual(self.t1["children"][0]["children"][1]["id"], 4)
        self.assertEqual(self.t1["children"][0]["children"][1]["label"], "c")

        # children of C
        self.assertEqual(len(self.t1["children"][0]["children"][1]["children"]), 1)
        self.assertEqual(self.t1["children"][0]["children"][1]["children"][0]["id"], 5)
        self.assertEqual(self.t1["children"][0]["children"][1]["children"][0]["label"], "b")
Beispiel #2
0
 def test_compute_references(self):
     params = { 'pos2ref':[], 'stack':[], 'refKey':'label' }
     [ self.t1, params ] = TD.preorder_traverse( self.t1, params, XUDiff.compute_references )
     [ self.t1, params ] = TD.postorder_traverse( self.t1, params, XUDiff.compute_reference_list )
     
     expected_ref = [ "f.d.a", "f.d.c.b", "f.d.c", "f.d", "f.e", "f" ]
     for i in range(0, len( params['pos2ref']), 6 ):
         self.assertEqual( params['pos2ref'][i], expected_ref[i] )
         i = i + 1