Ejemplo n.º 1
0
 def test_tinyest_board(self):
     solver = SolverContext(1, 1, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
     ])
     self.assertEquals(solver.result_counter, 1)
Ejemplo n.º 2
0
 def test_two_rooks_four_knights(self):
     solver = SolverContext(4, 4, rook=2, knight=4)
     results = solver.solve()
     self.check_results(results, [
         [('Rook', 0, 3), ('Rook', 2, 1),
          ('Knight', 1, 0), ('Knight', 3, 0),
          ('Knight', 1, 2), ('Knight', 3, 2)],
         [('Rook', 0, 1), ('Rook', 2, 3),
          ('Knight', 1, 0), ('Knight', 3, 0),
          ('Knight', 1, 2), ('Knight', 3, 2)],
         [('Rook', 0, 0), ('Rook', 2, 2),
          ('Knight', 1, 1), ('Knight', 3, 1),
          ('Knight', 1, 3), ('Knight', 3, 3)],
         [('Rook', 0, 2), ('Rook', 2, 0),
          ('Knight', 1, 1), ('Knight', 3, 1),
          ('Knight', 1, 3), ('Knight', 3, 3)],
         [('Rook', 1, 0), ('Rook', 3, 2),
          ('Knight', 0, 1), ('Knight', 2, 1),
          ('Knight', 0, 3), ('Knight', 2, 3)],
         [('Rook', 3, 0), ('Rook', 1, 2),
          ('Knight', 0, 1), ('Knight', 2, 1),
          ('Knight', 0, 3), ('Knight', 2, 3)],
         [('Rook', 1, 3), ('Rook', 3, 1),
          ('Knight', 0, 0), ('Knight', 2, 0),
          ('Knight', 0, 2), ('Knight', 2, 2)],
         [('Rook', 1, 1), ('Rook', 3, 3),
          ('Knight', 0, 0), ('Knight', 2, 0),
          ('Knight', 0, 2), ('Knight', 2, 2)],
     ])
     self.assertEquals(solver.result_counter, 8)
Ejemplo n.º 3
0
 def test_two_rooks_four_knights(self):
     solver = SolverContext(4, 4, rook=2, knight=4)
     results = solver.solve()
     self.check_results(results, [
         [('Rook', 0, 3), ('Rook', 2, 1),
          ('Knight', 1, 0), ('Knight', 3, 0),
          ('Knight', 1, 2), ('Knight', 3, 2)],
         [('Rook', 0, 1), ('Rook', 2, 3),
          ('Knight', 1, 0), ('Knight', 3, 0),
          ('Knight', 1, 2), ('Knight', 3, 2)],
         [('Rook', 0, 0), ('Rook', 2, 2),
          ('Knight', 1, 1), ('Knight', 3, 1),
          ('Knight', 1, 3), ('Knight', 3, 3)],
         [('Rook', 0, 2), ('Rook', 2, 0),
          ('Knight', 1, 1), ('Knight', 3, 1),
          ('Knight', 1, 3), ('Knight', 3, 3)],
         [('Rook', 1, 0), ('Rook', 3, 2),
          ('Knight', 0, 1), ('Knight', 2, 1),
          ('Knight', 0, 3), ('Knight', 2, 3)],
         [('Rook', 3, 0), ('Rook', 1, 2),
          ('Knight', 0, 1), ('Knight', 2, 1),
          ('Knight', 0, 3), ('Knight', 2, 3)],
         [('Rook', 1, 3), ('Rook', 3, 1),
          ('Knight', 0, 0), ('Knight', 2, 0),
          ('Knight', 0, 2), ('Knight', 2, 2)],
         [('Rook', 1, 1), ('Rook', 3, 3),
          ('Knight', 0, 0), ('Knight', 2, 0),
          ('Knight', 0, 2), ('Knight', 2, 2)],
     ])
     self.assertEquals(solver.result_counter, 8)
Ejemplo n.º 4
0
 def test_tinyest_board(self):
     solver = SolverContext(1, 1, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
     ])
     self.assertEquals(solver.result_counter, 1)
Ejemplo n.º 5
0
 def test_wide_board(self):
     solver = SolverContext(4, 1, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
         [('King', 1, 0)],
         [('King', 2, 0)],
         [('King', 3, 0)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 6
0
 def test_long_board(self):
     solver = SolverContext(1, 4, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
         [('King', 0, 1)],
         [('King', 0, 2)],
         [('King', 0, 3)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 7
0
 def test_two_kings_one_rook(self):
     solver = SolverContext(3, 3, king=2, rook=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0), ('King', 2, 0), ('Rook', 1, 2)],
         [('King', 0, 0), ('King', 0, 2), ('Rook', 2, 1)],
         [('King', 2, 0), ('King', 2, 2), ('Rook', 0, 1)],
         [('King', 0, 2), ('King', 2, 2), ('Rook', 1, 0)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 8
0
 def test_two_kings_one_rook(self):
     solver = SolverContext(3, 3, king=2, rook=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0), ('King', 2, 0), ('Rook', 1, 2)],
         [('King', 0, 0), ('King', 0, 2), ('Rook', 2, 1)],
         [('King', 2, 0), ('King', 2, 2), ('Rook', 0, 1)],
         [('King', 0, 2), ('King', 2, 2), ('Rook', 1, 0)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 9
0
 def test_long_board(self):
     solver = SolverContext(1, 4, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
         [('King', 0, 1)],
         [('King', 0, 2)],
         [('King', 0, 3)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 10
0
 def test_wide_board(self):
     solver = SolverContext(4, 1, king=1)
     results = solver.solve()
     self.check_results(results, [
         [('King', 0, 0)],
         [('King', 1, 0)],
         [('King', 2, 0)],
         [('King', 3, 0)],
     ])
     self.assertEquals(solver.result_counter, 4)
Ejemplo n.º 11
0
def run_scenario(params):
    """ Run one scenario and returns execution time and number of solutions.

    Also returns initial parameters in the response to keep the results
    associated with the initial context.
    """
    solver = SolverContext(**params)
    start = time.time()
    count = sum(1 for _ in solver.solve())
    execution_time = time.time() - start
    params.update({'solutions': count, 'execution_time': execution_time})
    return params
Ejemplo n.º 12
0
def run_scenario(params):
    """ Run one scenario and returns execution time and number of solutions.

    Also returns initial parameters in the response to keep the results
    associated with the initial context.
    """
    solver = SolverContext(**params)
    start = time.time()
    count = sum(1 for _ in solver.solve())
    execution_time = time.time() - start
    params.update({
        'solutions': count,
        'execution_time': execution_time})
    return params
Ejemplo n.º 13
0
 def test_single_queen(self):
     solver = SolverContext(3, 3, queen=1)
     results = solver.solve()
     self.check_results(results, [
         [('Queen', 0, 0)],
         [('Queen', 0, 1)],
         [('Queen', 0, 2)],
         [('Queen', 1, 0)],
         [('Queen', 1, 1)],
         [('Queen', 1, 2)],
         [('Queen', 2, 0)],
         [('Queen', 2, 1)],
         [('Queen', 2, 2)],
     ])
     self.assertEquals(solver.result_counter, 9)
Ejemplo n.º 14
0
 def test_single_queen(self):
     solver = SolverContext(3, 3, queen=1)
     results = solver.solve()
     self.check_results(results, [
         [('Queen', 0, 0)],
         [('Queen', 0, 1)],
         [('Queen', 0, 2)],
         [('Queen', 1, 0)],
         [('Queen', 1, 1)],
         [('Queen', 1, 2)],
         [('Queen', 2, 0)],
         [('Queen', 2, 1)],
         [('Queen', 2, 2)],
     ])
     self.assertEquals(solver.result_counter, 9)
Ejemplo n.º 15
0
 def test_big_family(self):
     solver = SolverContext(7, 7, king=2, queen=2, bishop=2, knight=1)
     for _ in solver.solve():
         pass
     self.assertEquals(solver.result_counter, 1000000)
Ejemplo n.º 16
0
 def test_eight_queens(self):
     solver = SolverContext(8, 8, queen=8)
     for _ in solver.solve():
         pass
     self.assertEquals(solver.result_counter, 92)
Ejemplo n.º 17
0
 def test_no_queen_solutions(self):
     solver = SolverContext(3, 3, queen=3)
     results = solver.solve()
     self.check_results(results, [])
     self.assertEquals(solver.result_counter, 0)
Ejemplo n.º 18
0
 def test_no_queen_solutions(self):
     solver = SolverContext(3, 3, queen=3)
     results = solver.solve()
     self.check_results(results, [])
     self.assertEquals(solver.result_counter, 0)
Ejemplo n.º 19
0
 def test_eight_queens(self):
     solver = SolverContext(8, 8, queen=8)
     for _ in solver.solve():
         pass
     self.assertEquals(solver.result_counter, 92)
Ejemplo n.º 20
0
 def test_big_family(self):
     solver = SolverContext(7, 7, king=2, queen=2, bishop=2, knight=1)
     for _ in solver.solve():
         pass
     self.assertEquals(solver.result_counter, 1000000)