Exemplo n.º 1
0
    def test_set_possible_value(self):

        c = Cell(9, 0, 0, poss_vals=frozenset({1}))

        c2 = c.set_possible_value(2)
        self.assertEqual({1}, c.possible_vals())
        self.assertEqual({1, 2}, c2.possible_vals())

        # Out of range checks
        with self.assertRaises(ValueError):
            c.set_possible_value(0)

        with self.assertRaises(ValueError):
            c.set_possible_value(-1)

        with self.assertRaises(ValueError):
            c.set_possible_value(10)

        # Make sure setting a possible value on a set value doesn't change the value.
        c = Cell(9, 0, 0, 4)
        c2 = c.set_possible_value(5)

        self.assertFalse(c2.has_possible_val(5))
        self.assertEqual(-1, c2.possible_count())
        self.assertEqual(4, c2.value())
Exemplo n.º 2
0
    def test_modify_initial_cell(self):

        c = Cell(9, 0, 0, 4, is_initial=True)

        with self.assertRaises(ValueError):
            c.set_possible_value(3)

        with self.assertRaises(ValueError):
            c.set_value(5)

        with self.assertRaises(ValueError):
            c.clear_value(6)

        with self.assertRaises(ValueError):
            c.clear_possible_value(2)