Skip to content

Commit adb4ff9

Browse files
committed
ST6RI-884 Added new tests in ExpressionEvaluationTest.
- Moved SequenceFunction tests out of ModelLevelEvaluationTest, because SequenceFunctions are not currently model-level evaluable per the spec. - Added tests for evaluation of expressions using ControlFunctions collect and select. These functions are model-level evaluable, but cannot be usefully used because of problem with model-level evaluability of body expressions with result expressions that reference parameters. - Added a few tests for collect and select into ModelLevelEvaluationTest just to confirm that they the functions themselves are considered model-level evaluable.
1 parent bd2e562 commit adb4ff9

2 files changed

Lines changed: 28 additions & 0 deletions

File tree

org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/ExpressionEvaluationTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,4 +397,13 @@ public void testNumericalFunctionEvaluation() throws Exception {
397397
assertElement("LiteralInteger 6", instance.eval("NumericalFunctions::sum((1,2,3))", null));
398398
assertElement("LiteralInteger 6", instance.eval("NumericalFunctions::product((1,2,3))", null));
399399
}
400+
401+
@Test
402+
public void testControlOpEvaluation() throws Exception {
403+
SysMLInteractive instance = getSysMLInteractiveInstance();
404+
assertList(new String[] {"LiteralInteger 2", "LiteralInteger 4", "LiteralInteger 6"}, instance.eval("(1,2,3).{in x : ScalarValues::Integer; x * 2}", null));
405+
assertList(new String[] {"LiteralInteger 1", "LiteralInteger 2"}, instance.eval("(1,2,3).?{in x : ScalarValues::Integer; x < 3}", null));
406+
assertList(new String[] {"LiteralInteger 2", "LiteralInteger 4", "LiteralInteger 6"}, instance.eval("(1,2,3)->ControlFunctions::collect{in x : ScalarValues::Integer; x * 2}", null));
407+
assertList(new String[] {"LiteralInteger 1", "LiteralInteger 2"}, instance.eval("(1,2,3)->ControlFunctions::select{in x : ScalarValues::Integer; x < 3}", null));
408+
}
400409
}

org.omg.sysml.interactive.tests/src/org/omg/sysml/interactive/tests/ModelLevelEvaluationTest.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,15 @@ public void testListOpsModelLevelEvaluability() throws Exception {
201201
checkExpressionIsModelLevelEvaluable(instance, "(1, 2, 3)");
202202
checkExpressionIsModelLevelEvaluable(instance, "1..3");
203203
}
204+
205+
@Test
206+
public void testControlOpsModelLevelEvaluability() throws Exception {
207+
SysMLInteractive instance = getSysMLInteractiveInstance();
208+
checkExpressionIsModelLevelEvaluable(instance, "null.{in x; 1}");
209+
checkExpressionIsModelLevelEvaluable(instance, "null.?{in x; true}");
210+
checkExpressionIsModelLevelEvaluable(instance, "ControlFunctions::collect(null, {in x; 1})");
211+
checkExpressionIsModelLevelEvaluable(instance, "ControlFunctions::select(null, {in x; true})");
212+
}
204213

205214
@Test
206215
public void testNonModelLevelEvaluability() throws Exception {
@@ -306,6 +315,16 @@ public void testListEvaluation() throws Exception {
306315
// assertEquals(true, evaluateBooleanValue(null, null, "SequenceFunctions::notEmpty((1,2,3))"));
307316
}
308317

318+
// Note: These collect and select expressions are currently not model-level evaluable, because the feature references
319+
// to parameters of the body expressions are considered non-model-level evaluable (currently per the specification).
320+
// @Test
321+
// public void testControlOpEvaluation() throws Exception {
322+
// assertArrayEquals(new Object[] {2, 4, 6}, evaluateListValue(null, null, "(1,2,3).{in x : ScalarValues::Integer; x * 2}"));
323+
// assertArrayEquals(new Object[] {1, 2}, evaluateListValue(null, null, "(1,2,3).?{in x : ScalarValues::Integer; x < 3}"));
324+
// assertArrayEquals(new Object[] {2, 4, 6}, evaluateListValue(null, null, "(1,2,3)->ControlFunctions::collect{in x : ScalarValues::Integer; x * 2}"));
325+
// assertArrayEquals(new Object[] {1, 2}, evaluateListValue(null, null, "(1,2,3)->ControlFunctions::select{in x : ScalarValues::Integer; x < 3}"));
326+
// }
327+
309328
@Test
310329
public void testConstructorEvaluation() throws Exception {
311330
SysMLInteractive instance = getSysMLInteractiveInstance();

0 commit comments

Comments
 (0)