2023-07-17 19:57:34 +01:00
|
|
|
# Crown Owned Copyright (C) Dstl 2023. DEFCON 703. Shared in confidence.
|
2023-07-03 17:25:21 +01:00
|
|
|
import pytest
|
2023-06-22 15:34:13 +01:00
|
|
|
|
2023-07-03 09:46:52 +01:00
|
|
|
from primaite.config.lay_down_config import data_manipulation_config_path
|
2023-07-03 10:08:25 +01:00
|
|
|
from primaite.nodes.node_state_instruction_red import NodeStateInstructionRed
|
2023-06-22 15:34:13 +01:00
|
|
|
from tests import TEST_CONFIG_ROOT
|
|
|
|
|
|
2023-07-03 20:40:38 +01:00
|
|
|
|
2023-07-03 17:25:21 +01:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
|
"temp_primaite_session",
|
|
|
|
|
[
|
|
|
|
|
[
|
|
|
|
|
TEST_CONFIG_ROOT / "test_random_red_main_config.yaml",
|
|
|
|
|
data_manipulation_config_path(),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
indirect=True,
|
|
|
|
|
)
|
|
|
|
|
def test_random_red_agent_behaviour(temp_primaite_session):
|
|
|
|
|
"""Test that red agent POL is randomised each episode."""
|
2023-06-22 15:34:13 +01:00
|
|
|
list_of_node_instructions = []
|
2023-07-03 09:46:52 +01:00
|
|
|
|
2023-07-03 17:25:21 +01:00
|
|
|
with temp_primaite_session as session:
|
|
|
|
|
session.evaluate()
|
|
|
|
|
list_of_node_instructions.append(session.env.red_node_pol)
|
2023-06-22 15:34:13 +01:00
|
|
|
|
2023-07-03 17:25:21 +01:00
|
|
|
session.evaluate()
|
|
|
|
|
list_of_node_instructions.append(session.env.red_node_pol)
|
2023-07-03 09:46:52 +01:00
|
|
|
|
|
|
|
|
# compare instructions to make sure that red instructions are truly random
|
|
|
|
|
for index, instruction in enumerate(list_of_node_instructions):
|
|
|
|
|
for key in list_of_node_instructions[index].keys():
|
2023-07-03 10:08:25 +01:00
|
|
|
instruction: NodeStateInstructionRed = list_of_node_instructions[index][key]
|
2023-07-03 09:46:52 +01:00
|
|
|
print(f"run {index}")
|
|
|
|
|
print(f"{key} start step: {instruction.get_start_step()}")
|
|
|
|
|
print(f"{key} end step: {instruction.get_end_step()}")
|
|
|
|
|
print(f"{key} target node id: {instruction.get_target_node_id()}")
|
|
|
|
|
print("")
|
2023-06-22 15:34:13 +01:00
|
|
|
assert list_of_node_instructions[0].__ne__(list_of_node_instructions[1])
|