Changeset 13794
 Timestamp:
 Oct 22, 2019 8:38:02 AM (3 weeks ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

branches/dev5819/Python/src/tests_jmodelica/simulation/test_assimulo_interface_fmi.py
r13791 r13794 59 59 input_object = (["u"],input_linear) 60 60 61 class Test_When: 61 class AssertWithMessage: 62 def __init__(self): 63 self.message = "" 64 def assert_equal_msg(self, actual, desired): 65 err_msg = "\nACTUAL: {}\nDESIRED: {}".format(actual, desired) 66 assert actual == desired, err_msg 67 68 class Test_When(AssertWithMessage): 62 69 @classmethod 63 70 def setUpClass(cls): … … 72 79 res = model.simulate(final_time=3.5) 73 80 74 assert res.final("nextTime") == 4.075 assert res.final("nextTime2") == 3.076 assert res.final("nextTime3") == 8.077 78 class Test_Sparse_Linear_Block :81 self.assert_equal_msg(res.final("nextTime"), 4.0) 82 self.assert_equal_msg(res.final("nextTime2"), 3.0) 83 self.assert_equal_msg(res.final("nextTime3"), 8.0) 84 85 class Test_Sparse_Linear_Block(AssertWithMessage): 79 86 @classmethod 80 87 def setUpClass(cls): … … 98 105 99 106 #Assert that sparse handling has no impact on the number of steps 100 assert res1.solver.statistics["nsteps"] == res2.solver.statistics["nsteps"]107 self.assert_equal_msg(res2.solver.statistics["nsteps"], res1.solver.statistics["nsteps"]) 101 108 N.testing.assert_almost_equal(res1.final("J1.w"), res2.final("J1.w"), 3) 102 109 … … 108 115 compiler_options={"generate_sparse_block_jacobian_threshold": 0}) 109 116 110 class Test_Time_Events_FMU10 :117 class Test_Time_Events_FMU10(AssertWithMessage): 111 118 @classmethod 112 119 def setUpClass(cls): … … 144 151 ev = model.get_event_info() 145 152 print(ev.nextEventTime) 146 assert ev.nextEventTime == 1153 self.assert_equal_msg(ev.nextEventTime, 1) 147 154 148 155 @testattr(stddist_full = True) … … 152 159 ev = model.get_event_info() 153 160 print(ev.nextEventTime) 154 assert ev.nextEventTime == 2155 assert ev.nextEventTime == model.get("p")161 self.assert_equal_msg(ev.nextEventTime, 2) 162 self.assert_equal_msg(ev.nextEventTime, model.get("p")) 156 163 157 164 @testattr(stddist_full = True) … … 161 168 ev = model.get_event_info() 162 169 print(ev.nextEventTime) 163 assert ev.nextEventTime == 1.5170 self.assert_equal_msg(ev.nextEventTime, 1.5) 164 171 165 172 @testattr(stddist_full = True) … … 169 176 model.initialize() 170 177 ev = model.get_event_info() 171 assert ev.upcomingTimeEvent == False172 assert model.get("x")== 2178 self.assert_equal_msg(ev.upcomingTimeEvent, False) 179 self.assert_equal_msg(model.get("x"), 2) 173 180 174 181 model.reset() … … 176 183 model.initialize() 177 184 178 assert ev.upcomingTimeEvent == False179 assert model.get("x") == 1185 self.assert_equal_msg(ev.upcomingTimeEvent, False) 186 self.assert_equal_msg(model.get("x"), 1) 180 187 181 188 @testattr(stddist_base = True) … … 185 192 ev = model.get_event_info() 186 193 print(ev.nextEventTime) 187 assert ev.nextEventTime == 0.5194 self.assert_equal_msg(ev.nextEventTime, 0.5) 188 195 189 196 model.simulate(options={"initialize":False}) 190 197 191 198 print("i (should be 2): ", model.get("i")) 192 assert model.get("i") == 2199 self.assert_equal_msg(model.get("i"), 2) 193 200 194 201 @testattr(stddist_base = True) … … 198 205 ev = model.get_event_info() 199 206 print(ev.nextEventTime) 200 assert ev.nextEventTime == 0.5207 self.assert_equal_msg(ev.nextEventTime, 0.5) 201 208 202 209 model.simulate(options={"initialize":False}) 203 210 204 211 print("i (should be 2): ", model.get("i")) 205 assert model.get("i") == 2212 self.assert_equal_msg(model.get("i"), 2) 206 213 207 214 @testattr(stddist_base = True) … … 211 218 ev = model.get_event_info() 212 219 print(ev.nextEventTime) 213 assert ev.nextEventTime == 0.5220 self.assert_equal_msg(ev.nextEventTime, 0.5) 214 221 215 222 model.simulate(options={"initialize":False}) … … 217 224 print("i (should be 2): ", model.get("i")) 218 225 print("j (should be 1): ", model.get("j")) 219 assert model.get("i") == 2220 assert model.get("j") == 1226 self.assert_equal_msg(model.get("i"), 2) 227 self.assert_equal_msg(model.get("j"), 1) 221 228 222 229 @testattr(stddist_base = True) … … 226 233 ev = model.get_event_info() 227 234 print(ev.nextEventTime) 228 assert ev.nextEventTime == 0.5235 self.assert_equal_msg(ev.nextEventTime, 0.5) 229 236 230 237 model.simulate(options={"initialize":False}) … … 232 239 print("i (should be 1): ", model.get("i")) 233 240 print("j (should be 1): ", model.get("j")) 234 assert model.get("i") == 1235 assert model.get("j") == 1241 self.assert_equal_msg(model.get("i"), 1) 242 self.assert_equal_msg(model.get("j"), 1) 236 243 237 244 @testattr(stddist_full = True) … … 241 248 ev = model.get_event_info() 242 249 print(ev.nextEventTime) 243 assert ev.nextEventTime == 1.5250 self.assert_equal_msg(ev.nextEventTime , 1.5) 244 251 245 252 res = model.simulate(final_time=4, options={"initialize":False}) … … 248 255 print("dx: ", res["der(x)"]) 249 256 250 assert res.solver.statistics["ntimeevents"] == 2251 assert res.solver.statistics["nstateevents"] == 2257 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 2) 258 self.assert_equal_msg(res.solver.statistics["nstateevents"], 2) 252 259 253 260 """ """ … … 261 268 model = load_fmu("TimeEvents_TestSampling1.fmu") 262 269 model.initialize() 263 res = model.simulate(0, 1e3, options={"initialize":False}) ;264 assert res.solver.statistics["ntimeevents"] == 1e4270 res = model.simulate(0, 1e3, options={"initialize":False}) 271 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 265 272 266 273 """ Only small interval. """ … … 270 277 model = load_fmu("TimeEvents_TestSampling2.fmu") 271 278 model.initialize() 272 res = model.simulate(0,1e6, options={"initialize":False}) ;273 assert res.solver.statistics["ntimeevents"] == 1e4279 res = model.simulate(0,1e6, options={"initialize":False}) 280 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 274 281 275 282 """ Only big interval. """ … … 279 286 model = load_fmu("TimeEvents_TestSampling3.fmu") 280 287 model.initialize() 281 res = model.simulate(0,1e64, options={"initialize":False}) ;282 assert res.solver.statistics["ntimeevents"] == 1e4288 res = model.simulate(0,1e64, options={"initialize":False}) 289 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 283 290 284 291 """ Basic test using offset. """ … … 288 295 model = load_fmu("TimeEvents_TestSampling4.fmu") 289 296 model.initialize() 290 res = model.simulate(0,2e6, options={"initialize":False}) ;291 assert res.solver.statistics["ntimeevents"] == (1e4)+1297 res = model.simulate(0,2e6, options={"initialize":False}) 298 self.assert_equal_msg(res.solver.statistics["ntimeevents"], (1e4)+1) 292 299 293 300 """ Big interval, small offset. """ … … 297 304 model = load_fmu("TimeEvents_TestSampling5.fmu") 298 305 model.initialize() 299 res = model.simulate(0,1e64, options={"initialize":False}) ;300 assert res.solver.statistics["ntimeevents"] == 1e4306 res = model.simulate(0,1e64, options={"initialize":False}) 307 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 301 308 302 309 """ Big interval and offset. """ … … 306 313 model = load_fmu("TimeEvents_TestSampling6.fmu") 307 314 model.initialize() 308 res = model.simulate(0,1e64, options={"initialize":False}) ;309 assert res.solver.statistics["ntimeevents"] == 1e4315 res = model.simulate(0,1e64, options={"initialize":False}) 316 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 310 317 311 318 @testattr(sample = True) … … 313 320 model = load_fmu("TimeEvents_TestSampling7.fmu") 314 321 model.initialize() 315 res = model.simulate(0,1e5, options={"initialize":False}) ;316 assert res.solver.statistics["ntimeevents"] == 1e4322 res = model.simulate(0,1e5, options={"initialize":False}) 323 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 1e4) 317 324 318 325 """ Test 8 verifies that sampling raises an exception when a too small step is required. """ … … 330 337 model.initialize() 331 338 res = model.simulate(0,1, options={"initialize":False}) 332 assert res.solver.statistics["ntimeevents"] == 10339 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 10) 333 340 334 341 @testattr(stddist_base = True) … … 340 347 res = model.simulate(0,1, options=opts) 341 348 N.testing.assert_almost_equal(model.get("s"), 2.8) 342 assert res.solver.statistics["ntimeevents"] == 2349 self.assert_equal_msg(res.solver.statistics["ntimeevents"], 2) 343 350 344 351 class Test_Time_Events_FMU20:
Note: See TracChangeset
for help on using the changeset viewer.