<commit_before>"""
Tests for a Boggle solver.
"""

import unittest
import io

from tempfile import mkstemp
from textwrap import dedent

from boggle.boggle import Board, Boggle, Language, Word, Position


class LanguageTests(unittest.TestCase):
    """
    Tests for `Language`.
    """

    def test_words(self):
        """
        A list of list of tiles is returned, each representing the words which
        can exist on a board.
        """
        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(dedent(u"""\
            ABC
             DEF
            GHI  """))

        self.assertEqual(
            sorted(Language(dictionary_path=path).words),
            sorted([['A', 'B', 'C'], ['G', 'H', 'I'], ['D', 'E', 'F']]),
        )

    def test_short_words_not_listed(self):
        """
        Words shorter than 3 letters are not listed as valid results.
        """
        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(u"AB")

        self.assertEqual(
            Language(dictionary_path=path).words,
            [],
        )


    def test_json_dumped(self):
        """
        If a data path is given, valid words are dumped there.
        """
        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(u"AB")

        self.assertEqual(
            Language(dictionary_path=path).words,
            [],
        )

class BoggleTests(unittest.TestCase):
    """
    Tests for `Boggle`.
    """

    def test_list_words(self):
        """
        A set of words with available routes is returned.
        """
        board = Board(rows=[
            ['A', 'B', 'C'],<commit_msg>Test for json dumping<commit_after>"""
Tests for a Boggle solver.
"""

import unittest
import io
import os
import json

from tempfile import mkstemp
from textwrap import dedent

from boggle.boggle import Board, Boggle, Language, Word, Position


class LanguageTests(unittest.TestCase):
    """
    Tests for `Language`.
    """

    def test_words(self):
        """
        A list of list of tiles is returned, each representing the words which
        can exist on a board.
        """
        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(dedent(u"""\
            ABC
             DEF
            GHI  """))

        self.assertEqual(
            sorted(Language(dictionary_path=path).words),
            sorted([['A', 'B', 'C'], ['G', 'H', 'I'], ['D', 'E', 'F']]),
        )

    def test_short_words_not_listed(self):
        """
        Words shorter than 3 letters are not listed as valid results.
        """
        file, path = mkstemp()
        with io.open(path, mode='w') as file:
            file.write(u"AB")

        self.assertEqual(
            Language(dictionary_path=path).words,
            [],
        )

    def test_json_dumped(self):
        """
        If a data path is given, valid words are dumped there as JSON, in a
        dict keyed by the dictionary path.
        """
        file, dictionary_path = mkstemp()
        with io.open(dictionary_path, mode='w') as file:
            file.write(u"ABC")

        file, data_path = mkstemp()
        os.remove(data_path)
        Language(dictionary_path=dictionary_path, data_path=data_path)

        expected = json.dumps(
            {
                dictionary_path: [['A', 'B', 'C']],
            },
        )

        with io.open(data_path, mode='r') as file:
            self.assertEqual(file.read(), expected)


class BoggleTests(unittest.TestCase):
    """
    Tests for `Boggle`.
    """

    def test_list_words(self):
        """
        A set of words with available routes is returned.
        """
        board = Board(rows=[
            ['A', 'B', 'C'],
{'fraction_non_alphanumeric': 0.12781561026715557, 'fraction_numerical': 0.0005238344683080147, 'mean_word_length': 1.8779201205727205, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '92069', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1103, 'n_words': 319}