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_o_block():
    field = Field(6, 4)
    block = OBlock(field)
    block.position = 1, -1
    assert str(field) == '0,1,1,0;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0'

    block.position = 0, 4
    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;1,1,0,0;1,1,0,0'

    block.rotate_ccw().rotate_ccw()
    assert str(field) == '0,0,0,0;0,0,0,0;0,0,0,0;0,0,0,0;1,1,0,0;1,1,0,0'