// ------------------------------------------------------------------

// Iterator.cs: Represents OCL testing for Iterator expressions

// ------------------------------------------------------------------

// Project: C# and OCL Compiler

// Module:  Testing

// Author:  Dave Arnold

// Version: 1.0

// ------------------------------------------------------------------

 

// ------------------------------------------------------------------

// Imports

// ------------------------------------------------------------------

using System;

using System.Collections;

// ------------------------------------------------------------------

 

// ------------------------------------------------------------------

// DaveArnold.OCLTesting Namespace

// ------------------------------------------------------------------

namespace DaveArnold.OCLTesting

{

       // A Class to test Iterator expressions

       class IteratorTests

       {

              public class Person

              {

                     public int Age = 0;

                    

                     [Query]

                     public int GetAge()

                     {

                           return Age;

                     }

                    

                     public Person(int a)

                     {

                           Age = a;

                     }     

              }

             

              public Set _pSet = Set.EmptySet();

             

              public Person p1 = new Person(10);

              public Person p2 = new Person(20);

             

              OCL

              [

                     "context IteratorTests::Exists() : OclVoid"

                     "pre: Set { 1, 2, 3, 4, 5 }->exists(t | t > 4)"

              ]

              public void Exists()

              {

              }

             

              OCL

              [

                     "context IteratorTests::ForAll() : OclVoid"

                     "pre: Set { 1, 2, 3, 4, 5 }->forAll(t | t >= 1)"

              ]

              public void ForAll()

              {

              }

             

              OCL

              [

                     "context IteratorTests::ForAll2() : OclVoid"

                     "post: _pSet->forAll(p : Person | p.Age <= 60)"

              ]

              public void ForAll2()

              {

                     _pSet._col.Add(new Person(10));

                     _pSet._col.Add(new Person(20));

                     _pSet._col.Add(new Person(30));

                     _pSet._col.Add(new Person(40));

              }

             

              OCL

              [

                     "context IteratorTests::ForAll3() : OclVoid"

                     "pre: Set { p1, p2 }->forAll(Age <= 30)"

              ]

              public void ForAll3()

              {

              }

             

              OCL

              [

                     "context IteratorTests::ForAll4() : OclVoid"

                     "pre: Set { p1, p2 }->forAll(GetAge() <= 30)"

              ]

              public void ForAll4()

              {

              }

             

              OCL

              [

                     "context IteratorTests::ForAll5() : OclVoid"

                     "pre: Set { p1, p2 }->forAll(px1; px2 | px1 <> px2 implies px1.Age <> px2.Age)"

              ]

              public void ForAll5()

              {

              }

             

              OCL

              [

                     "context IteratorTests::ForAll6() : OclVoid"

                     "pre: Set { p1, p2 }->forAll(px1 |  Set { p1, p2 }->forAll(px2 | px1 <> px2 implies px1.Age <> px2.Age))"

              ]

              public void ForAll6()

              {

              }

             

              OCL

              [

                     "context IteratorTests::IsUnique() : OclVoid"

                     "pre: Set {1, 2, 3, 4, 5}->isUnique(t | t*2)"

              ]

              public void IsUnique()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Any() : OclVoid"

                     "pre: Set {1, 2, 3, 4, 5}->any(t | t > 2) > 2"

              ]

              public void Any()

              {

              }

             

              OCL

              [

                     "context IteratorTests::One() : OclVoid"

                     "pre: Set {1, 2, 3, 4, 5}->one(t | t = 1)"

              ]

              public void One()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Collect() : OclVoid"

                     "pre: Set {1, 2, 3, 4, 5}->collect(t | t*2)->exists(p | p = 4)"

              ]

              public void Collect()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Collect2() : OclVoid"

                     "pre: Sequence {1, 2, 3, 4, 5}->collect(t | t*2)->exists(p | p = 4)"

              ]

              public void Collect2()

              {

              }

             

              OCL

              [

                     "context IteratorTests::CollectShort() : OclVoid"

                     "pre: Set {p1, p2}.Age->exists(p | p = 10)"

              ]

              public void CollectShort()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Select() : OclVoid"

                     "pre: Set {1, 2, 3, 4}->select(t | t > 3).size() = 1"

              ]

              public void Select()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Select2() : OclVoid"

                     "pre: OrderedSet {1, 2, 3, 4}->select(t | t > 3).size() = 1"

              ]

              public void Select2()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Select3() : OclVoid"

                     "pre: Bag {1, 2, 3, 4, 4}->select(t | t > 3).size() = 2"

              ]

              public void Select3()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Select4() : OclVoid"

                     "pre: Sequence {1, 2, 3, 4, 4}->select(t | t > 3).size() = 2"

              ]

              public void Select4()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Reject() : OclVoid"

                     "pre: Set {1, 2, 3, 4}->reject(t | t > 3).size() = 3"

              ]

              public void Reject()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Reject2() : OclVoid"

                     "pre: OrderedSet {1, 2, 3, 4}->reject(t | t > 3).size() = 3"

              ]

              public void Reject2()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Reject3() : OclVoid"

                     "pre: Bag {1, 2, 3, 4, 4}->reject(t | t > 3).size() = 3"

              ]

              public void Reject3()

              {

              }

             

              OCL

              [

                     "context IteratorTests::Reject4() : OclVoid"

                     "pre: Sequence {1, 2, 3, 4, 4}->reject(t | t > 3).size() = 3"

              ]

              public void Reject4()

              {

              }

             

              OCL

              [

                     "context IteratorTests::CollectNested() : OclVoid"

                     "pre: Set {1, 2, 3, 4, 5}->collectNested(t | t*2)->exists(p | p = 4)"

              ]

              public void CollectNested()

              {

              }

             

              OCL

              [

                     "context IteratorTests::CollectNested2() : OclVoid"

                     "pre: Sequence {1, 2, 3, 4, 5}->collectNested(t | t*2)->exists(p | p = 4)"

              ]

              public void CollectNested2()

              {

              }

             

              OCL

              [

                     "context IteratorTests::SortedBy() : OclVoid"

                     "pre: Set {5, 4, 3, 2, 1}->sortedBy(t | t).at(1) = 1"

              ]

              public void SortedBy()

              {

              }

             

              OCL

              [

                     "context IteratorTests::SortedBy2() : OclVoid"

                     "pre: Bag {5, 4, 5, 3, 2, 1}->sortedBy(t | t).at(1) = 1"

              ]

              public void SortedBy2()

              {

              }

             

              OCL

              [

                     "context IteratorTests::SortedBy3() : OclVoid"

                     "pre: Sequence {5, 4, 5, 3, 2, 1}->sortedBy(t | t).at(1) = 1"

              ]

              public void SortedBy3()

              {

              }

      

             

              public void RunTests()

              {

                     Console.WriteLine("-------------- ITERATOR TESTS ----------------");

                     Exists();

                     Console.WriteLine("I1 (Set {{1,2,3,4,5}}->exists(t | t > 4)): PASSED");

                     ForAll();

                     Console.WriteLine("I2 (Set {{1,2,3,4,5}}->forAll(t | t >= 1)): PASSED");

                     ForAll2();

                     Console.WriteLine("I3 (_pSet->forAll(p : Person | p.Age < 60)): PASSED");

                     ForAll3();

                     Console.WriteLine("I4 (Set {{p1, p2}}->forAll(Age < 30)): PASSED");

                     ForAll4();

                     Console.WriteLine("I5 (Set {{p1, p2}}->forAll(GetAge() < 30)): PASSED");

                     ForAll5();

                     Console.WriteLine("I6 (Set {{p1, p2}}->forAll(px1, px2 | px1 <> px2 implies px1.Age <> px2.Age)): PASSED");

                     ForAll6();

                     Console.WriteLine("I6 Set {{ p1, p2 }}->forAll(px1 |  Set {{ p1, p2 }}->forAll(px2 | px1 <> px2 implies px1.Age <> px2.Age)): PASSED");

                     IsUnique();

                     Console.WriteLine("I7 (Set {{1,2,3,4,5}}->isUnique(t | t *2)): PASSED");

                     Any();

                     Console.WriteLine("I8 (Set {{1, 2, 3, 4, 5}}->any(t | t > 2) > 2): PASSED");

                     One();

                     Console.WriteLine("I9 (Set {{1, 2, 3, 4, 5}}->one(t | t = 1)): PASSED");

                     Collect();

                     Console.WriteLine("I10 (Set {{1, 2, 3, 4, 5}}->collect(t | t*2)->exists(p | p = 4)): PASSED");

                     Collect2();

                     Console.WriteLine("I11 (Sequence {{1, 2, 3, 4, 5}}->collect(t | t*2)->exists(p | p = 4)): PASSED");

                     CollectShort();

                     Console.WriteLine("I12 (Set {{p1, p2}}.Age->exists(p | p = 10)): PASSED");

                     Select();

                     Console.WriteLine("I13 (Set {1, 2, 3, 4}->select(t | t > 3).size() = 1): PASSED");

                     Select2();

                     Console.WriteLine("I14 (OrderedSet {1, 2, 3, 4}->select(t | t > 3).size() = 1): PASSED");

                     Select3();

                     Console.WriteLine("I15 (Bag {1, 2, 3, 4, 4}->select(t | t > 3).size() = 2): PASSED");

                     Select4();

                     Console.WriteLine("I16 (Sequence {1, 2, 3, 4, 4}->select(t | t > 3).size() = 2): PASSED");

                     Reject();

                     Console.WriteLine("I17 (Set {1, 2, 3, 4}->reject(t | t > 3).size() = 3): PASSED");

                     Reject2();

                     Console.WriteLine("I18 (OrderedSet {1, 2, 3, 4}->reject(t | t > 3).size() = 3): PASSED");

                     Reject3();

                     Console.WriteLine("I19 (Bag {1, 2, 3, 4, 4}->reject(t | t > 3).size() = 3): PASSED");

                     Reject4();

                     Console.WriteLine("I20 (Sequence {1, 2, 3, 4, 4}->reject(t | t > 3).size() = 3): PASSED");

                     CollectNested();

                     Console.WriteLine("I21 (Set {{1, 2, 3, 4, 5}}->collectNested(t | t*2)->exists(p | p = 4)): PASSED");

                     CollectNested2();

                     Console.WriteLine("I22 (Sequence {{1, 2, 3, 4, 5}}->collectNested(t | t*2)->exists(p | p = 4)): PASSED");  

                     SortedBy();

                     Console.WriteLine("I23 (Set {5, 4, 3, 2, 1}->sortedBy(t | t)->at(1) = 1): PASSED");

                     SortedBy2();

                     Console.WriteLine("I24 (Bag {5, 4, 5, 3, 2, 1}->sortedBy(t | t)->at(1) = 1): PASSED");

                     SortedBy3();

                     Console.WriteLine("I25 (Sequence {5, 4, 5, 3, 2, 1}->sortedBy(t | t)->at(1) = 1): PASSED");

                     Console.WriteLine("---------- ITERATOR TESTS COMPLETE -----------");

              }

       }

}

 

// ------------------------------------------------------------------

// EOF