Exemplo n.º 1
0
 def test_game_problem_generator(self):
     # Game problem tests
     app = FTPtsGame()
     app.generate_problem(problem=[6, 0, 0, 7, 0])
     app.start()
     self.assertEqual((0, 0, 0, 6, 7), app.get_current_problem())
     self.assertEqual(1, app.get_total_solution_number())
     app.stop()
Exemplo n.º 2
0
    def test_game_problem_generator(self):
        # Game problem tests
        app = FTPtsGame()
        app.generate_problem('database', minimum_solutions=20, maximum_solutions=30)
        app.start()
        self.assertIn(app.get_current_problem(), DATABASE_42)
        self.assertIn(app.get_total_solution_number(), list(range(20, 31)))
        app.stop()

        app.generate_problem('database')
        app.start()
        self.assertIn(app.get_current_problem(), DATABASE_42)
        self.assertIn(app.get_total_solution_number(), list(range(1, 101)))
        app.stop()

        app.generate_problem('custom')
        app.start()
        self.assertIn(app.get_current_problem(), DATABASE_42)
        app.stop()

        self.assertRaises(ValueError, app.generate_problem, method='custom', problem='12345')
        self.assertRaises(TypeError, app.generate_problem, method='custom', problem=123)
        self.assertRaises(ValueError, app.generate_problem, method='custom', problem=[0, 0, 0, 0, 0])
        
        app.generate_problem('custom', problem=[6, 0, 0, 7, 0])
        app.start()
        self.assertEqual((0, 0, 0, 6, 7), app.get_current_problem())
        app.stop()

        app.generate_problem(method='probability')
        app.start()
        self.assertIn(app.get_current_problem(), DATABASE_42)
        app.stop()
        self.assertRaises(TypeError, app.generate_problem, method='probability', prob=123)
        self.assertRaises(ValueError, app.generate_problem, method='probability', prob=[1, 2, 2])
        test_prob = [0] * len(DATABASE_42.keys())
        r = random.randint(0, len(DATABASE_42.keys()) - 1)
        test_prob[r] = 100
        app.generate_problem('probability', prob=test_prob)
        app.start()
        self.assertEqual(list(DATABASE_42.keys())[r], app.get_current_problem()) 
        app.stop()

        self.assertRaises(TypeError, app.generate_problem, method='wrong_method', problem=[6, 7, 0, 0, 0])