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

// Collection.cs: Represents OCL testing for the Collection STL type

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

// 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 the Collection expressions

       class CollectionTests

       {

             

              OCL

              [

                     "context CollectionTests::_c1 : Integer"

                     "init: Set{1, 2, 3, 4}.size()"

              ]

              private int _c1;

             

              OCL

              [

                     "context CollectionTests::_c2 : Integer"

                     "init: Set{}.size()"

              ]

              private int _c2;

             

              OCL

              [

                     "context CollectionTests::_c3 : Integer"

                     "init: Set{Bag { 2, 2, 4}.size(), Bag { 2, 2}.size()}.size()"

              ]

              private int _c3;

             

              OCL

              [

                     "context CollectionTests::_c4 : Boolean"

                     "init: Set{1, 2, 3,4}.includes(2)"

              ]

              private bool _c4;

             

              OCL

              [

                     "context CollectionTests::_c5 : Boolean"

                     "init: Set{1, 2, 3,4}.includes(5)"

              ]

              private bool _c5;

             

              OCL

              [

                     "context CollectionTests::_c6 : Boolean"

                     "init: Set{ Bag { 1, 2, 3,4 }, Bag { 1, 2 }}.includes(Bag { 1, 2 })"

              ]

              private bool _c6;

             

              OCL

              [

                     "context CollectionTests::_c7 : Boolean"

                     "init: Set{1, 2, 3,4}.excludes(2)"

              ]

              private bool _c7;

             

              OCL

              [

                     "context CollectionTests::_c8 : Boolean"

                     "init: Set{1, 2, 3,4}.excludes(5)"

              ]

              private bool _c8;

             

              OCL

              [

                     "context CollectionTests::_c9 : Boolean"

                     "init: Set{ Bag { 1, 2, 3,4 }, Bag { 1, 2 }}.excludes(Bag { 1, 2 })"

              ]

              private bool _c9;

             

              OCL

              [

                     "context CollectionTests::_c10 : Integer"

                     "init: Bag { 1, 1, 2, 2, 3, 4}.count(1)"

              ]

              private int _c10;

             

              OCL

              [

                     "context CollectionTests::_c11 : Integer"

                     "init: Bag { 1, 1, 2, 2, 3, 4}.count(5)"

              ]

              private int _c11;

             

              OCL

              [

                     "context CollectionTests::_c12 : Integer"

                     "init: Set{ Bag { 1, 2, 3,4 }, Bag { 1, 2 }}.count(Bag { 1, 2 })"

              ]

              private int _c12;

             

              OCL

              [

                     "context CollectionTests::_c13 : Boolean"

                     "init: Set { 1, 2, 3, 4 }.includesAll(Set { 1, 2 })"

              ]

              private bool _c13;

             

              OCL

              [

                     "context CollectionTests::_c14 : Boolean"

                     "init: Set { 1, 2, 3, 4 }.includesAll(Set { 1, 2, 3, 4, 5 })"

              ]

              private bool _c14;

             

              OCL

              [

                     "context CollectionTests::_c15 : Boolean"

                     "init: Set{ Bag { 1, 2, 3,4 }, Bag { 1, 2 }}.includesAll(Bag { Bag {1, 2 }, Bag {1, 2, 3, 4 }})"

              ]

              private bool _c15;

             

              OCL

              [

                     "context CollectionTests::_c16 : Boolean"

                     "init: Set { 1, 2, 3, 4 }.excludesAll(Set { 1, 2 })"

              ]

              private bool _c16;

             

              OCL

              [

                     "context CollectionTests::_c17 : Boolean"

                     "init: Set { 1, 2, 3, 4 }.excludesAll(Set { 1, 2, 3, 4, 5 })"

              ]

              private bool _c17;

             

              OCL

              [

                     "context CollectionTests::_c18 : Boolean"

                     "init: Set{ Bag { 1, 2, 3,4 }, Bag { 1, 2 }}.excludesAll(Bag { Bag {1, 2 }, Bag {1, 2, 3, 4 }})"

              ]

              private bool _c18;

             

              OCL

              [

                     "context CollectionTests::_c19 : Boolean"

                     "init: Set { }.isEmpty()"

              ]

              private bool _c19;

             

              OCL

              [

                     "context CollectionTests::_c20 : Boolean"

                     "init: Set { 2 }.isEmpty()"

              ]

              private bool _c20;

             

              OCL

              [

                     "context CollectionTests::_c21 : Boolean"

                     "init: Set { }.notEmpty()"

              ]

              private bool _c21;

             

              OCL

              [

                     "context CollectionTests::_c22 : Boolean"

                     "init: Set { 2 }.notEmpty()"

              ]

              private bool _c22;

             

              OCL

              [

                     "context CollectionTests::_c23 : Integer"

                     "init: Set {1, 2, 3, 4}.sum()"

              ]

              private int _c23;

             

              OCL

              [

                     "context CollectionTests::_c24 : Real"

                     "init: Set {1.1, 2.2, 3.3, 4.3}.sum()"

              ]

              private double _c24;

             

              OCL

              [

                     "context CollectionTests::_c25 : Real"

                     "init: Set { }.sum()"

              ]

              private double _c25;

             

              OCL

              [

                     "context CollectionTests::_c26 : Set(Tuple(first: Integer, second: Integer))"

                     "init: Set { 1, 2, 3, 4}.product(Set { 40, 5} )"

              ]

              private Set _c26;

             

 

              public void RunTests()

              {

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

                     Console.WriteLine("C1 (Set{{1, 2, 3, 4}}.size()): {0}", _c1);

                     Console.WriteLine("C2 (Set{{}}.size()): {0}", _c2);

                     Console.WriteLine("C3 (Set{{ Bag {{ 2, 2, 4 }}.size(), Bag {{ 2, 2}}.size()}}.size()): {0}", _c3);

                     Console.WriteLine("C4 (Set{{1, 2, 3, 4}}.includes(2)): {0}", _c4);

                     Console.WriteLine("C5 (Set{{1, 2, 3, 4}}.includes(5)): {0}", _c5);

                     Console.WriteLine("C6 (Set{{ Bag {{ 1, 2, 3, 4}}, Bag {{ 1, 2 }}}}.includes(Bag {{ 1, 2 }})): {0}", _c6);

                     Console.WriteLine("C7 (Set{{1, 2, 3, 4}}.excludes(2)): {0}", _c7);

                     Console.WriteLine("C8 (Set{{1, 2, 3, 4}}.excludes(5)): {0}", _c8);

                     Console.WriteLine("C9 (Set{{ Bag {{ 1, 2, 3, 4}}, Bag {{ 1, 2 }}}}.excludes(Bag {{ 1, 2 }})): {0}", _c9);

                     Console.WriteLine("C10 (Bag {{ 1, 1, 2, 2, 3, 4}}.count(1)): {0}", _c10);

                     Console.WriteLine("C11 (Bag {{ 1, 1, 2, 2, 3, 4}}.count(5)): {0}", _c11);

                     Console.WriteLine("C12 (Set{{ Bag {{ 1, 2, 3, 4}}, Bag {{ 1, 2 }}}}.count(Bag {{ 1, 2 }})): {0}", _c12);

                     Console.WriteLine("C13 (Set{{1, 2, 3, 4}}.includesAll(Set {{ 1, 2 }})): {0}", _c13);

                     Console.WriteLine("C14 (Set{{1, 2, 3, 4}}.includesAll(Set {{ 1, 2, 3, 4, 5 }})): {0}", _c14);

                     Console.WriteLine("C15 (Set{{ Bag {{ 1, 2, 3,4 }}, Bag {{ 1, 2 }}}}.includesAll(Bag {{ Bag {{1, 2 }}, Bag {{1, 2, 3, 4 }}}}): {0}", _c15);

                     Console.WriteLine("C16 (Set{{1, 2, 3, 4}}.excludesAll(Set {{ 1, 2 }})): {0}", _c16);

                     Console.WriteLine("C17 (Set{{1, 2, 3, 4}}.excludesAll(Set {{ 1, 2, 3, 4, 5 }})): {0}", _c17);

                     Console.WriteLine("C18 (Set{{ Bag {{ 1, 2, 3,4 }}, Bag {{ 1, 2 }}}}.includesAll(Bag {{ Bag {{1, 2 }}, Bag {{1, 2, 3, 4 }}}}): {0}", _c18);

                     Console.WriteLine("C19 (Set{{ }}.isEmpty()): {0}", _c19);

                     Console.WriteLine("C20 (Set{{2 }}.isEmpty()): {0}", _c20);

                     Console.WriteLine("C21 (Set{{ }}.notEmpty()): {0}", _c21);

                     Console.WriteLine("C22 (Set{{2 }}.notEmpty()): {0}", _c22);

                     Console.WriteLine("C23 (Set{{1, 2, 3, 4}}.sum()): {0}", _c23);

                     Console.WriteLine("C24 (Set{{1.1, 2.2, 3.3, 4.3}}.sum()): {0}", _c24);

                     Console.WriteLine("C25 (Set{{ }}.sum()): {0}", _c25);

                     Console.WriteLine("C26 (Set{{ 1, 2, 3, 4}}.product(Set{{ 40, 5}})): {0}", _c26);

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

              }

       }

}

 

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

// EOF