Exemplo n.º 1
0
def test_drop():
    """blocks can be dropped downwards to their final position"""
    field = Field(6, 4)
    oblock1, oblock2, iblock = OBlock(field), OBlock(field), IBlock(field)

    # Drop first O into bottom right corner
    oblock1.position = 0, 0
    oblock1.drop()
    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;2,2,0,0;2,2,0,0'

    # Move second O next to it and drop it (stays in place)
    oblock2.position = 2, 4
    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;2,2,1,1;2,2,1,1'
    oblock2.drop()
    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;2,2,2,2;2,2,2,2'

    # Drop I on top of O
    iblock.position = 0, -1
    iblock.drop()

    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;2,2,2,2;2,2,2,2;2,2,2,2'

    with pytest.raises(CannotMoveBlock):
        oblock1.position = 0, 0

    with pytest.raises(CannotMoveBlock):
        oblock1.rotate_ccw()
Exemplo n.º 2
0
def test_ending_game_with_drop():
    field = Field.from_str('0,0,0,0;3,3,3,3')

    oblock = OBlock(field)
    oblock.position = 1, -1

    with pytest.raises(GameOver):
        oblock.drop()