|
3 | 3 | import org.junit.jupiter.api.Nested; |
4 | 4 | import org.junit.jupiter.api.Test; |
5 | 5 | import parser.State; |
| 6 | +import parser.type.TypeBool; |
6 | 7 | import parser.type.TypeInt; |
7 | 8 | import prism.PrismLangException; |
8 | 9 | import simulator.LabelEvaluator; |
|
12 | 13 | import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; |
13 | 14 | import static org.junit.jupiter.api.Assertions.assertEquals; |
14 | 15 | import static org.junit.jupiter.api.Assertions.assertThrows; |
| 16 | +import static org.junit.jupiter.api.Assertions.assertTrue; |
15 | 17 |
|
16 | 18 | public class LabelTest |
17 | 19 | { |
@@ -79,6 +81,18 @@ public void testGetLabelValues() throws PrismLangException |
79 | 81 | assertEquals(l2, actualValues.test("l2")); |
80 | 82 | } |
81 | 83 | } |
| 84 | + |
| 85 | + @Test |
| 86 | + public void testLabelChainEvaluation() throws PrismLangException |
| 87 | + { |
| 88 | + LabelList ll = createLabelListWithDependencyChain(); |
| 89 | + LabelEvaluator labelEvaluator = new LabelEvaluator(ll); |
| 90 | + |
| 91 | + State state = new State(0); |
| 92 | + assertTrue(labelEvaluator.getLabelValue(state, "l1")); |
| 93 | + assertTrue(labelEvaluator.getLabelValue(state, "l2")); |
| 94 | + assertTrue(labelEvaluator.getLabelValue(state, "l3")); |
| 95 | + } |
82 | 96 | } |
83 | 97 |
|
84 | 98 | private LabelList createLabelListWithoutCycle() |
@@ -119,4 +133,21 @@ private LabelList createLabelListWith2LabelCycle() |
119 | 133 | new ExpressionVar("d", TypeInt.getInstance()), new ExpressionLiteral(TypeInt.getInstance(), 5)))); |
120 | 134 | return ll; |
121 | 135 | } |
| 136 | + |
| 137 | + private LabelList createLabelListWithDependencyChain() |
| 138 | + { |
| 139 | + LabelList ll = new LabelList(); |
| 140 | + /* |
| 141 | + label "l1" = "l2" |
| 142 | + label "l2" = "l3" |
| 143 | + label "l3" = true |
| 144 | +
|
| 145 | + "l3" must be evaluated as dependency for "l1" |
| 146 | + */ |
| 147 | + ll.addLabel(new ExpressionIdent("l1"), new ExpressionLabel("l2")); |
| 148 | + ll.addLabel(new ExpressionIdent("l2"), new ExpressionLabel("l3")); |
| 149 | + ll.addLabel(new ExpressionIdent("l3"), new ExpressionLiteral(TypeBool.getInstance(), true)); |
| 150 | + |
| 151 | + return ll; |
| 152 | + } |
122 | 153 | } |
0 commit comments