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

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

       class BagTests

       {

             

              OCL

              [

                     "context BagTests::_b1 : Bag(Integer)"

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

              ]

              private Bag _b1;

             

              OCL

              [

                     "context BagTests::_b2 : Bag(Integer)"

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

              ]

              private Bag _b2;

             

              OCL

              [

                     "context BagTests::_b3 : Boolean"

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

              ]

              private bool _b3;

             

              OCL

              [

                     "context BagTests::_b4 : Boolean"

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

              ]

              private bool _b4;

             

              OCL

              [

                     "context BagTests::_b3a : Boolean"

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

              ]

              private bool _b3a;

             

              OCL

              [

                     "context BagTests::_b4a : Boolean"

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

              ]

              private bool _b4a;

             

              OCL

              [

                     "context BagTests::_b5 : Boolean"

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

              ]

              private bool _b5;

             

              OCL

              [

                     "context BagTests::_b6 : Boolean"

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

              ]

              private bool _b6;

             

              OCL

              [

                     "context BagTests::_b5a : Boolean"

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

              ]

              private bool _b5a;

             

              OCL

              [

                     "context BagTests::_b6a : Boolean"

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

              ]

              private bool _b6a;

             

              OCL

              [

                     "context BagTests::_b7 : Bag(Integer)"

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

              ]

              private Bag _b7;

             

              OCL

              [

                     "context BagTests::_b8 : Set(Integer)"

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

              ]

              private Set _b8;

             

              OCL

              [

                     "context BagTests::_b9 : Bag(Integer)"

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

              ]

              private Bag _b9;

             

              OCL

              [

                     "context BagTests::_b10 : Bag(Integer)"

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

              ]

              private Bag _b10;

             

              OCL

              [

                     "context BagTests::_b11 : Integer"

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

              ]

              private int _b11;

             

              OCL

              [

                     "context BagTests::_b12 : Integer"

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

              ]

              private int _b12;

             

              OCL

              [

                     "context BagTests::_b13 : Bag(Integer)"

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

              ]

              private Bag _b13;

             

              OCL

              [

                     "context BagTests::_b14 : Set(Integer)"

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

              ]

              private Set _b14;

             

              OCL

              [

                     "context BagTests::_b15 : OrderedSet(Integer)"

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

              ]

              private OrderedSet _b15;

             

              OCL

              [

                     "context BagTests::_b16 : Sequence(Integer)"

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

              ]

              private Sequence _b16;

             

              OCL

              [

                     "context BagTests::_b17 : Bag(Integer)"

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

              ]

              private Bag _b17;

             

 

              public void RunTests()

              {

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

                     Console.WriteLine("B1 (Bag {{ 1, 2, 3}}.union(Bag {{ 1, 2 }})): {0}", _b1);

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

                     Console.WriteLine("B3 (Bag {{1, 2 }} = Bag {{1, 2}}): {0}", _b3);

                     Console.WriteLine("B4 (Bag {{1, 2 }} = Bag {{1, 2, 1}}): {0}", _b4);

                     Console.WriteLine("B3a (Bag {{1, 2 }}.=(Bag {{1, 2}})): {0}", _b3a);

                     Console.WriteLine("B4a (Bag {{1, 2 }}.=(Bag {{1, 2, 1}})): {0}", _b4a);

                     Console.WriteLine("B5 (Bag {{1, 2 }} <> Bag {{1, 2}}): {0}", _b5);

                     Console.WriteLine("B6 (Bag {{1, 2 }} <> Bag {{1, 2, 1}}): {0}", _b6);

                     Console.WriteLine("B5a (Bag {{1, 2 }}.<>(Bag {{1, 2}})): {0}", _b5a);

                     Console.WriteLine("B6a (Bag {{1, 2 }}.<>(Bag {{1, 2, 1}})): {0}", _b6a);

                     Console.WriteLine("B7 (Bag {{ 1, 2, 3}}.intersection(Bag {{ 1, 1 }})): {0}", _b7);

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

                     Console.WriteLine("B9 (Bag {{1, 2, 3}}.including(1)): {0}", _b9);

                     Console.WriteLine("B10 (Bag {{1, 1, 1, 2, 3}}.excluding(1)): {0}", _b10);

                     Console.WriteLine("B11 (Bag {{1, 1, 1, 2, 4}}.count(1)): {0}", _b11);

                     Console.WriteLine("B12 (Bag {{1, 1, 2, 4}}.count(5)): {0}", _b12);

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

                     Console.WriteLine("B14 (Bag {{ 1, 1, 2, 3, 4}}.asSet()): {0}", _b14);

                     Console.WriteLine("B15 (Bag {{ 1, 1, 2, 3, 4}}.asOrderedSet()): {0}", _b15);

                     Console.WriteLine("B16 (Bag {{ 1, 1, 2, 3, 4}}.asSequence()): {0}", _b16);

                     Console.WriteLine("B17 (Bag {{ 1, 1, 2, 3, 4}}.asBag()): {0}", _b17);

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

              }

       }

}

 

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

// EOF