def test_blinker(): field = fields.closedField(size=(4, 4)) field[1][1] = True field[1][2] = True field[1][3] = True ans_field = fields.closedField(other=field) ans_field[1][1] = False ans_field[1][3] = False ans_field[0][2] = True ans_field[2][2] = True ans2_field = fields.closedField(other=field) ans3_field = fields.closedField(other=ans_field) field.NextStep() # Figure blinked assert field == ans_field field.NextStep() # Blinking is periodical assert field == ans2_field field.NextStep() # Blinking is periodical assert field == ans3_field
def test_beacon(): field = fields.closedField(size=(5, 5)) field[1][1] = True field[1][2] = True field[2][1] = True field[3][4] = True field[4][3] = True field[4][4] = True ans_field = fields.closedField(other=field) ans_field[2][2] = True ans_field[3][3] = True ans2_field = fields.closedField(other=field) ans3_field = fields.closedField(other=ans_field) field.NextStep() # Figure blinked assert field == ans_field field.NextStep() # Blinking is periodical assert field == ans2_field field.NextStep() # Blinking is periodical assert field == ans3_field
def test_glider(): field = fields.closedField(size=(8, 8)) field[0][1] = True field[1][2] = True field[2][0] = True field[2][1] = True field[2][2] = True ans_field = fields.closedField(size=(8, 8)) ans_field[1][0] = True ans_field[1][2] = True ans_field[2][1] = True ans_field[2][2] = True ans_field[3][1] = True ans2_field = fields.closedField(size=(8, 8)) ans2_field[1][2] = True ans2_field[2][0] = True ans2_field[2][2] = True ans2_field[3][1] = True ans2_field[3][2] = True ans3_field = fields.closedField(size=(8, 8)) ans3_field[1][1] = True ans3_field[2][2] = True ans3_field[2][3] = True ans3_field[3][1] = True ans3_field[3][2] = True ans4_field = fields.closedField(size=(8, 8)) ans4_field[1][2] = True ans4_field[2][3] = True ans4_field[3][1] = True ans4_field[3][2] = True ans4_field[3][3] = True field.NextStep() # Glider moved assert field == ans_field field.NextStep() # Glider moved assert field == ans2_field field.NextStep() # Glider moved assert field == ans3_field field.NextStep() # Glider moved, returned to the initial form assert field == ans4_field
def test_corner_block(): field = fields.closedField(size=(4, 4)) field[0][0] = True field[0][1] = True field[1][0] = True field[1][1] = True ans_field = fields.closedField(other=field) field.NextStep() # Square shoud remain assert field == ans_field
def test_block(): field = fields.closedField(size=(4, 4)) field[1][1] = True field[1][2] = True field[2][1] = True field[2][2] = True ans_field = fields.closedField(other=field) field.NextStep() # Block shoud remain assert field == ans_field
def test_block_with_dot(): field = fields.closedField(size=(4, 4)) field[0][0] = True field[0][1] = True field[1][0] = True field[1][1] = True field[3][3] = True ans_field = fields.closedField(other=field) ans_field[3][3] = False field.NextStep() # Block shoud remain, dot should die assert field == ans_field
def test_dots(): field = fields.closedField(size=(5, 5)) field[0][0] = True field[1][2] = True field[3][2] = True field[4][3] = True ans_field = fields.closedField(size=(5, 5)) field.NextStep() # All dots should die assert field == ans_field field.NextStep() # No dots should born assert field == ans_field
def test_stay_alive(): field = fields.closedField(size=(1, 3)) field[0][0] = True field[0][1] = True field[0][2] = True ans_field = fields.closedField(size=(1, 3)) ans_field[0][1] = True ans2_field = fields.closedField(size=(1, 3)) field.NextStep() # Dot in the middle should remain alive assert field == ans_field field.NextStep() # Last dot should die assert field == ans2_field
def test_born(): field = fields.closedField(size=(4, 4)) field[1][0] = True field[0][1] = True field[2][2] = True ans_field = fields.closedField(size=(4, 4)) ans_field[1][1] = True ans2_field = fields.closedField(size=(4, 4)) field.NextStep() # New dot should born, another should die assert field == ans_field field.NextStep() # Last dot should die assert field == ans2_field