예제 #1
0
    def test_height_DataNode(self):
        """
        Test height function of DataNode.
        """

        t1 = DataNode(1)
        self.assertEqual(t1.height(), 1)

        t1.add(DataNode(11))
        self.assertEqual(t1.height(), 2)
예제 #2
0
    def test_minimize_height_DataNode(self):
        """
        Test minimize_height function of DataNode.
        """

        t1, t2, t3 = DataNode('1'), DataNode('2'), DataNode('3')

        t1.add(t2)
        t2.add(t3)

        self.assertEqual(t1.height(), 3)

        t1.minimize_height()
        self.assertEqual(t1.height(), 2)

        t1.minimize_height()
        self.assertEqual(t1.height(), 1)
예제 #3
0
    def test_add_DataNode(self):
        """
        Test add function of DataNode.
        """

        t1 = DataNode('1')
        t2 = DataNode('2', children=[DataNode(21)])

        t1.add(DataNode(11))
        t1.add(DataNode(12))

        t2.add(DataNode(22))
        t2.add(DataNode(23))

        self.assertEqual(len(t1.children), 2)
        self.assertEqual(len(t2.children), 3)

        self.assertEqual(t1.height(), 2)
        self.assertEqual(t2.height(), 2)
예제 #4
0
    def test_complex_DataNode3(self):
        """
        Test a complex DataNode with all possible attributes
        """

        data = ('1', None)
        result = DataNode(*data)

        self.assertEqual(result.data, data[0])
        self.assertEqual(result.children, None)

        self.assertEqual(result.height(), 1)
예제 #5
0
    def test_complex_DataNode2(self):
        """
        Test a complex DataNode with all possible attributes

        List of childs
        """

        data = ('1', [DataNode('child')])

        result = DataNode(*data)

        self.assertEqual(result.data, data[0])
        self.assertEqual(result.children, data[1])
        self.assertEqual(result.height(), 2)
예제 #6
0
    def test_complex_DataNode1(self):
        """
        Test a complex DataNode with all possible attributes

        Single child
        """

        data = ('1', DataNode('child'))

        result = DataNode(*data)

        self.assertEqual(result.data, data[0])
        self.assertEqual(result.children, [data[1]])
        self.assertEqual(result.height(), 2)