Example #1
0
def test_simulator_run():
    """Test if the run() method returns the computed statistics"""
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    sim = sg.Simulator(board)
    stats = sim.run(sg.rules.conway_classic, iters=10)
    assert isinstance(stats, dict)
Example #2
0
def test_simulator_animate_without_run():
    """Test if animate() method throws an error when called before run()"""
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    sim = sg.Simulator(board)
    with pytest.raises(ValueError):
        sim.animate()
Example #3
0
def test_board_view():
    """Test if a figure and image is returned whenever view is called"""
    board = Board(size=(3, 3))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    fig, im = board.view()
    assert isinstance(fig, Figure)
    assert isinstance(im, AxesImage)
Example #4
0
def test_board_clear():
    """Test if the board resets whenever clear is called"""
    board = Board(size=(3, 3))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    board.clear()
    assert len(np.unique(board.state)) == 1
    assert np.unique(board.state)[0].astype(int) == 0
Example #5
0
def test_compute_statistics():
    """Test if compute_statistics() returns a dictionary"""
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    sim = sg.Simulator(board)
    sim.run(sg.rules.conway_classic, iters=10)
    stats = sim.compute_statistics(sim.get_history())
    assert isinstance(stats, dict)
Example #6
0
def test_simulator_animate():
    """Test if animate() method returns a FuncAnimation"""
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    sim = sg.Simulator(board)
    sim.run(sg.rules.conway_classic, iters=10)
    anim = sim.animate()
    assert isinstance(anim, animation.FuncAnimation)
Example #7
0
def test_simulator_get_history_shape():
    """Test if get_history() will return the expected shape"""
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    sim = sg.Simulator(board)
    sim.run(sg.rules.conway_classic, iters=10)
    hist = sim.get_history()
    assert hist.shape == (10, 10, 10)
Example #8
0
def test_rule_return_type(rule_name, fn):
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    new_state = fn(board.state)
    assert isinstance(new_state, (list, np.ndarray))
Example #9
0
def test_rule_return_shape(rule_name, fn):
    board = sg.Board(size=(10, 10))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    new_state = fn(board.state)
    assert new_state.shape == (10, 10)
Example #10
0
def test_board_add():
    """Test if adding a lifeform to board is successful"""
    board = Board(size=(3, 3))
    board.add(lf.Blinker(length=3), loc=(0, 1))
    assert np.array_equal(board.state, np.array([[False, True, False]] * 3))