Exemplo n.º 1
0
 def test_parsing_indices(self):
     xw = Crossword(5)
     black_inds = [(0, 0), (0, 1), (2, 2), (4, 4), (4, 3)]
     for ind in black_inds:
         xw[ind] = black
     expected_keys = [
         (across, 1),
         (across, 4),
         (across, 6),
         (across, 7),
         (across, 8),
         (across, 10),
         (down, 1),
         (down, 2),
         (down, 3),
         (down, 4),
         (down, 5),
         (down, 9),
     ]
     assert set(expected_keys) == set([w.index for w in xw.iterwords()])
Exemplo n.º 2
0
def xw(simple_dict):
    """
    ┌───┬───┬───┐   ┌───┬───┬───┐
    │███│ B │ C │   │███│1  │2  │
    ├───┼───┼───┤   ├───┼───┼───┤
    │ A │ B │ C │   │3  │   │   │
    ├───┼───┼───┤   ├───┼───┼───┤
    │   │   │███│   │4  │   │███│
    └───┴───┴───┘   └───┴───┴───┘
    """
    xw = Crossword(3, dictionary=simple_dict)
    xw[0, 0] = black
    xw[2, 2] = black
    xw[across, 1] = "BC"
    xw[across, 3] = "ABC"
    return xw
Exemplo n.º 3
0
class TestCrosswordIndexing:
    def test_index_word(self, xw):
        assert xw[across, 1].value == "BC"
        assert xw[across, 4].value == "  "
        assert xw[down, 1].value == "BB "

    def test_index_letter(self, xw):
        assert xw[0, 0] == black
        assert xw[1, 0] == "A"
        assert xw[2, 1] == " "
        assert xw[1, -1] == "C"

    def test_index_setter_word(self, xw):
        xw[across, 4] = "qZ"
        assert xw[across, 4].value == "QZ"
        assert xw[down, 1].value == "BBZ"

    def test_index_setter_letter(self, xw):
        xw[2, 1] = "z"
        assert xw[across, 4].value == " Z"
        assert xw[down, 1].value == "BBZ"

    def test_wrong_word_length(self, xw):
        for bad_val in ["A", "AAA"]:
            with pytest.raises(ValueError):
                xw[across, 4] = bad_val
        with pytest.raises(ValueError):
            xw[1, 0] = "AA"

    @pytest.mark.parametrize(
        "bad_val", [["A", "A"], 72, Crossword(2)[across, 1]])
    def test_wrong_types(self, xw, bad_val):
        with pytest.raises(ValueError):
            xw[across, 4] = bad_val

    @pytest.mark.parametrize("bad_index", [(across, 2), down, (1, 1, 0),
                                           (1, slice(1, 2))])
    def test_invalid_index(self, xw, bad_index):
        with pytest.raises(IndexError):
            xw[bad_index]
        with pytest.raises(IndexError):
            xw[bad_index] = "A"
Exemplo n.º 4
0
 def test_default_dictionary(self):
     xw = Crossword(3)
     assert "ALFALFA" in xw._dictionary
     assert all([0 <= v <= 1 for v in xw._dictionary.values()])
Exemplo n.º 5
0
 def test_num_rows_cols(self):
     xw = Crossword(5, 7)
     assert xw.num_rows == 5
     assert xw.num_cols == 7
Exemplo n.º 6
0
 def test_symmetric_index(self):
     xw = Crossword(5, 7)
     assert xw.get_symmetric_index((0, 1)) == (4, 5)
     assert xw.get_symmetric_index((2, 3)) == (2, 3)
Exemplo n.º 7
0
 def test_from_puz(self):
     Crossword.from_puz(Path(__file__).parent / "dummy.puz")
Exemplo n.º 8
0
 def test_to_puz(self, xw, tmp_path):
     filename = tmp_path / "test.puz"
     xw.to_puz(filename)
     assert tmp_path.exists()
     loaded = Crossword.from_puz(filename)
     assert np.all(loaded.grid == xw.grid)