Example #1
0
def test_queen_problem_with_four_queens():
    Coordinate = morpy.Coordinate
    dimensions = morpy.Dimensions(4, 4)
    pieces = 4 * morpy.QUEEN
    positions = morpy.get_positions_iter(dimensions, pieces)
    position_1 = morpy.Position(
        frozendict(
            {
                Coordinate(0, 2): morpy.QUEEN,
                Coordinate(1, 0): morpy.QUEEN,
                Coordinate(2, 3): morpy.QUEEN,
                Coordinate(3, 1): morpy.QUEEN,
            }
        ),
        dimensions,
    )
    position_2 = morpy.Position(
        frozendict(
            {
                Coordinate(0, 1): morpy.QUEEN,
                Coordinate(1, 3): morpy.QUEEN,
                Coordinate(2, 0): morpy.QUEEN,
                Coordinate(3, 2): morpy.QUEEN,
            }
        ),
        dimensions,
    )
    expected = (position_1, position_2)
    assert set(expected) == set(positions)
Example #2
0
def test_get_valid_positions_3_by_3_two_kings_one_rook_iter():
    Coordinate = morpy.Coordinate
    dimensions = morpy.Dimensions(3, 3)
    pieces = 2 * morpy.KING + morpy.ROOK
    positions = morpy.get_positions_iter(dimensions, pieces)
    position_1 = morpy.Position(
        frozendict({Coordinate(0, 1): morpy.ROOK, Coordinate(2, 0): morpy.KING, Coordinate(2, 2): morpy.KING}),
        dimensions,
    )
    position_2 = morpy.Position(
        frozendict({Coordinate(1, 0): morpy.ROOK, Coordinate(0, 2): morpy.KING, Coordinate(2, 2): morpy.KING}),
        dimensions,
    )
    position_3 = morpy.Position(
        frozendict({Coordinate(1, 2): morpy.ROOK, Coordinate(0, 0): morpy.KING, Coordinate(2, 0): morpy.KING}),
        dimensions,
    )
    position_4 = morpy.Position(
        frozendict({Coordinate(2, 1): morpy.ROOK, Coordinate(0, 0): morpy.KING, Coordinate(0, 2): morpy.KING}),
        dimensions,
    )
    expected = (position_1, position_2, position_3, position_4)
    assert set(expected) == set(positions)
Example #3
0
def test_copy():
    d = frozendict({'a': 'a'})
    d2 = d.copy()
    assert d is not d2
Example #4
0
def test_cant_set_item():
    d = frozendict({'a': 'a'})
    with raises(TypeError):
        d['b'] = 'b'
    assert 'b' not in d
Example #5
0
def test_repr():
    d = frozendict({'a': 'a'})
    assert str(d) == "<frozendict {'a': 'a'}>"