@@ -27,8 +27,8 @@ def test_single_model(self):
2727
2828 m = OneInputOneOutputOneEventLM ()
2929
30- with self . assertRaises ( ValueError ):
31- EnsembleModel ([m ])
30+
31+ EnsembleModel ([m ])
3232
3333 def test_wrong_type (self ):
3434 # An ensemble model with a non-model should raise an exception
@@ -43,6 +43,48 @@ def test_wrong_type(self):
4343 with self .assertRaises (TypeError ):
4444 EnsembleModel ([m , m , m , 77 ])
4545
46+ def test_single_model (self ):
47+ """
48+ This tests that the ensemble model works with a single model, ensuring that inputs, states, outputs, and events are correctly handled.
49+ """
50+ m = OneInputOneOutputOneEventLM ()
51+ em = EnsembleModel ([m ])
52+
53+ # inputs, states, outputs, and events should be the same as the single model
54+ self .assertSetEqual (set (em .inputs ), {'u1' })
55+ self .assertSetEqual (set (em .states ), {'x1' })
56+ self .assertSetEqual (set (em .outputs ), {'z1' })
57+ self .assertSetEqual (set (em .events ), {'x1 == 10' })
58+
59+ # Initialize
60+ x_t0 = em .initialize ()
61+ self .assertEqual (x_t0 ['x1' ], 0 )
62+
63+ # State transition
64+ u = em .InputContainer ({'u1' : 1 })
65+ x_t1 = em .next_state (x_t0 , u , 1 )
66+ self .assertEqual (x_t1 ['x1' ], 1 )
67+
68+ # Output
69+ z = em .output (x_t1 )
70+ self .assertEqual (z ['z1' ], 1 )
71+
72+ # Event state
73+ es = em .event_state (x_t1 )
74+ self .assertEqual (es ['x1 == 10' ], 0.9 )
75+
76+ # Threshold met
77+ self .assertFalse (em .threshold_met (x_t1 )['x1 == 10' ])
78+
79+ # Transition again
80+ x_t2 = em .next_state (x_t1 , u , 2 )
81+
82+ # Threshold met
83+ # x1 == 3
84+ self .assertFalse (em .threshold_met (x_t2 )['x1 == 10' ])
85+
86+
87+
4688 def test_two_models_identical (self ):
4789 """
4890 This tests that the ensemble model works with two identical model-types with identical states, inputs, etc., one with slightly altered parameters.
0 commit comments