aboutsummaryrefslogtreecommitdiff
path: root/diplomacy/tests/test_datc_no_check.py
diff options
context:
space:
mode:
authorPhilip Paquette <pcpaquette@gmail.com>2018-09-26 07:48:55 -0400
committerPhilip Paquette <pcpaquette@gmail.com>2019-04-18 11:14:24 -0400
commit6187faf20384b0c5a4966343b2d4ca47f8b11e45 (patch)
tree151ccd21aea20180432c13fe4b58240d3d9e98b6 /diplomacy/tests/test_datc_no_check.py
parent96b7e2c03ed98705754f13ae8efa808b948ee3a8 (diff)
Release v1.0.0 - Diplomacy Game Engine - AGPL v3+ License
Diffstat (limited to 'diplomacy/tests/test_datc_no_check.py')
-rw-r--r--diplomacy/tests/test_datc_no_check.py105
1 files changed, 105 insertions, 0 deletions
diff --git a/diplomacy/tests/test_datc_no_check.py b/diplomacy/tests/test_datc_no_check.py
new file mode 100644
index 0000000..59e5419
--- /dev/null
+++ b/diplomacy/tests/test_datc_no_check.py
@@ -0,0 +1,105 @@
+# ==============================================================================
+# Copyright (C) 2019 - Philip Paquette
+#
+# This program is free software: you can redistribute it and/or modify it under
+# the terms of the GNU Affero General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option) any
+# later version.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
+# details.
+#
+# You should have received a copy of the GNU Affero General Public License along
+# with this program. If not, see <https://www.gnu.org/licenses/>.
+# ==============================================================================
+""" DATC Test Cases (Using rule NO_CHECK)
+ - Contains the diplomacy adjudication test cases (without order validation)
+"""
+from diplomacy.engine.game import Game
+from diplomacy.tests.test_datc import TestDATC as RootDATC
+
+# -----------------
+# DATC TEST CASES (Without order validation)
+# -----------------
+class TestDATCNoCheck(RootDATC):
+ """ DATC test cases"""
+
+ @staticmethod
+ def create_game():
+ """ Creates a game object"""
+ game = Game()
+ game.add_rule('NO_CHECK')
+ return game
+
+ @staticmethod
+ def check_results(game, unit, value, phase='M'):
+ """ Checks adjudication results """
+ # pylint: disable=too-many-return-statements
+ if not game:
+ return False
+
+ result = game.result_history.last_value()
+
+ # Checking if the results contain duplicate values
+ unit_result = result.get(unit, [])
+ if len(unit_result) != len(set(unit_result)):
+ raise RuntimeError('Duplicate values detected in %s' % unit_result)
+
+ # Done self.processing a retreats phase
+ if phase == 'R':
+ if value == 'void' and 'void' in unit_result:
+ return True
+ if value == '':
+ success = unit not in game.popped and unit_result == []
+ if not success:
+ print('Results: %s - Expected: []' % result.get(unit, '<Not Found>'))
+ return success
+
+ success = unit in game.popped and value in unit_result
+ if not success:
+ print('Results: %s - Expected: %s' % (result.get(unit, '<Not Found>'), value))
+ return success
+
+ # Done self.processing a retreats phase
+ if phase == 'A':
+ if value == 'void' and 'void' in unit_result:
+ return True
+ success = value == unit_result
+ if not success:
+ print('Results: %s - Expected: %s' % (result.get(unit, '<Not Found>'), value))
+ return success
+
+ order_status = game.get_order_status(unit=unit)
+
+ # >>>>>>>>>>>>>>>>>>>>>>>>
+ # For NO_CHECK, we expect to find the unit in game.orderable_units
+ # But we require that the order is marked as 'void'
+ # As opposed to a regular game, where an invalid order is dropped
+ # <<<<<<<<<<<<<<<<<<<<<<<<
+ # Invalid order
+ if value == 'void':
+ if 'void' in result.get(unit, []):
+ return True
+ return False
+
+ # Invalid unit
+ if unit not in game.command:
+ print('Results: %s NOT FOUND - Expected: %s' % (unit, value))
+ return False
+
+ # Expected no errors
+ if value == '':
+ if order_status:
+ print('Results: %s - Expected: []' % order_status)
+ return False
+ return True
+
+ # Incorrect error
+ if value not in game.get_order_status(unit=unit):
+ print('Results: %s - Expected: %s' % (order_status, value))
+ return False
+
+ # Correct value
+ return True