Esempio n. 1
0
    def test_infer_new_key_from_word_inconsistent(self):
        code_map = CodeMap({9: 'A'})
        sequence = ('A', 3, 4)
        word = 'ASS'

        with self.assertRaises(ValueError):
            code_map.infer_new_key_from_word(sequence, word)
Esempio n. 2
0
    def test_populates_grid_from_map(self):
        word_list = {
            'A',
            'ARE',
            'AREA',
            'OR',
            'ORE',
            'RARE',
            'REAR',
            'ROAR',
        }
        initial_grid = Grid([
            [None, 1, None],
            [2, 3, 4],
            [None, 4, None],
            [None, 1, None],
        ])
        initial_key = CodeMap({3: 'R', 4: 'E'})

        grid, key = solver.solve(initial_grid, initial_key, word_list)

        self.assertEqual(key, CodeMap({1: 'A', 2: 'O', 3: 'R', 4: 'E'}))
        self.assertEqual(
            grid,
            Grid([
                [None, 'A', None],
                ['O', 'R', 'E'],
                [None, 'E', None],
                [None, 'A', None],
            ]))
Esempio n. 3
0
    def test_infer_new_key_from_word_4(self):
        code_map = CodeMap({2: 'O', 3: 'R', 4: 'E'})
        sequence = (1, 'R', 'E', 1)
        word = 'AREA'

        result = code_map.infer_new_key_from_word(sequence, word)

        self.assertEqual(result, CodeMap({1: 'A', 2: 'O', 3: 'R', 4: 'E'}))
Esempio n. 4
0
    def test_infer_new_key_from_word(self):
        code_map = CodeMap({9: 'A'})
        sequence = ('A', 3, 4)
        word = 'ARE'

        result = code_map.infer_new_key_from_word(sequence, word)

        self.assertEqual(result, CodeMap({3: 'R', 4: 'E', 9: 'A'}))
Esempio n. 5
0
    def test_solve_sequences(self):
        key = CodeMap({1: 'A'})
        sequences = [
            (1, ),
            (1, 2),
            (3, 1, 2),
            (1, 3),
        ]

        result = solver.solve_sequences(key, sequences,
                                        {s: self.word_list
                                         for s in sequences})

        self.assertEqual(result, CodeMap({
            1: 'A',
            2: 'T',
            3: 'S',
        }))
Esempio n. 6
0
    def test_solves_codeword(self, mock_load_grid, mock_load_map,
                             mock_load_word_list, mock_solve):
        grid = Grid([])
        code_map = CodeMap({})
        word_list = set()

        mock_load_grid.return_value = grid
        mock_load_map.return_value = code_map
        mock_load_word_list.return_value = word_list

        codeword.main('grid', 'map', 'word_list')

        mock_solve.assert_called_with(grid, code_map, word_list)
Esempio n. 7
0
    def test_creates_map(self, mock_load_json):
        mock_load_json.return_value = {
            '2': 'T',
            '9': 'P',
            '17': 'E',
        }
        expected_map = CodeMap({
            2: 'T',
            9: 'P',
            17: 'E',
        })

        code_map = codeword.loaders.load_map('map_28.json')

        self.assertEquals(code_map, expected_map)
Esempio n. 8
0
    def test_repr_0(self):
        code_map = CodeMap({})

        self.assertEqual(repr(code_map), 'CodeMap({})')
Esempio n. 9
0
    def test_str_1(self):
        code_map = CodeMap({1: 'A'})

        self.assertEqual(str(code_map), 'A' + ('.' * 25))
Esempio n. 10
0
    def test_str_9(self):
        code_map = CodeMap({9: 'A'})

        self.assertEqual(str(code_map), '........A' + ('.' * 17))
Esempio n. 11
0
    def test_str_0(self):
        code_map = CodeMap({})

        self.assertEqual(str(code_map), '.' * 26)
Esempio n. 12
0
    def test_eq_0_1(self):
        a = CodeMap({})
        b = CodeMap({1: 'A'})

        self.assertNotEqual(a, b)
Esempio n. 13
0
    def test_eq_0_0(self):
        a = CodeMap({})
        b = CodeMap({})

        self.assertEqual(a, b)
Esempio n. 14
0
    def test_repr_2x(self):
        code_map = CodeMap({1: 'A', 13: 'Z'})

        self.assertEqual(repr(code_map), 'CodeMap({1: \'A\', 13: \'Z\'})')
Esempio n. 15
0
    def test_repr_1(self):
        code_map = CodeMap({1: 'A'})

        self.assertEqual(repr(code_map), 'CodeMap({1: \'A\'})')