Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/tests/Expressions_Sequence_Expansion_Reduction.alf')
-rw-r--r--tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/tests/Expressions_Sequence_Expansion_Reduction.alf120
1 files changed, 120 insertions, 0 deletions
diff --git a/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/tests/Expressions_Sequence_Expansion_Reduction.alf b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/tests/Expressions_Sequence_Expansion_Reduction.alf
new file mode 100644
index 00000000000..77e0ae5cb3f
--- /dev/null
+++ b/tests/junit/plugins/uml/alf/org.eclipse.papyrus.uml.alf.tests/tests/Expressions_Sequence_Expansion_Reduction.alf
@@ -0,0 +1,120 @@
+private import Alf::Library::PrimitiveBehaviors::IntegerFunctions::*;
+/**
+ * Test sequence expansion and reduction expressions.
+ **/
+active class Expressions_Sequence_Expansion_Reduction {
+
+ // Supporting declarations *************************************************
+
+ public class Employee {
+ public age: Integer = 51;
+ public isMarried: Boolean = true;
+ public name: String = "Joan";
+ public title: String = "President";
+ public id: Integer = 1;
+ }
+
+ public class Attribute {
+
+ public type: Integer = 0;
+
+ }
+
+ public class Something {
+
+ public attribute: Attribute [*] = new Attribute();
+
+ }
+
+ public class Object {
+
+ public attr: Attribute;
+
+ public init (in attr: Attribute) {
+ this.attr = attr;
+ }
+
+ }
+
+ activity Bad(in x: Integer, in y: Integer): Integer { return x/y; }
+
+ //**************************************************************************
+
+ public activity test(
+ out sum: Integer,
+ out remainder: Integer,
+ out bad: Integer,
+ out select: Employee[*] sequence,
+ out reject: Employee[*] sequence,
+ out collect: String[*] sequence,
+ out iterate: String[*] sequence,
+ out forAll: Boolean,
+ out exists: Boolean,
+ out one: Boolean,
+ out unique: Boolean,
+ out jack: Employee,
+ out joan: Employee,
+ out something: Something,
+ out obj: Object) {
+
+ subtotals = Integer[]{1,2,3};
+ sum = subtotals->reduce '+';
+ remainder = subtotals->reduce ordered '%';
+ bad = Integer[]{1,0,4,2}->reduce Bad;
+
+ e1 = new Employee();
+ e2 = new Employee();
+ e2.name = "Jack";
+ e2.age = 30;
+ e2.isMarried = false;
+ e2.title = "Director";
+ e2.id = 1;
+
+ employees = Employee[]{e1, e2};
+
+ select = employees->select e (e.age>50);
+ reject = employees->reject e (e.isMarried);
+ collect = employees->collect a (a.name);
+ iterate = employees->iterate e (e.name);
+ forAll = employees->forAll e (e.age<=65);
+ exists = employees->exists e (e.name=="Joan");
+ one = employees->one e (e.title=="President");
+ unique = employees->isUnique e (e.id);
+
+ jack = Employee->select e (e.name=="Jack")[1];
+ joan = Employee.allInstances()->select e (e.name=="Joan")[1];
+
+ myType = +1;
+ something = new Something();
+ something.attribute->iterate attr (attr.type = myType);
+
+ obj = new Object();
+ something.attribute->iterate attr (obj.init(attr));
+
+ }
+} do {
+ test(sum, remainder, bad,
+ select, reject, collect, iterate, forAll, exists, one, unique,
+ jack, joan, something, obj);
+
+// AssertEqual("sum",sum, 6);
+// AssertEqual("remainder", remainder, 1);
+// AssertEqual("bad", bad, 2);
+//
+// AssertList("select.name", select.name, String[]{"Joan"});
+// AssertList("reject.name", reject.name, String[]{"Jack"});
+// AssertList("collect.name", collect, String[]{"Joan","Jack"});
+// AssertList("iterate.name", iterate, String[]{"Joan","Jack"});
+// AssertTrue("forAll", forAll);
+// AssertTrue("exists", exists);
+// AssertTrue("one", one);
+// AssertFalse("unique", unique);
+//
+// AssertEqual("jack.name", jack.name, "Jack");
+// AssertEqual("joan.name", joan.name, "Joan");
+//
+// AssertList("something.attribute.type", something.attribute.type, 1);
+// AssertEqual("obj.attr.type", obj.attr.type, 1);
+
+ WriteLine("Done");
+} \ No newline at end of file

Back to the top