From d84377c9242401a7d870e5e544c864edda790238 Mon Sep 17 00:00:00 2001 From: DannyAbdi <dannyabdi13@gmail.com> Date: Sat, 30 Mar 2024 04:43:38 +0000 Subject: [PATCH] Created test class for Expectimax class --- testExpectimax.py | 69 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 testExpectimax.py diff --git a/testExpectimax.py b/testExpectimax.py new file mode 100644 index 0000000..d456122 --- /dev/null +++ b/testExpectimax.py @@ -0,0 +1,69 @@ +import unittest +from expectimax import Expectimax + + +class TestExpectimax(unittest.TestCase): + + def test_valid_scenario(self): + maze = [[0, 0, 0], + [0, 1, 0], + [0, 0, 0]] + expectimax_solver = Expectimax(maze) + player_position = (0, 0) + enemy_position = (2, 2) + depth = 3 + maximizing_player = True + result = expectimax_solver.expectimax(player_position, enemy_position, depth, maximizing_player) + self.assertIsNotNone(result) + + def test_invalid_scenario_negative_depth(self): + maze = [[0, 0, 0], + [0, 1, 0], + [0, 0, 0]] + expectimax_solver = Expectimax(maze) + player_position = (0, 0) + enemy_position = (2, 2) + depth = -1 + maximizing_player = True + with self.assertRaises(ValueError): + expectimax_solver.expectimax(player_position, enemy_position, depth, maximizing_player) + + def test_no_valid_moves(self): + maze = [[1, 1, 1], + [1, 1, 1], + [1, 1, 1]] + expectimax_solver = Expectimax(maze) + player_position = (0, 0) + enemy_position = (2, 2) + depth = 3 + maximizing_player = True + result = expectimax_solver.expectimax(player_position, enemy_position, depth, maximizing_player) + self.assertEqual(result, 0) + + def test_game_over(self): + maze = [[0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + expectimax_solver = Expectimax(maze) + player_position = (0, 0) + enemy_position = (2, 2) + depth = 3 + maximizing_player = True + result = expectimax_solver.expectimax(player_position, enemy_position, depth, maximizing_player) + self.assertEqual(result, 0) + + def test_max_depth(self): + maze = [[0, 0, 0], + [0, 0, 0], + [0, 0, 0]] + expectimax_solver = Expectimax(maze) + player_position = (0, 0) + enemy_position = (2, 2) + depth = 10 + maximizing_player = True + result = expectimax_solver.expectimax(player_position, enemy_position, depth, maximizing_player) + self.assertIsNotNone(result) + + +if __name__ == '__main__': + unittest.main() -- GitLab