Coverage for tests/test_modify.py: 92%

1 from pylogics_modalities.syntax.pltl import (

2 Atomic as PLTLAtomic,

3 Before,

4 WeakBefore,

5 Historically,

6 Once,

7 PropositionalFalse,

8 Since,

9 Triggers

10)

11 from pylogics_modalities.syntax.base import (

12 And as PLTLAnd,

13 Or as PLTLOr,

14 Implies as PLTLImplies,

15 Not as PLTLNot

16)

17 from pylogics_modalities.parsers import parse_pltl

18 from src.SymbSyntDec.modify import modify

19 import coverage

20 import unittest

21

22

23 a = PLTLAtomic("a")

24 b = PLTLAtomic("b")

25 c = PLTLAtomic("c")

26 d = PLTLAtomic("d")

27 neg = parse_pltl("!a")

28 _and = parse_pltl("a & b")

29 _or = parse_pltl("a | b")

30 implies1 = parse_pltl("a -> b")

31 implies2 = parse_pltl("(!a) | b")

32 yesterday = parse_pltl("Y a")

33 weak_yesterday = parse_pltl("Z a")

34 historically = parse_pltl("H a")

35 once1 = parse_pltl("O a")

36 once2 = parse_pltl("true S a")

37 false = parse_pltl("false")

38 true = parse_pltl("true")

39 since = parse_pltl("a S b")

40 triggers = parse_pltl("a T b")

41

42

43 class TestModify(unittest.TestCase):

44

45 def test_modify_not_implemented(self):

46 with self.assertRaises(NotImplementedError):

47 modify(1)

48 with self.assertRaises(NotImplementedError):

49 modify("H a")

50 with self.assertRaises(NotImplementedError):

51 modify(1.0)

52

53 def test_modify_true(self):

54 self.assertTrue(modify(parse_pltl("true"))

55 == modify(parse_pltl("true")))

56

57 def test_modify_false(self):

58 self.assertTrue(modify(parse_pltl("false")) ==

59 modify(parse_pltl("false")))

60

61 def test_modify_atomic(self):

62 self.assertEqual(modify(a), a)

63

64 def test_modify_and(self):

65 formula = PLTLAnd(a, b)

66 result = modify(formula)

67 self.assertIsInstance(result, PLTLAnd)

68 self.assertEqual(result.operands[0], a)

69 self.assertEqual(result.operands[1], b)

70 self.assertEqual(result, _and)

71 self.assertEqual(parse_pltl("b & a"), parse_pltl("a & b"))

72

73 def test_modify_or(self):

74 formula = PLTLOr(a, b)

75 result = modify(formula)

76 self.assertIsInstance(result, PLTLOr)

77 self.assertEqual(result.operands[0], a)

78 self.assertEqual(result.operands[1], b)

79 self.assertEqual(parse_pltl("b | a"), parse_pltl("a | b"))

80 self.assertEqual(result, _or)

81

82 def test_modify_not(self):

83 formula = PLTLNot(a)

84 result = modify(formula)

85 self.assertIsInstance(result, PLTLNot)

86 self.assertEqual(result.argument, a)

87 self.assertEqual(neg, formula)

88

89 def test_modify_implies(self):

90 formula = PLTLImplies(a, b)

91 self.assertEqual(formula, implies1)

92 result = modify(formula)

93 self.assertIsInstance(result, PLTLOr)

94 self.assertIsInstance(result.operands[0], PLTLNot)

95 self.assertEqual(result.operands[0].argument, a)

96 self.assertEqual(result.operands[1], b)

97 self.assertEqual(implies2, result)

98

99 def test_modify_yesterday(self):

100 formula = Before(a)

101 result = modify(formula)

102 self.assertIsInstance(result, Before)

103 self.assertEqual(result.argument, a)

104 self.assertEqual(formula, result)

105 self.assertEqual(yesterday, result)

106

107 def test_modify_weak_yesterday(self):

108 formula = WeakBefore(a)

109 result = modify(formula)

110 self.assertIsInstance(result, WeakBefore)

111 self.assertEqual(result.argument, a)

112 self.assertEqual(formula, result)

113 self.assertEqual(weak_yesterday, result)

114

115 def test_modify_since(self):

116 formula = Since(a, b)

117 result = modify(formula)

118 self.assertIsInstance(result, Since)

119 self.assertEqual(result.operands[0], a)

120 self.assertEqual(result.operands[1], b)

121 self.assertEqual(formula, result)

122 self.assertEqual(since, result)

123

124 def test_modify_triggers(self):

125 formula = Triggers(a, b)

126 result = modify(formula)

127 self.assertIsInstance(result, Triggers)

128 self.assertEqual(result.operands[0], a)

129 self.assertEqual(result.operands[1], b)

130 self.assertEqual(formula, result)

131 self.assertEqual(triggers, result)

132

133 def test_modify_once(self):

134 formula = Once(a)

135 result = modify(formula)

136 self.assertIsInstance(result, Since)

137 self.assertEqual(result.operands[0], true)

138 self.assertEqual(result.operands[1], a)

139 self.assertNotEqual(formula, result)

140 self.assertEqual(once2, result)

141

142 def test_modify_historically(self):

143 formula = Historically(a)

144 result = modify(formula)

145 self.assertIsInstance(result, Triggers)

146 self.assertEqual(result.operands[0], false)

147 self.assertEqual(result.operands[0], PropositionalFalse())

148 self.assertEqual(result.operands[1], a)

149 self.assertNotEqual(formula, result)

150

151

152# if __name__ == '__main__':

153# unittest.main()

154

155

156 if __name__ == '__main__':

157 cov = coverage.Coverage()

158 cov.start()

159

160 try:

161 unittest.main()

162 except: # catch-all except clause

163 pass

164

165 cov.stop()

166 cov.save()

167

168 cov.html_report()

169 print("Done.")

170 # python3 -m coverage report

171 # python3 -m coverage html