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

// Init.cs: Represents OCL testing for init rules

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

// 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 init expressions

       class Init

       {

              OCL

              [

                     "context Init::_bool1 : Boolean"

                  "init: false"

              ]

              private bool _bool1;

 

              OCL

              [

                     "context Init::_bool2 : Boolean"

                     "init: true"

              ]

              private bool _bool2;

 

              OCL

              [

                     "context Init::_byte : Integer"

                     "init: 42"

              ]

              private byte _byte;

 

              OCL

              [

                     "context Init::_sbyte : Integer"

                     "init: 43"

              ]

              private sbyte _sbyte;

 

              OCL

              [

                     "context Init::_char : Integer"

                     "init: 68"

              ]

              private char _char;

 

              OCL

              [

                     "context Init::_short : Integer"

                     "init: 2"

              ]

              private short _short;

 

              OCL

              [

                     "context Init::_ushort : Integer"

                     "init: 98"

              ]

              private ushort _ushort;

 

              OCL

              [

                     "context Init::_int : Integer"

                     "init: 1234"

              ]

              private int _int;

 

              OCL

              [

                     "context Init::_uint : Integer"

                     "init: 123456"

              ]

              private uint _uint;

 

              OCL

              [

                     "context Init::_float : Real"

                     "init: 35.23"

              ]

              private float _float;

 

              OCL

              [

                     "context Init::_double : Real"

                     "init: 1258.28"

              ]

              private double _double;

 

              OCL

              [

                     "context Init::_decimal : Real"

                     "init: 5486.54"

              ]

              private decimal _decimal;

 

              OCL

              [

                     "context Init::_string : String"

                     "init: 'Hello World'"

              ]

              private string _string;

 

              OCL

              [

                     "context Init::_collection : Collection(Integer)"

                     "init: Set { 1, 4, 3, 5, 34, 88..90, 909..911, 1024 }"

              ]

              private ArrayList _collection;

 

              OCL

              [

                     "context Init::_collectionSet : Set(String)"

                     "init: Set { 'Dave', 'Kevin', 'Jim', 'Phil' }"

              ]

              private ArrayList _collectionSet;

 

              OCL

              [

                     "context Init::_collectionBag : Bag(Real)"

                     "init: Bag { 8.43, 34, 0.34, 1024.343 }"

              ]

              private ArrayList _collectionBag;

 

              OCL

              [

                     "context Init::_collectionOrderedSet : OrderedSet(Boolean)"

                     "init: OrderedSet { true, false }"

              ]

              private ArrayList _collectionOrderedSet;

 

              OCL

              [

                     "context Init::_collectionSequence : Sequence(Integer)"

                     "init: Sequence { 7, 8, 9, 10, 11 }"

              ]

              private ArrayList _collectionSequence;

 

              OCL

              [

                     "context Init::_col : Collection(Integer)"

                     "init: Bag { 1, 8..14 }"

              ]

              private Collection _col;

 

              OCL

              [

                     "context Init::_set : Set(Set(Integer))"

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

              ]

              private Set _set;

 

              OCL

              [

                     "context Init::_bag : Bag(Set(String))"

                     "init: Bag { Set { 'Dave', 'Kevin' }, Set {'Dave', 'Jim' } }"

              ]

              private Bag _bag;

 

              OCL

              [

                     "context Init::_orderedSet : OrderedSet(Sequence(Real))"

                     "init: OrderedSet { Sequence { 9.34, 43.34 }, Sequence { 434.43, 434.43 } }"

              ]

              private OrderedSet _orderedSet;

 

              OCL

              [

                     "context Init::_sequence : Sequence(Bag(Boolean))"

                     "init: Sequence { Bag { true, false }, Bag { false, true }, Bag { true, true, true } }"

              ]

              private Sequence _sequence;

 

              OCL

              [

                     "context Init::_tuple : TupleType(name: String, age: Integer)"

                     "init: Tuple{name = 'Dave', age = 24}"

              ]

              private Tuple _tuple;

 

              OCL

              [

                     "context Init::_tuple2 : TupleType(valid: Boolean, data: Set(Bag(Integer)))"

                     "init: Tuple{valid = true, data = Set { Bag {1..4 }, Bag {5, 8 }, Bag { 10..15 } } }"

              ]

              private Tuple _tuple2;

 

              OCL

              [

                     "context Init::_c1 : Integer"

                     "init: 5"

              ]

              private const int _c1 = 0;

 

              OCL

              [

                     "context Init::_c2 : String"

                     "init: 'Bye World'"

              ]

              private const string _c2 = "Hello World";

 

              public void RunTests()

              {

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

                     Console.WriteLine("Bool1(false) - {0}", _bool1.ToString());

                     Console.WriteLine("Bool2(true) - {0}", _bool2.ToString());

                     Console.WriteLine("Byte(42) - {0}", _byte.ToString());

                     Console.WriteLine("SByte(43) - {0}", _sbyte.ToString());

                     Console.WriteLine("Char(68) - {0}", _char.ToString());

                     Console.WriteLine("Short(2) - {0}", _short.ToString());

                     Console.WriteLine("UShort(98) - {0}", _ushort.ToString());

                     Console.WriteLine("Int(1234) - {0}", _int.ToString());

                     Console.WriteLine("UInt(123456) - {0}", _uint.ToString());

                     Console.WriteLine("Float(35.23) - {0}", _float.ToString());

                     Console.WriteLine("Double(1258.28) - {0}", _double.ToString());

                     Console.WriteLine("Decimal(5486.54) - {0}", _decimal.ToString());

                     Console.WriteLine("String('Hello World') - {0}", _string.ToString());

                     Console.WriteLine("Collection(Integer) - {0}", (Collection)_collection);

                     Console.WriteLine("Set(String) - {0}", (Set)_collectionSet);

                     Console.WriteLine("Bag(Real) - {0}", (Bag)_collectionBag);

                     Console.WriteLine("OrderedSet(Boolean) - {0}", (OrderedSet)_collectionOrderedSet);

                     Console.WriteLine("Sequence(Integer) - {0}", (Sequence)_collectionSequence);

                     Console.WriteLine("Collection(Integer) - {0}", _col.ToString());

                     Console.WriteLine("Set(Set(Integer)) - {0}", _set.ToString());

                     Console.WriteLine("Bag(Set(String)) - {0}", _bag.ToString());

                     Console.WriteLine("OrderedSet(Sequence(Real)) - {0}", _orderedSet.ToString());

                     Console.WriteLine("Sequence(Bag(Boolean)) - {0}", _sequence.ToString());

                     Console.WriteLine("Tuple(name: String, age: Integer) - {0}", _tuple.ToString());

                     Console.WriteLine("Tuple(valid: Boolean, data: Set(Bag(Integer))) - {0}", _tuple2.ToString());

                     Console.WriteLine("Constant - Int(5) - {0}", _c1);

                     Console.WriteLine("Constant - String('Bye World') - {0}", _c2);

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

              }

       }

}

 

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

// EOF