From 2330a30021c689f64dbba3b07300826822d514f2 Mon Sep 17 00:00:00 2001 From: Marek Wolan Date: Fri, 2 Jun 2023 13:08:11 +0100 Subject: [PATCH] Get observation tests passing --- tests/test_observation_space.py | 64 ++++++++++++++++++++++++++++++--- 1 file changed, 60 insertions(+), 4 deletions(-) diff --git a/tests/test_observation_space.py b/tests/test_observation_space.py index 314728ae..3fe71003 100644 --- a/tests/test_observation_space.py +++ b/tests/test_observation_space.py @@ -79,9 +79,65 @@ class TestNodeLinkTable: # * 6 columns (four fixed and two for the services) assert env.env_obs.shape == (5, 6) - # def test_value(self, env: Primaite): - # """""" - # ... + def test_value(self, env: Primaite): + """Test that the observation is generated correctly. + + The laydown has: + * 3 nodes (2 service nodes and 1 active node) + * 2 services + * 2 links + + Both nodes have both services, and all states are GOOD, therefore the expected observation value is: + + * Node 1: + * 1 (id) + * 1 (good hardware state) + * 1 (good OS state) + * 1 (good file system state) + * 1 (good service1 state) + * 1 (good service2 state) + * Node 2: + * 2 (id) + * 1 (good hardware state) + * 1 (good OS state) + * 1 (good file system state) + * 1 (good service1 state) + * 1 (good service2 state) + * Node 3 (active node): + * 3 (id) + * 1 (good hardware state) + * 1 (good OS state) + * 1 (good file system state) + * 0 (doesn't have service1) + * 0 (doesn't have service2) + * Link 1: + * 4 (id) + * 0 (n/a hardware state) + * 0 (n/a OS state) + * 0 (n/a file system state) + * 0 (no traffic for service1) + * 0 (no traffic for service2) + * Link 2: + * 5 (id) + * 0 (good hardware state) + * 0 (good OS state) + * 0 (good file system state) + * 0 (no traffic service1) + * 0 (no traffic for service2) + """ + act = np.asarray([0, 0, 0, 0]) + obs, reward, done, info = env.step(act) + + assert np.array_equal( + obs, + [ + [1, 1, 1, 1, 1, 1], + [2, 1, 1, 1, 1, 1], + [3, 1, 1, 1, 0, 0], + [4, 0, 0, 0, 0, 0], + [5, 0, 0, 0, 0, 0], + ], + ) @pytest.mark.env_config_paths( @@ -96,7 +152,7 @@ class TestNodeStatuses: def test_obs_shape(self, env: Primaite): """Try creating env with NodeStatuses as the only component.""" - assert env.env_obs.shape == (15) + assert env.env_obs.shape == (15,) def test_values(self, env: Primaite): """Test that the hardware and software states are encoded correctly.