Example #1
0
def run_goal(n_or_goal, goal=None):
    if goal is None:
        goal = n_or_goal
        return take_inf(goal(Substitution()))
    else:
        n = n_or_goal
        return take(n, goal(Substitution()))
Example #2
0
def test_append_map_inf():
    numbers = suspended_numbers(5)
    num_powers = append_map_inf(powers, numbers)
    result = list(take_inf(num_powers))
    assert set(result[:1]) == {625}
    assert set(result[1:3]) == {125, 256}
    assert set(result[3:6]) == {25, 64, 81}
    assert set(result[6:10]) == {5, 16, 27, 16}
    assert set(result[10:14]) == {4, 9, 8, 1}
    assert set(result[14:17]) == {3, 4, 1}
    assert set(result[17:19]) == {2, 1}
    assert set(result[19:]) == {1}
Example #3
0
def test_append_inf_a_is_longer():
    stream_a = suspended_numbers(4)
    stream_b = suspended_numbers(2)
    numbers = append_inf(stream_a, stream_b)
    assert list(take_inf(numbers)) == [4, 2, 3, 1, 2, 1]
Example #4
0
def test_append_inf_equal_length():
    stream_a = suspended_numbers(2)
    stream_b = suspended_numbers(2)
    numbers = append_inf(stream_a, stream_b)
    assert list(take_inf(numbers)) == [2, 2, 1, 1]
Example #5
0
def test_take_inf():
    stream = suspended_numbers(3)
    numbers = take_inf(stream)
    assert list(numbers) == [3, 2, 1]