You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
2.5 KiB

2 months ago
  1. import os
  2. import stormpy
  3. import stormpy.logic
  4. from helpers.helper import get_example_path
  5. from configurations import dft
  6. @dft
  7. class TestDftLoad:
  8. def test_load_dft_galileo_file(self):
  9. dft = stormpy.dft.load_dft_galileo_file(get_example_path("dft", "hecs.dft"))
  10. assert dft.nr_elements() == 23
  11. assert dft.nr_be() == 13
  12. assert dft.nr_dynamic() == 2
  13. assert not dft.can_have_nondeterminism()
  14. def test_load_dft_json_file(self):
  15. dft = stormpy.dft.load_dft_json_file(get_example_path("dft", "and.json"))
  16. assert dft.nr_elements() == 3
  17. assert dft.nr_be() == 2
  18. assert dft.nr_dynamic() == 0
  19. assert not dft.can_have_nondeterminism()
  20. def test_load_dft_json_string(self):
  21. # Build json string
  22. json_node_a = '{"data": {"id":"0", "name":"A", "type":"be", "rate":"1", "dorm":"1", "label":"A (1)"}, "group":"nodes", "classes":"be"}'
  23. json_node_b = '{"data": {"id":"1", "name":"B", "type":"be", "rate":"1", "dorm":"1", "label":"B (1)"}, "group":"nodes", "classes":"be"}'
  24. json_node_c = '{"data": {"id":"6", "name":"Z", "type":"pand", "children":["0", "1"], "label":"Z"}, "group":"nodes", "classes":"pand"}'
  25. json_string = '{"toplevel": "6", "parameters": {}, "nodes": [' + json_node_a + ',' + json_node_b + ',' + json_node_c + ']}'
  26. # Load
  27. dft = stormpy.dft.load_dft_json_string(json_string)
  28. assert dft.nr_elements() == 3
  29. assert dft.nr_be() == 2
  30. assert dft.nr_dynamic() == 1
  31. assert not dft.can_have_nondeterminism()
  32. @dft
  33. class TestDftExport:
  34. def test_export_dft_json_string(self):
  35. dft = stormpy.dft.load_dft_galileo_file(get_example_path("dft", "hecs.dft"))
  36. assert dft.nr_elements() == 23
  37. assert dft.nr_be() == 13
  38. assert dft.nr_dynamic() == 2
  39. json_string = stormpy.dft.export_dft_json_string(dft)
  40. dft2 = stormpy.dft.load_dft_json_string(json_string)
  41. assert dft2.nr_elements() == 23
  42. assert dft2.nr_be() == 13
  43. assert dft2.nr_dynamic() == 2
  44. def test_export_dft_json_file(self, tmpdir):
  45. dft = stormpy.dft.load_dft_galileo_file(get_example_path("dft", "hecs.dft"))
  46. assert dft.nr_elements() == 23
  47. assert dft.nr_be() == 13
  48. assert dft.nr_dynamic() == 2
  49. export_file = os.path.join(str(tmpdir), "hecs.json")
  50. stormpy.dft.export_dft_json_file(dft, export_file)
  51. dft2 = stormpy.dft.load_dft_json_file(export_file)
  52. assert dft2.nr_elements() == 23
  53. assert dft2.nr_be() == 13
  54. assert dft2.nr_dynamic() == 2