Example #1
0
    def create_mass_scenario(n_results: int = 100,
                             root_starter: int = 1) -> [str, Leaf]:
        tree = Leaf(root_starter)

        for i in range(n_results):
            tree.insert(i)

        expected = '63|31|15|7|3|1|0|2|5|4|6|11|9|8|10|13|12|14|23|19|17|16|18|21|20|22|27|25|24|26|29|28|30|47|39|35|'
        expected += '33|32|34|37|36|38|43|41|40|42|45|44|46|55|51|49|48|50|53|52|54|59|57|56|58|61|60|62|79|71|67|65|'
        expected += '64|66|69|68|70|75|73|72|74|77|76|78|87|83|81|80|82|85|84|86|95|91|89|88|90|93|92|94|97|96|98|99'

        return [expected, tree]
Example #2
0
    def test_simple_insert(self):
        tree = Leaf(1)
        tree.insert(2)
        self.assertEqual('1|2', str(tree), 'Insertion of second leaf in right')

        tree.insert(0)
        self.assertEqual('1|0|2', str(tree),
                         'Insertion of third leaf in left of root')

        tree.insert(1)
        self.assertEqual(
            '1|0|2', str(tree),
            'Insertion of element that already exist in tree (root)')

        tree.insert(2)
        self.assertEqual(
            '1|0|2', str(tree),
            'Insertion of element that already exist in tree (right leaf)')

        tree.insert(0)
        self.assertEqual(
            '1|0|2', str(tree),
            'Insertion of element that already exist in tree (left leaf)')

        tree.insert(3)
        self.assertEqual('1|0|2|3', str(tree),
                         'Insertion of leaf in left of left leaf of root')

        tree.insert(4)
        self.assertEqual(
            '1|0|3|2|4', str(tree),
            'Insertion of element that will execute normalization in tree')