Пример #1
0
 def test_modified(self):
     a = exponential
     c = modified_equation(a)
     n = 10
     self.assertEqual(c(empty_tree), 0)
     computed = list(c(tree) for tree in islice(tree_generator(), 0, n))
     expected = [1] + [0] * (n - 1)
     self.assertEqual(computed, expected)
Пример #2
0
 def test_generator(self):
     gen = unordered_tree.tree_generator(sort=True)
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
     print(next(gen))
Пример #3
0
 def setUp(self):
     a = tree_generator(sort=True)
     self.et = empty_tree
     self.t1_1 = next(a)  # []
     self.t2_1 = next(a)  # [[]]
     self.t3_1 = next(a)  # [[[]]]
     self.t3_2 = next(a)  # [[],[]]
     self.t4_1 = next(a)  # [[[[]]]]
     self.t4_2 = next(a)  # [[[],[]]]
     self.t4_3 = next(a)  # [[[]],[]]
     self.t4_4 = next(a)  # [[],[],[]]
Пример #4
0
def equal_up_to_order(a, b, max_order=None):
    '''Checks that ``a`` and ``b`` give the exact same answer for all trees.
    Returns the largest order for which this is true.
    '''
    if not a(empty_tree) == b(empty_tree):
        return None
    for tree in tree_generator():
        if max_order and tree.order() > max_order:
            return max_order
        elif not a(tree) == b(tree):
            return tree.order() - 1
Пример #5
0
 def setUp(self):
     a = tree_generator(sort=True)  # TODO: Implement indexing of functions.
     self.et = empty_tree
     self.t1_1 = next(a)  # []
     self.t2_1 = next(a)  # [[]]
     self.t3_1 = next(a)  # [[[]]]
     self.t3_2 = next(a)  # [[],[]]
     self.t4_1 = next(a)  # [[[[]]]]
     self.t4_2 = next(a)  # [[[],[]]]
     self.t4_3 = next(a)  # [[[]],[]]
     self.t4_4 = next(a)  # [[],[],[]]
     self.t5_1 = next(a)  # [[[[[]]]]]
     self.t5_2 = next(a)  # [[[[],[]]]]
     self.t5_3 = next(a)  # [[[[]],[]]]
     self.t5_4 = next(a)  # [[[],[],[]]]
     self.t5_5 = next(a)  # [[[[]]],[]
     self.t5_6 = next(a)  # [[[],[]],[]]
     self.t5_7 = next(a)  # [[[]],[[]]]
     self.t5_8 = next(a)  # [[[]],[],[]]
     self.t5_9 = next(a)  # [[],[],[],[]]