Exemplo n.º 1
0
    def test_draw_unpruned_tree_with_some_text(self):
        ft = FractalTree(value=20)
        ft.add_layer()
        ft.get_children()[0].add_layer()
        ft.get_children()[-1].add_layer()
        fill_tree_with_columns(ft, 2)
        selected_node = ft.select_index([1])
        child_1 = selected_node.get_children()[1]
        child_2 = selected_node.get_children()[2]
        lb1 = child_1.manual_graphic.draw_objects[0].start_mark_line.add_label(
            1, font_size=8, bottom_margin=1)
        lb2 = child_1.manual_graphic.draw_objects[0].start_mark_line.add_label(
            2, font_size=8, bottom_margin=1)
        lb3 = child_2.manual_graphic.draw_objects[0].start_mark_line.add_label(
            3, font_size=8, bottom_margin=1)

        for child in ft.get_children():
            try:
                child.manual_graphic.draw_objects[1].top_margin += 2
            except IndexError:
                pass

        with self.file_path(path, 'draw_unpruned_tree_with_some_text',
                            'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)
Exemplo n.º 2
0
 def test_3(self):
     ft = FractalTree(value=10, proportions=(1, 2, 3), tree_permutation_order=(3, 1, 2))
     ft.add_layer()
     ft.get_children()[0].add_layer()
     expected = [[0.8333333333333334, 1.6666666666666667, 2.5], 1.6666666666666667, 3.3333333333333335]
     result = ft.get_leaves(key=lambda leaf: float(leaf.value))
     self.assertEqual(expected, result)
Exemplo n.º 3
0
class Test(TestCase):
    def setUp(self) -> None:
        self.ft = FractalTree(proportions=[1, 2, 3],
                              tree_permutation_order=[3, 1, 2],
                              value=10)

    def test_1(self):
        self.ft.add_layer()
        self.ft.get_children()[1].add_layer()

        selected = self.ft.get_children()[1].get_children()[0]
        self.assertEqual(selected.__next__.name, '2.2')
Exemplo n.º 4
0
    def test_draw_filled_tree(self):
        ft = FractalTree(value=20)
        ft.add_layer()
        ft.get_children()[1].add_layer()
        fill_tree_with_columns(ft, 2)

        with self.file_path(path, 'draw_filled_tree', 'pdf') as pdf_path:
            self.pdf.translate_page_margins()
            self.pdf.draw_ruler('h')
            self.pdf.draw_ruler('v')
            self.pdf.translate(10, 10)
            ft.manual_graphic.draw(self.pdf)
            self.pdf.write(pdf_path)
Exemplo n.º 5
0
class Test(TestCase):
    def setUp(self) -> None:
        self.ft = FractalTree(value=10)

    def test_1(self):
        self.assertEqual([self.ft], self.ft.get_leaves())

    def test_2(self):
        self.assertEqual([self.ft.value],
                         self.ft.get_leaves(key=lambda leaf: leaf.value))

    def test_3(self):
        self.ft.add_layer()
        [
            child for child in self.ft.get_children()
            if child.fractal_order == 1
        ][0].fertile = False
        self.ft.add_layer()
        result = [[Fraction(5, 6),
                   Fraction(5, 3),
                   Fraction(5, 2)],
                  Fraction(5, 3),
                  [Fraction(10, 9),
                   Fraction(5, 3),
                   Fraction(5, 9)]]
        self.assertEqual(result,
                         self.ft.get_leaves(key=lambda leaf: leaf.value))
Exemplo n.º 6
0
 def test_3(self):
     ft = FractalTree(proportions=[1, 2, 3, 4, 5, 6], tree_permutation_order=[4, 1, 5, 3, 6, 2], value=20,
                      multi=(4, 3))
     ft.add_layer()
     ft.reduce_children(lambda child: child.fractal_order not in [2, 3])
     actual = [node.value for node in ft.get_children()]
     expected = [12, 8]
     self.assertEqual(actual, expected)
Exemplo n.º 7
0
 def test_two(self):
     t = FractalTree(value=10)
     t.add_layer()
     child = t.get_children()[0]
     s = child.split(1, 1)
     actual = [x.value for x in s]
     expected = [child.value / 2, child.value / 2]
     self.assertEqual(expected, actual)
Exemplo n.º 8
0
 def test_split_is_leaf(self):
     t = FractalTree(value=10)
     t.add_layer()
     child = t.get_children()[0]
     s = child.split(1, 1, 1)
     actual = [x.is_leaf for x in s]
     expected = [True, True, True]
     self.assertEqual(expected, actual)
 def test_1(self):
     ft = FractalTree(reading_direction='vertical', value=10)
     ft.add_layer()
     permutation_orders = [
         child.permutation_order for child in ft.get_children()
     ]
     result = [[2, 1, 3], [3, 2, 1], [1, 3, 2]]
     self.assertEqual(result, permutation_orders)
Exemplo n.º 10
0
class Test(TestCase):
    def setUp(self) -> None:
        self.ft = FractalTree(value=10)

    def test_1(self):
        self.ft.change_value(20)
        result = 20
        self.assertEqual(result, self.ft.value)

    def test_2(self):
        self.ft.add_layer()
        self.ft.get_children()[0].change_value(10)
        expected = 15
        self.assertEqual(expected, self.ft.value)

    def test_3(self):
        self.ft.add_layer()
        self.ft.get_children()[0].change_value(10)
        expected = [Fraction(10, 1), Fraction(5, 3), Fraction(10, 3)]
        self.assertEqual(expected,
                         [child.value for child in self.ft.get_children()])

    def test_4(self):
        self.ft.add_layer()
        self.ft.change_value(15)
        expected = [Fraction(15, 2), Fraction(5, 2), Fraction(5, 1)]
        self.assertEqual(expected,
                         [child.value for child in self.ft.get_children()])

    def test_5(self):
        self.ft.add_layer()
        self.ft.add_layer()
        self.ft.get_children()[0].change_value(10)
        expected = [[Fraction(15, 1)], [10,
                                        Fraction(5, 3),
                                        Fraction(10, 3)],
                    [[Fraction(5, 3),
                      Fraction(10, 3),
                      Fraction(5, 1)],
                     [Fraction(5, 6),
                      Fraction(5, 18),
                      Fraction(5, 9)],
                     [Fraction(10, 9),
                      Fraction(5, 3),
                      Fraction(5, 9)]]]
        self.assertEqual(expected, [
            self.ft.get_layer(layer=i, key='value')
            for i in range(self.ft.number_of_layers + 1)
        ])
Exemplo n.º 11
0
class Test(TestCase):
    def setUp(self) -> None:
        self.ft = FractalTree(tree_permutation_order=[3, 1, 2],
                              proportions=[1, 2, 3],
                              value=10)

    def test_1(self):
        self.ft.add_layer()
        result = [(2, 1), (2, 2), (2, 3)]
        self.assertEqual(result,
                         [child.multi for child in self.ft.get_children()])

    def test_2(self):
        self.ft.multi = (1, 7)
        self.ft.add_layer()
        result = [leaf.value for leaf in self.ft.traverse_leaves()]
        ft = FractalTree(value=10, multi=(3, 1))
        ft.add_layer()
        expected = [leaf.value for leaf in ft.traverse_leaves()]
        self.assertEqual(expected, result)

    def test_3(self):
        self.ft.multi = (4, 1)
        self.ft.add_layer()
        result = [leaf.value for leaf in self.ft.traverse_leaves()]
        ft = FractalTree(value=10, multi=(1, 1))
        ft.add_layer()
        expected = [leaf.value for leaf in ft.traverse_leaves()]
        self.assertEqual(expected, result)

    def test_4(self):
        self.ft.multi = (3, 4)
        self.ft.add_layer()
        result = [leaf.value for leaf in self.ft.traverse_leaves()]
        ft = FractalTree(value=10, multi=(1, 1))
        ft.add_layer()
        expected = [leaf.value for leaf in ft.traverse_leaves()]
        self.assertEqual(expected, result)
Exemplo n.º 12
0
class Test(TestCase):
    def setUp(self) -> None:
        self.ft = FractalTree(proportions=[1, 2, 3],
                              tree_permutation_order=[3, 1, 2],
                              value=10)

    def test_0(self):
        with self.assertRaises(Exception):
            self.ft.get_layer(1)

    def test_1(self):
        self.assertEqual([self.ft], self.ft.get_layer(0))

    def test_2(self):
        self.ft.add_layer()
        result = self.ft.get_children()
        self.assertEqual(result, self.ft.get_layer(1))

    def test_3(self):
        for i in range(3):
            self.ft.add_layer()

        result = self.ft.get_children()
        self.assertEqual(result, self.ft.get_layer(1))

    def test_4(self):
        for i in range(3):
            self.ft.add_layer()
        result = [child.get_children() for child in self.ft.get_children()]

        self.assertEqual(result, self.ft.get_layer(2))

    def test_5(self):
        for i in range(3):
            self.ft.add_layer()
        result = self.ft.get_leaves()

        self.assertEqual(result, self.ft.get_layer(3))

    def test_6(self):
        for i in range(3):
            self.ft.add_layer()

        with self.assertRaises(ValueError):
            self.ft.get_layer(4)

    def test_7(self):
        self.ft.add_layer()
        self.ft.add_layer(lambda n: True if n.fractal_order > 1 else False)
        self.ft.add_layer(lambda n: True if n.fractal_order > 1 else False)
        self.ft.add_layer(lambda n: True if n.fractal_order > 1 else False)
        self.ft.add_layer(lambda n: True if n.fractal_order > 1 else False)
        result = [[['1.1'],
                   [['1.2.1'], ['1.2.2.1', '1.2.2.2', '1.2.2.3'],
                    ['1.2.3.1', '1.2.3.2', '1.2.3.3']],
                   [['1.3.1.1', '1.3.1.2', '1.3.1.3'], ['1.3.2'],
                    ['1.3.3.1', '1.3.3.2', '1.3.3.3']]], '2',
                  [[['3.1.1'], ['3.1.2.1', '3.1.2.2', '3.1.2.3'],
                    ['3.1.3.1', '3.1.3.2', '3.1.3.3']],
                   [['3.2.1.1', '3.2.1.2', '3.2.1.3'], ['3.2.2'],
                    ['3.2.3.1', '3.2.3.2', '3.2.3.3']], ['3.3']]]
        self.assertEqual(result,
                         [name for name in self.ft.get_layer(4, key='name')])

    def test_7_1(self):
        self.ft.add_layer()
        self.ft.add_layer()
        self.assertEqual([10], self.ft.get_layer(0, key='value'))

    def test_7_2(self):
        self.ft.add_layer()
        self.ft.add_layer()
        result = [Fraction(5, 1), Fraction(5, 3), Fraction(10, 3)]
        self.assertEqual(result, self.ft.get_layer(1, key='value'))

    def test_7_3(self):
        self.ft.add_layer()
        self.ft.add_layer()
        result = [[Fraction(5, 6),
                   Fraction(5, 3),
                   Fraction(5, 2)],
                  [Fraction(5, 6),
                   Fraction(5, 18),
                   Fraction(5, 9)],
                  [Fraction(10, 9),
                   Fraction(5, 3),
                   Fraction(5, 9)]]
        self.assertEqual(result, self.ft.get_layer(2, key='value'))

    def test_get_layer_key_lambda(self):
        self.ft.add_layer()
        self.ft.add_layer()
        result = [[0.83, 1.67, 2.5], [0.83, 0.28, 0.56], [1.11, 1.67, 0.56]]
        self.assertEqual(
            result,
            self.ft.get_layer(2, key=lambda node: round(float(node.value), 2)))
Exemplo n.º 13
0
def make_ft():
    ft = FractalTree(value=20)
    ft.add_layer()
    ft.get_children()[0].add_layer()
    ft.get_children()[-1].add_layer()
    return ft
Exemplo n.º 14
0
 def test_child_is_not_leaf(self):
     t = FractalTree(value=10)
     t.add_layer()
     child = t.get_children()[0]
     child.split(1, 1, 1)
     self.assertFalse(child.is_leaf)
Exemplo n.º 15
0
 def setUp(self) -> None:
     ft = FractalTree(value=10, reading_direction='vertical')
     ft.add_layer()
     ft.add_layer()
     self.ft = ft.get_children()[1]
     self.deep_copied = self.ft.__deepcopy__()