def test_long_valid(self): p = picross.Picross(5, [[3], [3], [3], [1], [1]], [[3], [0], [5], [0], [3]]); self.assertTrue(p.long_valid()) p.set(0, 0, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(1, 0, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(2, 0, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(3, 0, picross.Cell.FULL) self.assertFalse(p.long_valid()) p.set(2, 0, picross.Cell.EMPTY) self.assertFalse(p.long_valid()) p.set(3, 0, picross.Cell.EMPTY) self.assertFalse(p.long_valid()) p.set(2, 0, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(2, 2, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(3, 2, picross.Cell.FULL) self.assertTrue(p.long_valid()) p.set(4, 2, picross.Cell.FULL) self.assertTrue(p.long_valid())
def test_str(self): p = picross.Picross(5, [[1], [1], [1], [1], [1]], [[5], [0], [0], [0], [0]]); self.assertEqual("?????\n?????\n?????\n?????\n?????\n", str(p)) for x in range(5): p.set(x, 0, picross.Cell.FULL) self.assertEqual("#####\n?????\n?????\n?????\n?????\n", str(p)) for x in range(5): p.set(x, 1, picross.Cell.EMPTY) self.assertEqual("#####\n \n?????\n?????\n?????\n", str(p))
def test_complete(self): p = picross.Picross(5, [[1], [1], [1], [1], [1]], [[5], [0], [0], [0], [0]]); self.assertFalse(p.complete()); for i in range(5): p.set(i, 0, picross.Cell.FULL) self.assertFalse(p.complete()); for i in range(5): self.assertFalse(p.complete()); for j in range(1, 5): self.assertFalse(p.complete()); p.set(i, j, picross.Cell.EMPTY) self.assertTrue(p.complete());
def test_valid(self): p = picross.Picross(5, [[1], [1], [1], [1], [1]], [[5], [0], [0], [0], [0]]); self.assertTrue(p.valid()) p.set(0, 0, picross.Cell.FULL) p.set(1, 0, picross.Cell.FULL) p.set(2, 0, picross.Cell.FULL) p.set(3, 0, picross.Cell.FULL) p.set(4, 0, picross.Cell.FULL) self.assertTrue(p.valid()) p.set(4, 0, picross.Cell.EMPTY) self.assertFalse(p.valid()) p.set(4, 0, picross.Cell.UNKNOWN) self.assertTrue(p.valid())
def test_sums_do_not_match(self): with self.assertRaises(AssertionError): p = picross.Picross(5, [[1], [1], [1], [0], [0]], [[1], [1], [0], [0], [0]]);
def test_not_enough_weights_horizontals(self): with self.assertRaises(AssertionError): p = picross.Picross(5, [[0], [0], [0], [0], [0]], [[0], [0], [0], [0]]);
def test_empty_grid(self): p = picross.Picross(5, [[0], [0], [0], [0], [0]], [[0], [0], [0], [0], [0]]);
#!/usr/bin/python # -*- coding: utf8 -*-" import picross import ownd # Example from https://en.wikipedia.org/wiki/Nonogram p = picross.Picross( 11, [[0], [9], [9], [2, 2], [2, 2], [4], [4], [0], [0], [0], [0]], [[0], [4], [6], [2, 2], [2, 2], [6], [4], [2], [2], [2], [0]]) p = picross.Picross( 20, [[5, 8], [5, 5, 1], [1, 3, 1, 4], [3, 1, 6], [11, 4], [11, 6], [4, 6, 6], [2, 3, 6], [3, 1, 1, 1, 7], [1, 1, 1, 3, 3], [1, 1, 8], [1, 1, 7, 1], [3, 3, 1], [1, 3, 4, 1], [1, 1, 4], [2, 2, 4], [2, 3, 2], [4, 3], [4, 1], [6, 1]], [[8, 4], [5, 2], [3, 2, 1, 1], [7, 1, 1], [2, 3, 1, 3], [7, 3], [3, 5, 2], [8, 2], [8], [5, 1], [1, 4, 7], [3, 3, 3], [4, 3, 4], [5, 4, 1], [16], [1, 13], [1, 5, 7], [1, 6, 2], [1, 9], [2, 6]]) p = picross.Picross( 25, [[7, 7], [3, 7], [2, 6], [2, 1, 4, 1], [2, 9, 1, 1, 2], [2, 3, 5, 1], [4, 4, 3, 2], [3, 1, 3, 5], [3, 5, 1, 1, 1, 1], [2, 1, 1, 3, 2], [7, 4], [1, 6, 3], [1, 3, 7, 8], [5, 4, 8], [7, 1, 5, 4], [7, 1, 2, 3], [7, 2, 3], [10, 2, 1], [2, 6, 4, 5], [4, 10], [3, 1, 8], [3, 3, 3], [2, 4, 3], [2, 2, 8], [1, 3, 4, 8]], [[2, 5, 1, 7, 1], [10, 6], [3, 3, 5], [1, 1, 1, 6, 1], [1, 8, 2], [1, 1, 3, 1, 5, 2], [1, 1, 1, 6], [1, 5, 3], [5, 3, 5], [5, 3, 5], [4, 3, 5], [1, 5, 3], [1, 5, 1], [1, 7, 1], [1, 1, 2, 2], [1, 1, 1, 2, 3], [4, 4, 1, 2], [8, 1, 13], [3, 20], [5, 6, 6], [3, 4, 3, 3], [3, 3, 3, 2], [2, 13], [1, 1, 5, 7], [3, 5, 7]])