Esempio n. 1
0
    def test_example_board(self):
        """
        Given a known board and language, expected words are found.
        """
        rows = [
            ["Qu", "A", "A"],
            ["A", "L", "G"],
            ["R", "G", "I"],
        ]

        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(dedent(u"""\
            AQuA
            Qua
            ILA
            GALGA
            LA
            ALA
            CHRISTMAS
            MOTHER
            """))

        language = Language(dictionary_path=path)
        boggle = Boggle(
            board=Board(rows=rows),
            valid_words=language.words)
        expected = set(['GALGA', 'ILA', 'AQuA', 'ALA', 'QuA'])
        self.assertEqual(boggle.list_words(), expected)
Esempio n. 2
0
    def test_example_board(self):
        """
        Given a known board and language, expected words are found.
        """
        rows = [
            ["Qu", "A", "A"],
            ["A", "L", "G"],
            ["R", "G", "I"],
        ]

        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(
                dedent(u"""\
            AQuA
            Qua
            ILA
            GALGA
            LA
            ALA
            CHRISTMAS
            MOTHER
            """))

        language = Language(dictionary_path=path)
        boggle = Boggle(board=Board(rows=rows), valid_words=language.words)
        expected = set(['GALGA', 'ILA', 'AQuA', 'ALA', 'QuA'])
        self.assertEqual(boggle.list_words(), expected)
Esempio n. 3
0
def main():
    boards = [
        {'board': large_board, 'file': 'large_board'},
        {'board': small_board, 'file': 'small_board'},
    ]

    for board in boards:
        language = Language(
            dictionary_path="/usr/share/dict/words",
            data_path="english_words.json")
        boggle = Boggle(
            board=Board(rows=board['board']),
            valid_words=language.words)

        found_words = boggle.list_words()

        if not os.path.exists(board['file']):
            with io.open(board['file'], 'wb') as word_file:
                for word in found_words:
                    word_file.write(word + '\n')
            return

        with io.open(board['file'], 'rb') as word_file:
            expected_words = set(word.strip() for word in word_file)

        if len(expected_words) != len(found_words):
            for word in found_words:
                if word not in expected_words:
                    print(word + ': found, not expected')
            for word in expected_words:
                if word not in found_words:
                    print(word + ': expected, not found')
Esempio n. 4
0
 def test_no_route_not_listed(self):
     """
     Words without an available route are not listed as valid results.
     """
     board = Board(rows=[
         ['A', 'B', 'C'],
     ])
     valid_words = set(['ACB'])
     self.assertEqual(
         Boggle(board=board, valid_words=valid_words).list_words(),
         set([]),
     )
Esempio n. 5
0
 def test_list_words(self):
     """
     A set of words with available routes is returned.
     """
     board = Board(rows=[
         ['A', 'B', 'C'],
         ['D', 'E', 'F'],
     ])
     valid_words = set(['ABC', 'DEF', 'GHI'])
     self.assertEqual(
         Boggle(board=board, valid_words=valid_words).list_words(),
         set(['ABC', 'DEF']),
     )
Esempio n. 6
0
def main():
    boards = [
        {
            'board': large_board,
            'file': 'large_board'
        },
        {
            'board': small_board,
            'file': 'small_board'
        },
    ]

    for board in boards:
        language = Language(dictionary_path="/usr/share/dict/words",
                            data_path="english_words.json")
        boggle = Boggle(board=Board(rows=board['board']),
                        valid_words=language.words)

        found_words = boggle.list_words()

        if not os.path.exists(board['file']):
            with io.open(board['file'], 'wb') as word_file:
                for word in found_words:
                    word_file.write(word + '\n')
            return

        with io.open(board['file'], 'rb') as word_file:
            expected_words = set(word.strip() for word in word_file)

        if len(expected_words) != len(found_words):
            for word in found_words:
                if word not in expected_words:
                    print(word + ': found, not expected')
            for word in expected_words:
                if word not in found_words:
                    print(word + ': expected, not found')