Browse Source

tests for prism programs and expressions

refactoring
Kevin Batz 5 years ago
parent
commit
92275c3960
  1. 3
      src/storage/expressions.cpp
  2. 2
      src/storage/prism.cpp
  3. 1
      tests/storage/test_expressions.py
  4. 7
      tests/storage/test_prism.py

3
src/storage/expressions.cpp

@ -28,6 +28,8 @@ void define_expressions(py::module& m) {
.def("create_rational_variable", &storm::expressions::ExpressionManager::declareRationalVariable, "create Rational variable", py::arg("name"), py::arg("auxiliary") = false) .def("create_rational_variable", &storm::expressions::ExpressionManager::declareRationalVariable, "create Rational variable", py::arg("name"), py::arg("auxiliary") = false)
; ;
// Variable // Variable
py::class_<storm::expressions::Variable, std::shared_ptr<storm::expressions::Variable>>(m, "Variable", "Represents a variable") py::class_<storm::expressions::Variable, std::shared_ptr<storm::expressions::Variable>>(m, "Variable", "Represents a variable")
.def_property_readonly("name", &storm::expressions::Variable::getName, "Variable name") .def_property_readonly("name", &storm::expressions::Variable::getName, "Variable name")
@ -41,6 +43,7 @@ void define_expressions(py::module& m) {
py::enum_<storm::expressions::OperatorType>(m, "OperatorType", "Type of an operator (of any sort)") py::enum_<storm::expressions::OperatorType>(m, "OperatorType", "Type of an operator (of any sort)")
.value("And", storm::expressions::OperatorType::And) .value("And", storm::expressions::OperatorType::And)
.value("Or", storm::expressions::OperatorType::Or) .value("Or", storm::expressions::OperatorType::Or)

2
src/storage/prism.cpp

@ -75,7 +75,7 @@ void define_prism(py::module& m) {
; ;
// Added by Kevin
py::class_<Variable, std::shared_ptr<Variable>> variable(m, "Prism_Variable", "A program variable in a Prism program"); py::class_<Variable, std::shared_ptr<Variable>> variable(m, "Prism_Variable", "A program variable in a Prism program");
variable.def_property_readonly("name", &Variable::getName, "Variable Name") variable.def_property_readonly("name", &Variable::getName, "Variable Name")
.def_property_readonly("initial_value_expression", &Variable::getInitialValueExpression, "The expression represented the initial value of the variable") .def_property_readonly("initial_value_expression", &Variable::getInitialValueExpression, "The expression represented the initial value of the variable")

1
tests/storage/test_expressions.py

@ -9,6 +9,7 @@ class TestExpressions:
manager = stormpy.ExpressionManager() manager = stormpy.ExpressionManager()
expression = manager.create_boolean(True) expression = manager.create_boolean(True)
assert expression.is_literal() assert expression.is_literal()
assert expression.evaluate_as_bool
assert not expression.contains_variables() assert not expression.contains_variables()
assert expression.has_boolean_type() assert expression.has_boolean_type()
assert not expression.has_integer_type() assert not expression.has_integer_type()

7
tests/storage/test_prism.py

@ -12,6 +12,7 @@ class TestPrism:
jani_model, new_properties = program.to_jani(orig_properties) jani_model, new_properties = program.to_jani(orig_properties)
assert len(new_properties) == len(orig_properties) assert len(new_properties) == len(orig_properties)
def test_prism_to_jani_labels(self): def test_prism_to_jani_labels(self):
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm")) program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
orig_properties = stormpy.parse_properties_for_prism_program("P=? [F \"two\"]", program) orig_properties = stormpy.parse_properties_for_prism_program("P=? [F \"two\"]", program)
@ -28,3 +29,9 @@ class TestPrism:
orig_properties = stormpy.parse_properties_for_prism_program("P=? [F s=7]", program) orig_properties = stormpy.parse_properties_for_prism_program("P=? [F s=7]", program)
jani_model, new_properties = program.to_jani(orig_properties, suffix = "2") jani_model, new_properties = program.to_jani(orig_properties, suffix = "2")
assert len(new_properties) == len(orig_properties) assert len(new_properties) == len(orig_properties)
def test_prism_variables(selfs):
program = stormpy.parse_prism_program(get_example_path("dtmc", "die.pm"))
module = program.modules[0]
assert len(module.integer_variables) == 2
assert len(module.boolean_variables) == 0
Loading…
Cancel
Save