def test_clip(): pat, _ = autoguess_life_file("lifep/breeder.lif") node = construct(pat) verify_clipped(node, 0, 0, 1600, 1600) verify_clipped(node, 0, 0, 160, 160) verify_clipped(node, 40, 40, 1600, 1600) verify_clipped(node, 40, 40, 160, 160)
def verify_baseline(pat, n): node = construct(pat) assert same_pattern(pat, expand(node)) for i in range(n): advanced = advance(node, i) assert same_pattern(pat, expand(advanced)) pat = baseline_life(pat)
def test_gray(): pat, _ = autoguess_life_file("lifep/breeder.lif") node = construct(pat) total_on = len(expand(node)) for l in range(6): expansion = expand(node, level=l) gray_sum = sum([g for (x, y, g) in expansion]) assert gray_sum == total_on / (2 ** (l * 2))
def test_centre(): node = construct(test_pattern) for i in range(5): old_node = node node = centre(node) assert node.k == old_node.k + 1 assert node.n == old_node.n ctr_node = inner(node) assert ctr_node == old_node
def test_advance(): pat_node = construct(test_pattern) for i in range(32): node = advance(pat_node, i) validate_tree(node) for i in range(4): node, gens = ffwd(pat_node, i) validate_tree(node) assert advance(get_zero(8), 8).n == 0 assert ffwd(get_zero(8), 4)[0].n == 0
def test_ffwd_large(): pat, _ = autoguess_life_file("lifep/breeder.lif") ffwd(construct(pat), 64)
def test_pad(): node = construct(test_pattern) node = pad(node) assert is_padded(node) node = crop(node) assert not is_padded(node)
def test_construct(): node = construct(test_pattern) validate_tree(node)