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

// Derive.cs: Represents OCL testing for Derive 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 Derive rules

       class DeriveTests

       {

              OCL

              [

                     "context DeriveTests::_d1 : Integer"

                     "init: 3"

                     "derive: 3"

              ]

              private int _d1;

             

              OCL

              [

                     "context DeriveTests::_d2 : Real"

                     "derive: -_d2a"

              ]

              private double _d2a = 15;

             

              OCL

              [

                     "context DeriveTests::_d3 : Boolean"

                     "derive: not _d3a"

              ]

              private bool _d3a = false;

             

              OCL

              [

                     "context DeriveTests::_d4 : Integer"

                     "derive: _d4a * 2 + 2"

              ]

              private int _d4a = 15;

             

              OCL

              [

                     "context DeriveTests::_d5 : Real"

                     "derive: _d5a / 2"

              ]

              private int _d5a = 15;

             

              OCL

              [

                     "context DeriveTests::_d6 : Boolean"

                     "derive: _d6a = _d6b"

              ]

              private int _d6a = 15;

              private int _d6b = 15;

             

              OCL

              [

                     "context DeriveTests::_d7 : Integer"

                     "derive: Set{_d6a, _d6b}.size()"

              ]

             

              OCL

              [

                     "context DeriveTests::_d8 : Integer"

                     "derive: Bag { Set { 2 }, Set{_d6a, _d6b}, Set {_d6a, _d6b}}.size()"

              ]

             

              OCL

              [

                     "context DeriveTests::_d9 : Integer"

                     "derive: Tuple{ name = 'Dave', age = _d9a}.age * 2"

              ]

              private int _d9a = 12;

             

              OCL

              [

                     "context DeriveTests::_d10 : Integer"

                     "derive: self._d10a"

              ]

              private int _d10a = 10;

             

             

             

             

              public void RunTests()

              {

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

                     Console.WriteLine("D1 (3): {0}", _d1);

                     Console.WriteLine("D2 (-_d2a): {0}", _d2);

                     Console.WriteLine("D3 (not _d3a): {0}", _d3);

                     Console.WriteLine("D4 (_d4a * 2 + 2): {0}", _d4);

                     Console.WriteLine("D5 (_d5a / 2): {0}", _d5);

                     Console.WriteLine("D6 (_d6a = _d6b): {0}", _d6);

                     _d6a++;

                     Console.WriteLine("D6A[_d6a++] (_d6a = _d6b): {0}", _d6);

                     Console.WriteLine("D7 (Set{{_d6a, _d6b}}.size()): {0}", _d7);

                     Console.WriteLine("D8 (Bag{{ Set {{2}}, Set {{_d6a, _d6b}}, Set {{_d6a, _d6b}}}}.size()): {0}", _d8);

                     Console.WriteLine("D9 (Tuple {{name = 'Dave', age = _d9a}}.age * 2): {0}", _d9);

                     Console.WriteLine("D10 (self._d10a): {0}", _d10);

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

              }

       }

}

 

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

// EOF