def test_init_filled():
    coin_a = Coin(0, 0)
    coin_b = Coin(0, 0)
    array = SlicedArray([coin_a, coin_b], grid=16)

    assert array._parts == {
        (0, 0): [coin_a, coin_b],
    }
    assert len(array) == 2
def test_remove():
    coin_a = Coin(0, 0)
    coin_b = Coin(16, 16)
    array = SlicedArray([coin_a, coin_b], grid=16)
    array.remove(coin_b)

    assert array._parts == {
        (0, 0): [coin_a],
        (1, 1): [],
    }
    assert len(array) == 1
def test_append():
    coin_a = Coin(0, 0)
    coin_b = Coin(16, 16)

    array = SlicedArray([coin_a], grid=16)
    array.append(coin_b)

    assert array._parts == {
        (0, 0): [coin_a],
        (1, 1): [coin_b],
    }
    assert len(array) == 2
Example #4
0
def test_messages_get_world_data():
    game = Game()

    player = Player(x=1, y=1, player_id=0)
    game.alive_players = [player]
    game.npcs = [NPC(2, 2)]
    game.bullets = [Bullet(3, 3)]
    game.walls = [TinyWall(x=4, y=4), Water(x=5, y=5)]
    game.coins = [Coin(x=4, y=4), Coin(x=5, y=5)]

    assert messages.get_world_data(player, game) == dict(
        id=player.id.hex,
        cords=[
            dict(type='player', id=player.id.hex, position={
                'x': 1,
                'y': 1
            }),
            dict(type='npc', id=game.npcs[0].id.hex, position={
                'x': 2,
                'y': 2
            }),
            dict(type='bullet',
                 id=game.bullets[0].id.hex,
                 position={
                     'x': 3,
                     'y': 3
                 }),
            dict(type='tinywall',
                 id=game.walls[0].id.hex,
                 position={
                     'x': 4,
                     'y': 4
                 }),
            dict(type='water',
                 id=game.walls[1].id.hex,
                 position={
                     'x': 5,
                     'y': 5
                 }),
            dict(type='coin',
                 id=game.coins[0].id.hex,
                 position={
                     'x': 4,
                     'y': 4
                 }),
            dict(type='coin',
                 id=game.coins[1].id.hex,
                 position={
                     'x': 5,
                     'y': 5
                 }),
        ])
def test_remove_not_exists():
    coin_a = Coin(0, 0)
    coin_b = Coin(16, 16)
    array = SlicedArray([coin_a], grid=16)

    with pytest.raises(ValueError):
        array.remove(coin_b)

    assert array._parts == {
        (0, 0): [coin_a],
        (1, 1): [],
    }
    assert len(array) == 1
def test_find_nearest():
    far_coins = {Coin(32, 32), Coin(32, 64), Coin(64, 64)}
    nearest_coins = {Coin(0, 0), Coin(1, 1), Coin(16, 1), Coin(1, 16)}
    array = SlicedArray(far_coins, grid=16)
    array.multiple_append(nearest_coins)

    result = array.find_nearest(Rect(18, 18, 13, 13))
    # rect.bottom/rect.right is 31

    assert set(result) == nearest_coins
Example #7
0
 def make_coin(self, char, cords, tile_cords):
     coin = Coin(*cords)
     self.game.coins.append(coin)
def test_iter():
    coin_a = Coin(0, 0)
    coin_b = Coin(16, 16)
    array = SlicedArray([coin_a, coin_b], grid=16)

    assert set(array) == {coin_a, coin_b}