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

// Set.cs: Represents OCL testing for the Set 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 Set expressions

       class SetTests

       {

             

              OCL

              [

                     "context SetTests::_s1 : Set(Integer)"

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

              ]

              private Set _s1;

             

              OCL

              [

                     "context SetTests::_s2 : Bag(Integer)"

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

              ]

              private Bag _s2;

             

              OCL

              [

                     "context SetTests::_s3 : Boolean"

                     "init: Set { 1, 2} = Set {1, 2 }"

              ]

              private bool _s3;

             

              OCL

              [

                     "context SetTests::_s4 : Boolean"

                     "init: Set { 1, 2} = Set {1, 2, 4}"

              ]

              private bool _s4;

             

              OCL

              [

                     "context SetTests::_s3a : Boolean"

                     "init: Set { 1, 2}.=(Set {1, 2 })"

              ]

              private bool _s3a;

             

              OCL

              [

                     "context SetTests::_s4a : Boolean"

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

              ]

              private bool _s4a;

             

              OCL

              [

                     "context SetTests::_s5 : Boolean"

                     "init: Set { 1, 2} <> Set {1, 2 }"

              ]

              private bool _s5;

             

              OCL

              [

                     "context SetTests::_s6 : Boolean"

                     "init: Set { 1, 2} <> Set {1, 2, 4}"

              ]

              private bool _s6;

             

              OCL

              [

                     "context SetTests::_s5a : Boolean"

                     "init: Set { 1, 2}.<>(Set {1, 2 })"

              ]

              private bool _s5a;

             

              OCL

              [

                     "context SetTests::_s6a : Boolean"

                     "init: Set { 1, 2}.<>(Set {1, 2, 4})"

              ]

              private bool _s6a;

             

              OCL

              [

                     "context SetTests::_s7 : Set(Integer)"

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

              ]

              private Set _s7;

             

              OCL

              [

                     "context SetTests::_s8 : Set(Integer)"

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

              ]

              private Set _s8;

             

              OCL

              [

                     "context SetTests::_s9 : Set(Integer)"

                     "init: Set {1, 2, 3} - Set { 4, 5 }"

              ]

              private Set _s9;

             

              OCL

              [

                     "context SetTests::_s10 : Set(Integer)"

                     "init: Set {1, 2, 3} - Set { 1, 4, 5 }"

              ]

              private Set _s10;

             

              OCL

              [

                     "context SetTests::_s9a : Set(Integer)"

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

              ]

              private Set _s9a;

             

              OCL

              [

                     "context SetTests::_s10a : Set(Integer)"

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

              ]

              private Set _s10a;

             

              OCL

              [

                     "context SetTests::_s11 : Set(Integer)"

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

              ]

              private Set _s11;

             

              OCL

              [

                     "context SetTests::_s12 : Set(Integer)"

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

              ]

              private Set _s12;

             

              OCL

              [

                     "context SetTests::_s13 : Set(Integer)"

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

              ]

              private Set _s13;

             

              OCL

              [

                     "context SetTests::_s14 : Integer"

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

              ]

              private int _s14;

             

              OCL

              [

                     "context SetTests::_s15 : Integer"

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

              ]

              private int _s15;

             

              OCL

              [

                     "context SetTests::_s16 : Set(Integer)"

                     "init: Set { Bag { 1, 2, 4}, Bag {3, 8, 11} }.flatten()"

              ]

              private Set _s16;

             

              OCL

              [

                     "context SetTests::_s17 : Set(Integer)"

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

              ]

              private Set _s17;

             

              OCL

              [

                     "context SetTests::_s18 : OrderedSet(Integer)"

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

              ]

              private OrderedSet _s18;

             

              OCL

              [

                     "context SetTests::_s19 : Sequence(Integer)"

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

              ]

              private Sequence _s19;

             

              OCL

              [

                     "context SetTests::_s20 : Bag(Integer)"

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

              ]

              private Bag _s20;

             

 

              public void RunTests()

              {

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

                     Console.WriteLine("S1 (Set {{ 1, 2, 3}}.union(Set {{ 4, 5 }})): {0}", _s1);

                     Console.WriteLine("S2 (Set {{ 1, 2, 3}}.union(Bag {{ 1, 4, 5 }})): {0}", _s2);

                     Console.WriteLine("S3 (Set {{1, 2 }} = Set {{1, 2}}): {0}", _s3);

                     Console.WriteLine("S4 (Set {{1, 2 }} = Set {{1, 2, 4}}): {0}", _s4);

                     Console.WriteLine("S3a (Set {{1, 2 }}.=(Set {{1, 2}})): {0}", _s3a);

                     Console.WriteLine("S4a (Set {{1, 2 }}.=(Set {{1, 2, 4}})): {0}", _s4a);

                     Console.WriteLine("S5 (Set {{1, 2 }} <> Set {{1, 2}}): {0}", _s5);

                     Console.WriteLine("S6 (Set {{1, 2 }} <> Set {{1, 2, 4}}): {0}", _s6);

                     Console.WriteLine("S5a (Set {{1, 2 }}.<>(Set {{1, 2}})): {0}", _s5a);

                     Console.WriteLine("S6a (Set {{1, 2 }}.<>(Set {{1, 2, 4}})): {0}", _s6a);

                     Console.WriteLine("S7 (Set {{ 1, 2, 3}}.intersection(Set {{ 4, 5 }})): {0}", _s7);

                     Console.WriteLine("S8 (Set {{ 1, 2, 3}}.intersection(Bag {{ 1, 1, 4, 5 }})): {0}", _s8);

                     Console.WriteLine("S9 (Set {{ 1, 2, 3}} - Set {{ 4, 5 }}): {0}", _s9);

                     Console.WriteLine("S10 (Set {{ 1, 2, 3}} - Set {{ 1, 4, 5 }}): {0}", _s10);

                     Console.WriteLine("S9a (Set {{ 1, 2, 3}}.-(Set {{ 4, 5 }})): {0}", _s9a);

                     Console.WriteLine("S10a (Set {{ 1, 2, 3}}.-(Set {{ 1, 4, 5 }})): {0}", _s10a);

                     Console.WriteLine("S11 (Set {{1, 2, 3}}.including(4)): {0}", _s11);

                     Console.WriteLine("S12 (Set {{1, 2, 3}}.excluding(3)): {0}", _s12);

                     Console.WriteLine("S13 (Set {{1, 2, 5}}.symmetricDifference(Set {{ 1, 2, 3 }})): {0}", _s13);

                     Console.WriteLine("S14 (Set {{1, 2, 4}}.count(1)): {0}", _s14);

                     Console.WriteLine("S15 (Set {{1, 2, 4}}.count(5)): {0}", _s15);

                     Console.WriteLine("S16 (Set {{ Bag {{ 1, 2, 4 }}, Bag {{ 3, 8, 11 }} }}.flatten()): {0}", _s16);

                     Console.WriteLine("S17 (Set {{ 1, 2, 3, 4}}.asSet()): {0}", _s17);

                     Console.WriteLine("S18 (Set {{ 1, 2, 3, 4}}.asOrderedSet()): {0}", _s18);

                     Console.WriteLine("S19 (Set {{ 1, 2, 3, 4}}.asSequence()): {0}", _s19);

                     Console.WriteLine("S20 (Set {{ 1, 2, 3, 4}}.asBag()): {0}", _s20);

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

              }

       }

}

 

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

// EOF