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

// Inheritance.cs: Represents OCL testing for Inheritance

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

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

{

 

       interface ITest

       {

              OCL

              [

                     "context ITest::Square(i : Integer) : Integer"

                     "pre: i > 3"

                     "post: result = i * i"

              ]

              int Square(int i);

             

              OCL

              [

                     "context ITest::Number get : Integer"

                     "post: result = 2"

              ]

              int Number { get; }

             

       }

      

       OCL

       [

              "context Squares"

              "inv: _age > 5"

       ]

       class Squares : ITest

       {

              protected int _age = 10;

             

              OCL

              [

                     "context Squares::Square(i : Integer) : Integer"

                     "pre: i > 3"

                     "post: result = i@pre * i@pre"

                    

              ]

              public virtual int Square(int i) { return i*i; }

             

              OCL

              [

                     "context Squares::Number get : Integer"

                     "post: result = 2"

              ]

              public virtual int Number

              {

                     get

                     {

                           return 2;

                     }

              }

       }

      

      

       // A Class to test Inheritance

       class InheritanceTests : Squares

       {

              OCL

              [

                     "context InheritanceTests::Square(i : Integer) : Integer"

                     "pre: i > 3"

              ]

              OCL

              [

                     "context InheritanceTests::Square(i : Integer) : Integer"

                     "post: result = i * i"

              ]

              public override int Square(int i)

              {

                     return i*i;

              }

             

              public InheritanceTests()

              {

              }

             

             

              public void RunTests()

              {

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

                     Console.WriteLine("I1 (this.Square(4)): {0}", this.Square(4));

                     Console.WriteLine("I2 (this.Number): {0}", this.Number);

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

              }

       }

}

 

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

// EOF