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

// Nav.cs: Represents OCL testing for Navigation expressions

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

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

       class NavTests

       {

              public class Person

              {

                     public string name = "Dave";

                    

                     public object data = new Object();

                    

                     public ArrayList ar = new ArrayList();

                    

                     public static int number = 5;

                    

                     public Person()

                     {

                           ar.Add(1);

                           ar.Add(2);

                           ar.Add(3);

                     }

                    

                     OCL

                     [

                           "context  NavTests::Person::NumberOfNames() : Integer"

                           "pre: self.name->size() = 1"

                            "post: result = self.name->size()"

                    

                     ]

                     public int NumberOfNames()

                     {

                           return 1;

                     }

                    

                     OCL

                     [

                           "context NavTests::Person::GetNumber() : Integer"

                           "post: result = Person::number"

                     ]

                     public int GetNumber()

                     {

                           return Person.number;

                     }

                    

                     OCL

                     [

                           "context NavTests::Person::GetMaxNumber() : Integer"

                           "post: result = Int32::MaxValue"

                     ]

                     public int GetMaxNumber()

                     {

                           return Int32.MaxValue;

                     }

                    

                     OCL

                     [

                           "context NavTests::Person::GetData() : System::Object"

                           "pre: not self.data->isEmpty()"

                     ]

                     public object GetData()

                     {

                           return data;

                     }

                    

                     OCL

                     [

                           "context NavTests::Person::ArCount() : Integer"

                           "post: result = ar->size()"

                     ]

                     public int ArCount()

                     {

                           return ar.Count;

                     }

              }

             

              public class PersonData

              {

                     public Person px = new Person();

              }

             

              OCL

              [

                     "context NavTests::GetName(px : PersonData) : String"

                     "post: result = px.px.name"

              ]

              public string GetName(PersonData px)

              {

                     return px.px.name;

              }

             

              OCL

              [

                     "context NavTests::GetLength(px : PersonData) : Integer"

                     "post: result = px.px.name.Length"

              ]

              public int GetLength(PersonData px)

              {

                     return px.px.name.Length;

              }

             

              OCL

              [

                     "context NavTests::GetLengthX2(px : PersonData) : Integer"

                     "post: result = px.px.name.Length * 2"

              ]

              public int GetLengthX2(PersonData px)

              {

                     return px.px.name.Length * 2;

              }

      

             

              public void RunTests()

              {

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

                     Console.WriteLine("N1 (GetName()): {0}", GetName(new PersonData()));

                     Console.WriteLine("N2 (GetLength()): {0}", GetLength(new PersonData()));

                     Console.WriteLine("N3 (GetLengthX2()): {0}", GetLengthX2(new PersonData()));

                     Person p = new Person();

                     Console.WriteLine("N4 (p.NumberOfNames()): {0}", p.NumberOfNames());

                     Console.WriteLine("N5 (p.GetData()): {0}", p.GetData());

                     Console.WriteLine("N6 (p.ArCount()): {0}", p.ArCount());

                     Console.WriteLine("N7 (p.GetNumber()): {0}", p.GetNumber());

                     Console.WriteLine("N8 (p.GetMaxNumber()): {0}", p.GetMaxNumber());

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

              }

       }

}

 

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

// EOF