Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 77e0ae5cb3f3b0d56e19c6ff8f17e39d06b31acc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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");
}

Back to the top