From 2c57642ca0411957f3892c7f5411a6912c7221d5 Mon Sep 17 00:00:00 2001 From: Tom Janson Date: Tue, 13 Dec 2016 14:45:56 +0100 Subject: [PATCH] use math.isclose for float comparison asserts --- tests/core/test_modelchecking.py | 8 +++++--- tests/storage/test_matrix.py | 8 +++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/tests/core/test_modelchecking.py b/tests/core/test_modelchecking.py index 56ccdc9..e6ba3c8 100644 --- a/tests/core/test_modelchecking.py +++ b/tests/core/test_modelchecking.py @@ -2,6 +2,8 @@ import stormpy import stormpy.logic from helpers.helper import get_example_path +import math + class TestModelChecking: def test_model_checking_dtmc(self): program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm")) @@ -10,7 +12,7 @@ class TestModelChecking: assert model.nr_states == 13 assert model.nr_transitions == 20 result = stormpy.model_checking(model, formulas[0]) - assert result == 0.16666666666666663 + assert math.isclose(result, 0.16666666666666663) def test_model_checking_all_dtmc(self): program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm")) @@ -19,8 +21,8 @@ class TestModelChecking: assert model.nr_states == 13 assert model.nr_transitions == 20 results = stormpy.model_checking_all(model, formulas[0]) - results_orig = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0] - assert results == results_orig + reference = [0.16666666666666663, 0.3333333333333333, 0, 0.6666666666666666, 0, 0, 0, 1, 0, 0, 0, 0, 0] + assert all(map(math.isclose, results, reference)) def test_parametric_state_elimination(self): import pycarl diff --git a/tests/storage/test_matrix.py b/tests/storage/test_matrix.py index e6e2e63..85f191b 100644 --- a/tests/storage/test_matrix.py +++ b/tests/storage/test_matrix.py @@ -1,6 +1,8 @@ import stormpy from helpers.helper import get_example_path +import math + class TestMatrix: def test_sparse_matrix(self): model = stormpy.parse_explicit_model(get_example_path("dtmc", "die.tra"), get_example_path("dtmc", "die.lab")) @@ -36,7 +38,7 @@ class TestMatrix: # First model checking formulas = stormpy.parse_formulas("P=? [ F \"one\" ]") result = stormpy.model_checking(model, formulas[0]) - assert result == 0.16666666666666663 + assert math.isclose(result, 0.16666666666666663) # Change probabilities i = 0 @@ -51,7 +53,7 @@ class TestMatrix: assert e.value() == 0.3 or e.value() == 0.7 or e.value() == 1 or e.value() == 0 # Second model checking result = stormpy.model_checking(model, formulas[0]) - assert result == 0.06923076923076932 + assert math.isclose(result, 0.06923076923076932) # Change probabilities again for state in stormpy.state.State(0, model): @@ -63,7 +65,7 @@ class TestMatrix: transition.set_value(0.2) # Third model checking result = stormpy.model_checking(model, formulas[0]) - assert result == 0.3555555555555556 or result == 0.3555555555555557 + assert math.isclose(result, 0.3555555555555556) def test_change_parametric_sparse_matrix_modelchecking(self): import stormpy.logic