JAL Computing

C++COMProgramming .NET Mac Palm CPP/CLI Hobbies

 

Home
Up

Chapter 39 "Unit Testing"

Unit testing allows convenient, reproducible verification "of the correctness of a particular module" of code. This is often done using a third party automated tool such as the open source  NUnit for C# and JUnit for Java. If possible, the unit test should strive to exercise every path in the code for the expected outcome. Unit test should trigger and capture any expected exceptions. Finally, unit testing should be convenient and repeatable so that the testing environment encourages running a unit test after each change in the code base. Unit test are especially useful after refactoring a unit of code to insure that the requirements have not been inadvertently violated.

What follows is an attempt at hand coding a unit test harness for the Temperature class in Chapter 38. We can invoke the test harness in main after each change in the code base like this:

    class Program
    {
        static void Main(string[] args)
        {
            UnitTest unit = new UnitTest();
            unit.DoUnitTest();
            System.Console.WriteLine(unit.Log);
            System.Console.ReadLine();
        }
    }

That's it! The DoUnitTest method should return without triggering any Debug.Assert dialogs. The triggering of a Debug.Assert dialog represents a failure of the unit test. For instance here is a sample output:

UNIT TEST LOG <JAL Computing>
THIS TEST SHOULD COMPLETE WITHOUT ANY ASSERT DIALOGS.
Running Setup.
Begin unit test.
Testing Constants.
Testing Constructors.
Expected Exception.
End Unit Test.
Running Teardown.
THIS UNIT TEST SHOULD COMPLETE WITHOUT ANY ASSERT DIALOGS.
UNIT TEST COMPLETED WITHOUT UNEXPECTED EXCEPTONS <JAL Computing>

Using Assert

In each method, code a Debug.Assert to verify the correctness of the method. For instance, to test the correctness of using the Celsius constructor, each getter method is tested for accuracy. In this case, the conversion are lossy, thus the need for an accuracy variable.

// now we test conversions, but
// conversions are lossy
double accuracy = .0000000000001; // max accuracy

// Freeze H2O
Celsius c1 = new Celsius(Celsius.FREEZE_H2O);
Debug.Assert(c1.Value == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters"); // Value getter
Debug.Assert(c1.Celsius == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters");
Debug.Assert(c1.Fahrenheit == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters");
Debug.Assert(c1.Kelvin == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters");
Debug.Assert(Math.Abs(c1.Rankine-Rankine.FREEZE_H2O)<accuracy,
                "Err TestConstructorsGettersSetters");//lossy conversion

Verifying Expected Exceptions

It is also necessary to verify that exceptions are thrown as expected. In this example, the constructor is expected to throw an ArgumentOutOfRange exception when the parameter is less than absolute zero.

// test assertions parameter <= absolute zero
// should throw ArgumentOutOfRangeException
// first test constructors
bool threw = false;
try
{
     Fahrenheit f = new Fahrenheit(Fahrenheit.ABSOLUTE_ZERO-1);
}
catch (ArgumentOutOfRangeException)
{
     log.Append("Expected exception.\n");
     threw = true;
}
Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");

An assert dialog will be displayed if an ArgumentOutOfRange exception is not thrown in the constructor of Fahrenheit when passed a value less than absolute zero. Note that only the specific ArgumentOutOfRange exception is caught. Unexpected exceptions are not caught in this method, but pass up the chain to the TestAll() method. The TestAll method will then flag the unit test as a failure and send the unexpected exception to the output log.

Splitting the UnitTest and Temperature Source Files

It may be convenient to place the code for the UnitTest class in one file and the Code for the Temperature class in another file, in the same project. Alternatively, the coder can create two projects and say add a reference to the Temperature project in the TestTemperature project.

TestTemperature Project: Project --> Add Reference --> Browse --> Temperature --> Obj --> Debug --> Temperature

The coder can remove a reference using the Solution Explorer by expanding the references folder and deleting the selected reference. If the code in the Temperature Debug build is rebuilt, the TestTemperature project will reflect the most recent changes.

Code

Note the use of the static constants for BOIL_H2O, FREEZE_H2O and ABSOLUTE_ZERO for each concrete class.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;  // numbers styles
using System.Diagnostics;


namespace Temperature
{
    class Program
    {
        static void Main(string[] args)
        {
            // http://en.wikipedia.org/wiki/Rankine_scale
            // test in line formatting string
            System.Console.WriteLine("Testing IFormattable");
            Celsius c = new Celsius(Celsius.FREEZE_H2O);
            System.Console.WriteLine("Value expected is {1}'C--> {0:C}", c, Celsius.FREEZE_H2O);
            System.Console.WriteLine("Value expected is {1}'F--> {0:F}", c, Fahrenheit.FREEZE_H2O);
            System.Console.WriteLine("Value expected is {1}'K-->  {0:K}", c, Kelvin.FREEZE_H2O);
            System.Console.WriteLine("Value expected is {1}'R-->  {0:R}", c, Rankine.FREEZE_H2O); 

            //  ******************************************************  //
            //((Temperature)r).Value; // will not compile, good behavior, ambiguous
            //Temperature t = new Rankine(491.688);
            //t.Value; // will not compile, good behavoir, ambiguous
            //  ******************************************************  //

            UnitTest unit = new UnitTest();
            unit.DoUnitTest();
            System.Console.WriteLine(unit.Log);

            System.Console.ReadLine();
            
        }
    }

    
    //////////////////////////////////////////////////////////////////////////
    //                                                                      //
    // **************** PROTOTYPE CODE ** DO NOT USE ********************** //
    //                       JAL Computing                                  //
    //                            12.12.07                                  //
    //                                                                      //
    //////////////////////////////////////////////////////////////////////////
    public class UnitTest
    {
        /// <summary>
        /// Unit Test
        /// A simple test harness for this class.
        /// Be sure to run this test harness after any major rewrites.
        /// Each method test should trigger, trap and examine expected exceptions
        /// Each method test should run post condition assertions as Debug.Assert(bool,string);
        /// USAGE UnitTest unit= new UnitTest();
        /// USAGE unit.DoUnitTest();
        /// USAGE System.Console.Writeline(unit.Log);
        /// </summary>
        private StringBuilder log = new StringBuilder("\nUNIT TEST LOG <JAL Computing>\n");

        public string Log
        {
            get { return log.ToString(); }
        }
        // clears log
        public bool DoUnitTest()
        {
            log = new StringBuilder("\nUNIT TEST LOG <JAL Computing>\n"+
                "THIS TEST SHOULD COMPLETE WITHOUT ANY ASSERT DIALOGS.\n"); // clear log
            bool success= true;
            if (!Setup()) 
            {
                log.Append(" **** Setup Failed ****. \n");
                success = false;
            }
            else 
            {
                bool ta = TestAll();
                bool td = Teardown();
                if (!td) { log.Append("  *** TEARDOWN FAILED ***  \n"); }
                success = ta && td;

            }
            log.Append("THIS UNIT TEST SHOULD HAVE COMPLETED WITHOUT ANY ASSERT DIALOGS.\n");
            if (success) { log.Append("UNIT TEST COMPLETED WITHOUT UNEXPECTED EXCEPTIONS. <JAL Computing>."); }
            else
            {
                log.Append(" **** FAILED *****. \nTHE UNIT TEST DID NOT COMPLETE SUCCESSFULLY. <JAL Computing>.");
                success = false;
            }
            return success;
        }
        private bool Setup()
        {
            log.Append("Running Setup.\n");
            return true;
        }
        private bool TestAll()
        {
            bool success = true;
            log.Append("Begin unit test.\n");
            try
            {
                // all method tests here
                TestConstants();
                TestConstructorsGettersSetters();
                TestParse();
                TestComparisons();
                TestToString();
            }
            catch (Exception e)
            {
                log.Append("TEST ABORTED.\n"+e+"\n");
                success = false;
            }
            log.Append("End Unit Test.\n");
            return success;
        }
        private bool Teardown()
        {
            log.Append("Running Teardown.\n");
            return true;
        }
        // method tests here
        private void TestToString()
        {
            Celsius c = new Celsius(Celsius.FREEZE_H2O);
            // calls Double.ToString()32
            int compare = String.Compare(Fahrenheit.FREEZE_H2O.ToString(), c.Fahrenheit.ToString());
            Debug.Assert(compare ==0, "Err in TestToString");
            compare= String.Compare(Fahrenheit.FREEZE_H2O.ToString()+"'F", c.ToString("F", null));
            Debug.Assert(compare == 0, "Err in TestToString1");
            compare= String.Compare("0'?",c.ToString(null,null));
            Debug.Assert(compare == 0, "Err in TestToSring"); // calls base.ToString

            // test virtual overriding
            Temperature parent = (Temperature)c;
            compare = String.Compare(parent.ToString(), c.ToString());
            Debug.Assert(compare == 0, "Err in TestToString");

            Fahrenheit f = new Fahrenheit(Fahrenheit.FREEZE_H2O);
            parent = (Temperature)f;
            compare = String.Compare(f.ToString(), parent.ToString());
            Debug.Assert(compare == 0, "Err in TestToString");

            Kelvin k = new Kelvin(Kelvin.FREEZE_H2O);
            parent = (Temperature)k;
            compare = String.Compare(k.ToString(), parent.ToString());
            Debug.Assert(compare == 0, "Err in TestToString");

            Rankine r = new Rankine(Rankine.FREEZE_H2O);
            parent = (Temperature)r;
            compare = String.Compare(r.ToString(), parent.ToString());
            Debug.Assert(compare == 0, "Err in TestToString");
        }
        private void TestComparisons()
        {
            log.Append("Testing Comparisons.\n");

            // CompareTo
            Fahrenheit f = new Fahrenheit(Fahrenheit.BOIL_H2O);
            Debug.Assert(f.CompareTo(null) > 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(f, null) > 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(null, f) < 0, "Err TestComparisons");

            Temperature t1 = new Fahrenheit(Fahrenheit.BOIL_H2O);
            Temperature t2 = new Celsius(Celsius.BOIL_H2O);
            int compare = t1.CompareTo(t2);
            Debug.Assert(compare == 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(t1, t2) == 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(null, t1) < 0, "Err TestComparisons");

            t2 = new Celsius(Celsius.BOIL_H2O+1); 
            compare = t1.CompareTo(t2);
            Debug.Assert(compare < 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(t1, t2) < 0, "Err TestComparisons");

            t2 = new Celsius(Celsius.BOIL_H2O-1);
            compare = t1.CompareTo(t2);
            Debug.Assert(compare > 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(t1, t2) > 0, "Err TestComparisons");

            Temperature t3 = new Kelvin(Kelvin.BOIL_H2O);
            Temperature t4 = new Rankine(Rankine.BOIL_H2O);   
            compare = t3.CompareTo(t4);
            Debug.Assert(compare == 0, "Err TestComparisons");
            Debug.Assert(Temperature.Compare(t3, t4) == 0, "Err TestComparisons");


        }
        private void TestParse() {
            log.Append("Testing Parse.\n");

            // Parse throws FormatException if temperature is not formated as XXX'T
            bool threw = false;
            try
            {
                Fahrenheit f1 = (Fahrenheit)Temperature.Parse("0", NumberStyles.Any, null);
            }
            catch (FormatException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestParse.\n");

            Celsius c = (Celsius)Temperature.Parse("100'C");
            Debug.Assert(c.Value==(double)100,"Err TestParse");
            c = (Celsius)Temperature.Parse("100'C", NumberStyles.Any);
            Debug.Assert(c.Value == (double)100, "Err TestParse");
            c = (Celsius)Temperature.Parse("100'C", NumberStyles.Any, null);
            Debug.Assert(c.Value == (double)100, "Err TestParse");
            Fahrenheit f = (Fahrenheit)Temperature.Parse("212'F");
            Debug.Assert(f.Value == Fahrenheit.BOIL_H2O, "Err TestParse");
            Kelvin k = (Kelvin)Temperature.Parse("373.15'K");
            Debug.Assert(k.Value == Kelvin.BOIL_H2O, "Err TestParse");
            Rankine r = (Rankine)Temperature.Parse("671.67'R");
            Debug.Assert(r.Value == Rankine.BOIL_H2O, "Err TestParse");

        }
        private void TestConstants()
        {
            log.Append("Testing Constants.\n");
            Debug.Assert(Celsius.ABSOLUTE_ZERO == (double)-273.15,"Err Celsius.ABSOLUTE_ZERO");
            Debug.Assert(Celsius.BOIL_H2O == (double)100, "Err Celsius.BOIL_H2O");
            Debug.Assert(Celsius.FREEZE_H2O == (double)0, "Err Celsius.FREEZE_H2O");
            Debug.Assert(Fahrenheit.ABSOLUTE_ZERO == (double)-459.67, "Err Fahrenheit.ABSOLUTE_ZERO");
            Debug.Assert(Fahrenheit.BOIL_H2O == (double)212, "Err Fahrenheit.BOIL_H2O");
            Debug.Assert(Fahrenheit.FREEZE_H2O == (double)32, "Err Fahrenheit.FREEZE_H2O");
            Debug.Assert(Kelvin.ABSOLUTE_ZERO == (double)0, "Err Kelvin.ABSOLUTE_ZERO");
            Debug.Assert(Kelvin.BOIL_H2O == (double)373.15, "Err Kelvin.BOIL_H2O");
            Debug.Assert(Kelvin.FREEZE_H2O == (double)273.15, "Err Kelvin.FREEZE_H2O");
            Debug.Assert(Rankine.ABSOLUTE_ZERO == (double)0, "Err Rankine.ABSOLUTE_ZERO");
            Debug.Assert(Rankine.BOIL_H2O == (double)671.67, "Err Rankine.BOIL_H2O");
            Debug.Assert(Rankine.FREEZE_H2O == (double)491.67, "Err Rankine.FREEZE_H2O");
        }
        private void TestConstructorsGettersSetters()
        {
            log.Append("Testing Constructors and Properties.\n");

            // test assertions parameter <= absolute zero
            // should throw ArgumentOutOfRangeException
            // first test constructors
            bool threw = false;
            try
            {
                Fahrenheit f = new Fahrenheit(Fahrenheit.ABSOLUTE_ZERO-1);
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            threw = false;
            try
            {
                Celsius c = new Celsius(Celsius.ABSOLUTE_ZERO-1);
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            threw = false;
            try {     
                Kelvin k = new Kelvin(Kelvin.ABSOLUTE_ZERO-1);     
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            threw = false;
            try
            {
                Rankine r = new Rankine(Rankine.ABSOLUTE_ZERO-1);
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");

            // now we test the setters for exceptions
            threw = false;
            Celsius c2= new Celsius(Celsius.BOIL_H2O);
            try
            {
                c2.Rankine = Celsius.ABSOLUTE_ZERO - 1;
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            Fahrenheit f2= new Fahrenheit(Fahrenheit.BOIL_H2O);
            try
            {
                f2.Fahrenheit = Fahrenheit.ABSOLUTE_ZERO - 1;
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            Kelvin k2= new Kelvin(Kelvin.BOIL_H2O);
            try
            {
                k2.Kelvin = Kelvin.ABSOLUTE_ZERO - 1;
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            Rankine r2 = new Rankine(Rankine.BOIL_H2O);
            try
            {
                r2.Rankine = Rankine.ABSOLUTE_ZERO - 1;
            }
            catch (ArgumentOutOfRangeException)
            {
                log.Append("Expected exception.\n");
                threw = true;
            }
            Debug.Assert(threw, "Failed to throw: TestConstructorsGettersSetters.\n");
            

            // now we test conversions, but
            // conversions are lossy
            double accuracy = .0000000000001; // max accuracy

            // Freeze H2O
            Celsius c1 = new Celsius(Celsius.FREEZE_H2O);
            Debug.Assert(c1.Value == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters"); // Value getter
            Debug.Assert(c1.Celsius == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(c1.Fahrenheit == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(c1.Kelvin == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(c1.Rankine-Rankine.FREEZE_H2O)<accuracy,
                "Err TestConstructorsGettersSetters");//lossy conversion

            Fahrenheit f1 = new Fahrenheit(Fahrenheit.FREEZE_H2O);
            Debug.Assert(f1.Value == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters"); // Value getter
            Debug.Assert(f1.Celsius == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(f1.Fahrenheit == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(f1.Kelvin == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(f1.Rankine - Rankine.FREEZE_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            Kelvin k1 = new Kelvin(Kelvin.FREEZE_H2O);
            Debug.Assert(k1.Value == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters"); // Value getter
            Debug.Assert(k1.Celsius == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(k1.Fahrenheit == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(k1.Kelvin == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(k1.Rankine - Rankine.FREEZE_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            Rankine r1 = new Rankine(Rankine.FREEZE_H2O);
            // Value getter
            Debug.Assert(Math.Abs(r1.Value - Rankine.FREEZE_H2O) < accuracy, "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Celsius == Celsius.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Fahrenheit == Fahrenheit.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Kelvin == Kelvin.FREEZE_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(r1.Rankine - Rankine.FREEZE_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            // Boil H2O
            c1 = new Celsius(Celsius.BOIL_H2O);
            Debug.Assert(c1.Celsius == Celsius.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(c1.Fahrenheit == Fahrenheit.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(c1.Kelvin == Kelvin.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(c1.Rankine - Rankine.BOIL_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            f1 = new Fahrenheit(Fahrenheit.BOIL_H2O);
            Debug.Assert(f1.Celsius == Celsius.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(f1.Fahrenheit == Fahrenheit.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(f1.Kelvin == Kelvin.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(f1.Rankine - Rankine.BOIL_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            k1 = new Kelvin(Kelvin.BOIL_H2O);
            Debug.Assert(k1.Celsius == Celsius.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(k1.Fahrenheit == Fahrenheit.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(k1.Kelvin == Kelvin.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(k1.Rankine - Rankine.BOIL_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            r1 = new Rankine(Rankine.BOIL_H2O);
            Debug.Assert(r1.Celsius == Celsius.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Fahrenheit == Fahrenheit.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Kelvin == Kelvin.BOIL_H2O, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(r1.Rankine - Rankine.BOIL_H2O) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion

            // Absolute Zero
            c1 = new Celsius(Celsius.ABSOLUTE_ZERO);
            Debug.Assert(c1.Celsius == Celsius.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(c1.Fahrenheit - Fahrenheit.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");
            Debug.Assert(c1.Kelvin == Kelvin.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(c1.Rankine - Rankine.ABSOLUTE_ZERO) < accuracy, 
                
                "Err TestConstructorsGettersSetters");//lossy conversion

            f1 = new Fahrenheit(Fahrenheit.ABSOLUTE_ZERO);
            Debug.Assert(f1.Celsius == Celsius.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(f1.Fahrenheit - Fahrenheit.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");
            Debug.Assert(f1.Kelvin == Kelvin.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(f1.Rankine - Rankine.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion
            
            k1 = new Kelvin(Kelvin.ABSOLUTE_ZERO);
            Debug.Assert(k1.Celsius == Celsius.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(k1.Fahrenheit - Fahrenheit.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");
            Debug.Assert(k1.Kelvin == Kelvin.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(k1.Rankine - Rankine.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion
            
            r1 = new Rankine(Rankine.ABSOLUTE_ZERO);
            Debug.Assert(r1.Celsius == Celsius.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(r1.Fahrenheit - Fahrenheit.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");
            Debug.Assert(r1.Kelvin == Kelvin.ABSOLUTE_ZERO, "Err TestConstructorsGettersSetters");
            Debug.Assert(Math.Abs(r1.Rankine - Rankine.ABSOLUTE_ZERO) < accuracy, 
                "Err TestConstructorsGettersSetters");//lossy conversion
        }// end TestConstructorsGettersSetters

    }// end UnitTest
}

Unit test support is built into Visual Studio 2005 Team System.

Send mail to [email protected] with questions or comments about this web site. Copyright © 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 © 
Last modified: 08/04/09
Hosted by www.Geocities.ws

1