コード例 #1
0
    def testSimpleUVC(self):
        puzzle = PuzzleFactory.createSingleConstraintPuzzle(set([1,2]), 2, UniqueValueConstraint)
        
        cells = puzzle.grid.getCells()
        cells[0].setValue(1)

        self.assertEqual(cells[1].getPossibleValues(), set([2]), 
                         "Incorrect exclusion of value")
コード例 #2
0
 def testSimpleTSVC(self):
     """Test the basic properties of the total sum value constraint"""
     puzzle = PuzzleFactory.createSingleConstraintPuzzle(set([1,2]), 2, TotalSumValueConstraint)
     
     for cg in puzzle.getConstraintGroups():
         for constraint in cg.getConstraints():
             constraint.setTotalValue(3);
             constraint.applyConstraint()
             
     possibleValues = puzzle.grid.getCells()[1].getPossibleValues()
     self.assertTrue(1 in possibleValues, "Incorrectly removed value from constraint")
     self.assertTrue(2 in possibleValues, "Incorrectly removed value from constraint")
     
     puzzle.grid.getCells()[0].setValue(1)
     for cg in puzzle.getConstraintGroups():
         for constraint in cg.getConstraints():
             constraint.applyConstraint()
     possibleValues = puzzle.grid.getCells()[1].getPossibleValues()
     
     self.assertTrue(1 not in possibleValues, "Incorrectly kept value from constraint")
     self.assertTrue(2 in possibleValues, "Incorrectly removed value from constraint")