示例#1
0
def main():
    parser = argparse.ArgumentParser(description="A sudoku resolver")
    parser.add_argument("-v", "--verbose", action="count", default=0, help="increase output verbosity (-vv or --verbose=2 for even more verbosity)")
    parser.add_argument("-g", "--grid", help="a grid directly on the command line (9x9 digits and dots, with or without \\n)")
    parser.add_argument("gridAsFile", type=argparse.FileType('r'), nargs='?', help="a file containing the grid to solve")
    args = parser.parse_args()

    if not args.gridAsFile and not args.grid:
        parser.error("A grid must be provided.")

    logLevel = [logging.WARNING, logging.INFO, logging.DEBUG][args.verbose]
    logging.basicConfig(format='%(levelname)s: %(message)s', level=logLevel)

    grid = prepareGrid(args.gridAsFile, args.grid)
    print "Loaded grid :"
    print grid.display()

    gridResolution = GridResolution(grid)
    if gridResolution.solve():
        logging.info("Grid solved completely !")
    else:
        logging.info("Solving stopped without being able to finish the grid.")

    print "Final grid :"
    print grid.display()

    logging.info("Distribution of resolution strategies used :")
    for key, value in Stats.results().iteritems():
        logging.info("  {}\t : {} cell(s)".format(key, value))
示例#2
0
    def test_increment(self):
        Stats.increment("A resolution")
        Stats.increment("Another one")
        Stats.increment("A resolution")

        self.assertItemsEqual({"A resolution": 2, "Another one": 1}, Stats.results())
示例#3
0
    def test_increment_with_step(self):
        Stats.increment("A resolution", 1)
        Stats.increment("Another one", 2)
        Stats.increment("A resolution", 3)

        self.assertItemsEqual({"A resolution": 4, "Another one": 2}, Stats.results())
示例#4
0
 def test_initial_results(self):
     self.assertEqual({}, Stats.results())