Пример #1
0
def test_exchange_missing_tile_raises():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    with pytest.raises(MissingTileError):
        hand.exchange_tiles(2 * [Tile(Color.YELLOW, Shape.DIAMOND)], bag)
    assert set(tiles_in_hand) == set(hand.tiles)
    assert set(bag.tiles) == set(tiles_for_bag)
Пример #2
0
def test_fill_full_hand():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    hand.fill_from(bag)
    assert set(hand.tiles) == set(tiles_in_hand)
    assert len(bag.tiles) == 6
    assert len(hand.tiles) == 6
Пример #3
0
def test_init():
    tiles_in_bag = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER)
    ]
    bag = Bag(tiles_in_bag)
    hand = Hand.init_from(bag)
    expected = set(tiles_in_bag)
    result = set(hand.tiles)
    assert expected == result
Пример #4
0
def test_exchange_one_tile():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [Tile(Color.PURPLE, Shape.CIRCLE)]
    bag = Bag(tiles_for_bag)
    hand.exchange_tiles([Tile(Color.RED, Shape.CIRCLE)], bag)
    expected_tiles_in_hand = tiles_in_hand[1:]
    expected_tiles_in_hand.append(Tile(Color.PURPLE, Shape.CIRCLE))
    assert set(expected_tiles_in_hand) == set(hand.tiles)

    expected_tiles_in_bag = [Tile(Color.RED, Shape.CIRCLE)]
    assert set(bag.tiles) == set(expected_tiles_in_bag)
Пример #5
0
def test_exchange_all_tiles():
    tiles_in_hand = [
        Tile(Color.RED, Shape.CIRCLE),
        Tile(Color.ORANGE, Shape.X),
        Tile(Color.YELLOW, Shape.DIAMOND),
        Tile(Color.GREEN, Shape.SQUARE),
        Tile(Color.BLUE, Shape.STAR),
        Tile(Color.PURPLE, Shape.CLOVER),
    ]
    bag = Bag(tiles_in_hand)
    hand = Hand.init_from(bag)
    del bag
    tiles_for_bag = [
        Tile(Color.PURPLE, Shape.CIRCLE),
        Tile(Color.RED, Shape.X),
        Tile(Color.ORANGE, Shape.DIAMOND),
        Tile(Color.YELLOW, Shape.SQUARE),
        Tile(Color.GREEN, Shape.STAR),
        Tile(Color.BLUE, Shape.CLOVER),
    ]
    bag = Bag(tiles_for_bag)
    hand.exchange_tiles(copy(tiles_in_hand), bag)
    assert set(tiles_for_bag) == set(hand.tiles)
    assert set(bag.tiles) == set(tiles_in_hand)
Пример #6
0
 def init_from(cls, bag):
     hand = Hand.init_from(bag)
     return cls(hand)