Esempio n. 1
0
def test_is_complete():
    chunksize, raw_puzzle = get_valid_complete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.is_solved() == True
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.is_solved() == False
Esempio n. 2
0
def test_validate_all_chunks():
    """
    Does a known valid puizzle validate all chunks?
    """
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_all_chunks() == True
    chunksize, raw_puzzle = get_valid_complete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_all_chunks() == True
Esempio n. 3
0
def test_validate_row():
    """
    Does a known valid single incomplete row validate?
    """
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_row(0) == True
    chunksize, raw_puzzle = get_valid_complete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_row(0) == True
    chunksize, raw_puzzle = get_invalid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_row(0) == False
Esempio n. 4
0
def test_validate_chunk_by_cell_index():
    """
    Does a known valid single incomplete chunk validate?
    """
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    for ccc in range(0, 9):
        assert puzzle.validate_chunk_for_cell(ccc, ccc) == True
    chunksize, raw_puzzle = get_invalid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    for ccc in range(0, 3):
        assert puzzle.validate_chunk_for_cell(ccc, ccc) == False
    for ccc in range(3, 9):
        assert puzzle.validate_chunk_for_cell(ccc, ccc) == True
Esempio n. 5
0
def test_validate_chunk():
    """
    Does a known valid single incomplete chunk validate?
    """
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_chunk(0, 0) == True
    assert puzzle.validate_chunk(1, 1) == True
    assert puzzle.validate_chunk(2, 2) == True
    chunksize, raw_puzzle = get_valid_complete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.validate_chunk(0, 0) == True
    assert puzzle.validate_chunk(1, 1) == True
    assert puzzle.validate_chunk(2, 2) == True
Esempio n. 6
0
def test_reduce():
    chunksize, raw_puzzle = get_easy_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.get(1,
                      0) == set(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
    puzzle.reduce_cell(1, 0)
    assert puzzle.get(1, 0) == set(["3"])
Esempio n. 7
0
def test_solve():
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    op = solver.format_puzzle(puzzle)
    print()
    print(op)
    score, puzzle = solver.solve(puzzle)
    op = solver.format_puzzle(puzzle)
    print()
    print(op)
    assert True
Esempio n. 8
0
def test_print_puzzle():
    chunksize, raw_puzzle = get_valid_complete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    op = solver.format_puzzle(puzzle)
    assert op == """{5} {3} {4} {6} {7} {8} {9} {1} {2}
{6} {7} {2} {1} {9} {5} {3} {4} {8}
{1} {9} {8} {3} {4} {2} {5} {6} {7}
{8} {5} {9} {7} {6} {1} {4} {2} {3}
{4} {2} {6} {8} {5} {3} {7} {9} {1}
{7} {1} {3} {9} {2} {4} {8} {5} {6}
{9} {6} {1} {5} {3} {7} {2} {8} {4}
{2} {8} {7} {4} {1} {9} {6} {3} {5}
{3} {4} {5} {2} {8} {6} {1} {7} {9}"""
    print()
    print(op)
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    op = solver.format_puzzle(puzzle)
    print()
    print(op)
Esempio n. 9
0
def test_puzzle_obj():
    """Test a puzzle obj wraps the raw_data
    nicely and that all the methods work ok
    according to:

            8 _ _  _ 9 _  2 5 _
            5 _ _  _ 7 _  6 _ 1
            _ _ _  8 _ _  _ 9 4

            _ 7 5  9 4 _  _ _ _
            6 4 _  7 _ 8  _ _ _
            _ _ _  _ 2 6  4 7 _

            9 2 _  _ _ 4  _ _ _
            7 _ 8  _ 1 _  _ _ 2
            _ 5 6  _ 8 _  _ _ 9

    """
    chunksize, raw_puzzle = get_valid_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.get(0, 0) == set(["8"])
    assert puzzle.get(1,
                      0) == set(["1", "2", "3", "4", "5", "6", "7", "8", "9"])
Esempio n. 10
0
def test_find_cells():
    chunksize, raw_puzzle = get_easy_incomplete()
    puzzle = solver.Puzzle(chunksize, raw_puzzle)
    assert puzzle.find_first_unsolved_cell() == (1, 0)
    assert puzzle.find_simplest_unsolved_cell() == (1, 0)