def test_i_column(self): print("") print("I-Column Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if ( y in [3, 6, 8, 9, 11, 14] and x in [4, 5, 6]) or ( y in [4, 5, 12, 13] and x in [5]) else False) for x in range(11) ] for y in range(18)]) print(grid) generation = Generation(grid) for i in range(14): print(generation) generation = Generation(generation.grid, generation.generation_number) print(generation) self.assertEqual(str(grid), str(generation.grid))
def test_pulsar(self): print("") print("Pulsar Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if ( y in [2, 7, 9, 14] and x in [4, 5, 6, 10, 11, 12]) or (y in [4, 5, 6, 10, 11, 12] and x in [2, 7, 9, 14]) else False) for x in range(17) ] for y in range(17)]) print(grid) generation = Generation(grid) print(generation) generation2 = Generation(generation.grid, generation.generation_number) print(generation2) generation3 = Generation(generation2.grid, generation2.generation_number) print(generation3) self.assertEqual(str(grid), str(generation3.grid))
def test_block(self): print("") print("Block Test") grid = Grid(cells=[[ Cell(Coordinates(x, y), True if ( x in [1, 2] and y in [1, 2]) else False) for x in range(4) ] for y in range(4)]) print(grid) generation = Generation(grid) print(generation) self.assertEqual(str(grid), str(generation.grid))
def test_file_write_then_read(self): print("") print("Basic File Write and Read Back Test") generation = Generation(grid=Grid(cells=self.test_data), steps=0) write_state(final_state=generation, out_file=self.first_file) read_grid = read_state(in_file=self.first_file) print(read_grid) print("=============") print(generation) print("") self.assertEqual(str(read_grid), str(generation.grid))
def test_tub(self): print("") print("Tub Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if (x in [1, 3] and y in [2]) or ( y in [1, 3] and x in [2]) else False) for x in range(5) ] for y in range(5)]) print(grid) generation = Generation(grid) print(generation) self.assertEqual(str(grid), str(generation.grid))
def test_boat(self): print("") print("Boat Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if (x in [1, 2] and y in [1]) or (x in [1, 3] and y in [2]) or (x == 2 and y == 3) else False) for x in range(5) ] for y in range(5)]) print(grid) generation = Generation(grid) print(generation) self.assertEqual(str(grid), str(generation.grid))
def test_loaf(self): print("") print("Beehive Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if (x in [2, 3] and y in [1]) or ( x in [4] and y in [2, 3]) or ((x == 1 and y == 2) or ( x == 2 and y == 3) or (x == 3 and y == 4)) else False) for x in range(6) ] for y in range(6)]) print(grid) generation = Generation(grid) print(generation) self.assertEqual(str(grid), str(generation.grid))
def test_heavyweight(self): print("") print("Heavyweight Spaceship Test") grid = Grid(cells=[[ Cell( Coordinates(x, y), True if (x in [3, 4] and y == 1) or ( x in [1, 6] and y == 2) or (x == 7 and y in [3, 4, 5]) or ( x == 1 and y == 4) or ( y == 5 and x in [2, 3, 4, 5, 6]) else False) for x in range(11) ] for y in range(9)]) print(grid) initial_hwss = GridWindow(grid=grid, x_offset=0, y_offset=0, x_max=9, y_max=7) initial_hwss_str = str(Grid(cells=initial_hwss.contents)) generation = Generation(grid) for i in range(3): print(generation) generation = Generation(generation.grid, generation.generation_number) print(generation) final_hwss = GridWindow(grid=generation.grid, x_offset=2, y_offset=0, x_max=11, y_max=7) final_hwss_str = str(Grid(cells=final_hwss.contents)) print("") print(self.initial_state_header) print(initial_hwss) print("") print(self.final_state_header) print(final_hwss) self.assertEqual(initial_hwss_str, final_hwss_str)