22
33import org .junit .jupiter .api .Nested ;
44import org .junit .jupiter .api .Test ;
5- import parser .State ;
65import parser .type .TypeBool ;
76import parser .type .TypeInt ;
87import prism .PrismLangException ;
9- import simulator .LabelEvaluator ;
10-
11- import java .util .function .Predicate ;
128
139import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
14- import static org .junit .jupiter .api .Assertions .assertEquals ;
1510import static org .junit .jupiter .api .Assertions .assertThrows ;
16- import static org .junit .jupiter .api .Assertions .assertTrue ;
1711
1812public class LabelTest
1913{
@@ -49,58 +43,20 @@ public void testFindCycles_noCycle()
4943 }
5044 }
5145
52- @ Nested
53- class LabelEvaluterTest
46+ /**
47+ * <p>
48+ * Helper method that will create a {@link LabelList} with the following Labels:
49+ * </p>
50+ * <ul>
51+ * <li>label "l2" = d<=3;</li>
52+ * <li>label "l1" = "l2" | d=5;</li>
53+ * </ul>
54+ * </p>
55+ * Note: d is the only variable (index 0) and has {@link TypeInt}
56+ * <p>
57+ */
58+ protected static LabelList createLabelListWithoutCycle ()
5459 {
55- @ Test
56- public void testGetLabelValues () throws PrismLangException
57- {
58- /*
59- d is part of the state and will go from [0..5]
60-
61- label "l1" = "l2" | d=5
62- label "l2" = d<=3
63- */
64- LabelList ll = createLabelListWithoutCycle ();
65- LabelEvaluator labelEvaluator = new LabelEvaluator (ll );
66-
67- // loop through all states and check label values
68- for (int i = 0 ; i <= 5 ; i ++) {
69- // create the new state with 1 variable
70- State state = new State (1 );
71- // set d to [0..5]
72- state .setValue (0 , i ); // index of d is 0
73-
74- // expected labelValues
75- boolean l2 = i <= 3 ;
76- boolean l1 = l2 || i == 5 ;
77-
78- // compare
79- Predicate <String > actualValues = labelEvaluator .getLabelValues (state );
80- assertEquals (l1 , actualValues .test ("l1" ));
81- assertEquals (l2 , actualValues .test ("l2" ));
82- }
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- }
96- }
97-
98- private LabelList createLabelListWithoutCycle ()
99- {
100- /*
101- label "l1" = "l2" | d=5
102- label "l2" = d<=3
103- */
10460 LabelList ll = new LabelList ();
10561 ExpressionVar dVar = new ExpressionVar ("d" , TypeInt .getInstance ());
10662 dVar .setIndex (0 ); // index of d is 0
@@ -112,38 +68,56 @@ private LabelList createLabelListWithoutCycle()
11268 return ll ;
11369 }
11470
115- private LabelList createLabelListWith1LabelCycle ()
71+ /**
72+ * <p>
73+ * Helper method that will create a {@link LabelList} with the following Labels:
74+ * </p>
75+ * <ul>
76+ * <li>label "l1" = "l1";</li>
77+ * </ul>
78+ */
79+ protected static LabelList createLabelListWith1LabelCycle ()
11680 {
11781 LabelList ll = new LabelList ();
118- /* label "l1" = "l1" */
11982 ll .addLabel (new ExpressionIdent ("l1" ), new ExpressionLabel ("l1" ));
12083 return ll ;
12184 }
12285
123- private LabelList createLabelListWith2LabelCycle ()
86+ /**
87+ * <p>
88+ * Helper method that will create a {@link LabelList} with the following Labels:
89+ * </p>
90+ * <ul>
91+ * <li>label "l1" = "l2";</li>
92+ * <li>label "l2" = "l1" | d=5;</li>
93+ * </ul>
94+ * </p>
95+ * Note: d is the only variable (index 0) and has {@link TypeInt}
96+ * <p>
97+ */
98+ protected static LabelList createLabelListWith2LabelCycle ()
12499 {
125100 LabelList ll = new LabelList ();
126- /*
127- label "l1" = "l2"
128- label "l2" = "l1" | d=5
129- */
130101 ll .addLabel (new ExpressionIdent ("l1" ), new ExpressionLabel ("l2" ));
131102 ll .addLabel (new ExpressionIdent ("l2" ), new ExpressionBinaryOp (ExpressionBinaryOp .OR ,
132103 new ExpressionLabel ("l1" ), new ExpressionBinaryOp (ExpressionBinaryOp .EQ ,
133104 new ExpressionVar ("d" , TypeInt .getInstance ()), new ExpressionLiteral (TypeInt .getInstance (), 5 ))));
134105 return ll ;
135106 }
136107
137- private LabelList createLabelListWithDependencyChain ()
108+ /**
109+ * <p>
110+ * Helper method that will create a {@link LabelList} with the following Labels:
111+ * </p>
112+ * <ul>
113+ * <li>label "l1" = "l2";</li>
114+ * <li>label "l2" = "l3";</li>
115+ * <li>label "l3" = true;</li>
116+ * </ul>
117+ */
118+ protected static LabelList createLabelListWithDependencyChain ()
138119 {
139120 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- */
147121 ll .addLabel (new ExpressionIdent ("l1" ), new ExpressionLabel ("l2" ));
148122 ll .addLabel (new ExpressionIdent ("l2" ), new ExpressionLabel ("l3" ));
149123 ll .addLabel (new ExpressionIdent ("l3" ), new ExpressionLiteral (TypeBool .getInstance (), true ));
0 commit comments