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)
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)
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)
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)
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)
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
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
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)
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)
def test_eight_queens(self): solver = SolverContext(8, 8, queen=8) for _ in solver.solve(): pass self.assertEquals(solver.result_counter, 92)
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)
def test_instanciation(self): solver = SolverContext(3, 3, king=2, queen=7) self.assertEquals(solver.length, 3) self.assertEquals(solver.height, 3) self.assertDictContainsSubset( {King.uid: 2, Queen.uid: 7}, solver.pieces)