utcs : Unit Test driver for C#.

Download utcs.zip

Synopsis:

utcsmain.cs
utx.cs
Asserter.cs
Globals.cs
MessageWriter.cs
Reporter.cs
Statistics.cs
TestRunner.cs
UnitTestClass.cs
UnitTestMethod.cs
utcs.cs
utcstest.cs


utcsmain.cs

Synopsis
using System;

namespace utcsmain
{
	/// <summary>
	/// Summary description for utcs.
	/// </summary>
	public class utcsmain
	{
    static void Main(string[] args)
    {
      new ut.utcs(args);
    }
	}
}

utx.cs

Synopsis
using System;
using System.Collections;
using System.Diagnostics;

namespace ut 
{
  public class utx
  {
    private static Asserter mAsserter = null;
    private static Reporter mReporter = null;
    //Internal use only!
    internal static void Set(Reporter r, Asserter a)
    {
      mReporter = r;
      mAsserter = a;
    }
    //used only for testing utcs!
    public static void assertNextAssertFails()
    {
      mReporter.SetNextAssertFails();
    }

    //bools
    public static void assert(bool b)
    {
      SetLocation();
      mAsserter.assert(null, b, true);
    }
    public static void assertnot(bool b)
    {
      SetLocation();
      mAsserter.assertnot(null, b, true);
    }
    public static void assert(string msg, bool b)
    {
      SetLocation();
      mAsserter.assert(msg, b, true);
    }
    public static void assertnot(string msg, bool b)
    {
      SetLocation();
      mAsserter.assertnot(msg, b, true);
    }

    //int
    public static void assert(string msg, int actual, int expected)
    {
      SetLocation();
      mAsserter.assert(msg, actual.ToString(), expected.ToString());
    }
    public static void assert(int actual, int expected)
    {
      SetLocation();
      mAsserter.assert(null, actual.ToString(), expected.ToString());
    }
    public static void assertnot(string msg, int actual, int expected)
    {
      SetLocation();
      mAsserter.assertnot(msg, actual.ToString(), expected.ToString());
    }
    public static void assertnot(int actual, int expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual.ToString(), expected.ToString());
    }

    //char
    public static void assert(string msg, char actual, char expected)
    {
      SetLocation();
      mAsserter.assert(msg, actual.ToString(), expected.ToString());
    }
    public static void assert(char actual, char expected)
    {
      SetLocation();
      mAsserter.assert(null, actual.ToString(), expected.ToString());
    }
    public static void assertnot(string msg, char actual, char expected)
    {
      SetLocation();
      mAsserter.assertnot(msg, actual.ToString(), expected.ToString());
    }
    public static void assertnot(char actual, char expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual.ToString(), expected.ToString());
    }

    //byte
    public static void assert(string msg, byte actual, byte expected)
    {
      SetLocation();
      mAsserter.assert(msg, actual.ToString(), expected.ToString());
    }
    public static void assert(byte actual, byte expected)
    {
      SetLocation();
      mAsserter.assert(null, actual.ToString(), expected.ToString());
    }
    public static void assertnot(string msg, byte actual, byte expected)
    {
      SetLocation();
      mAsserter.assertnot(msg, actual.ToString(), expected.ToString());
    }
    public static void assertnot(byte actual, byte expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual.ToString(), expected.ToString());
    }

    //double
    public static void assert(string msg, double actual, double expected, double epsilon)
    {
      SetLocation();
      mAsserter.assert(msg, actual, expected, epsilon);
    }
    public static void assert(double actual, double expected, double epsilon)
    {
      SetLocation();
      mAsserter.assert(null, actual, expected, epsilon);
    }
    public static void assertnot(string msg, double actual, double expected, double epsilon)
    {
      SetLocation();
      mAsserter.assertnot(msg, actual, expected, epsilon);
    }
    public static void assertnot(double actual, double expected, double epsilon)
    {
      SetLocation();
      mAsserter.assertnot(null, actual, expected, epsilon);
    }

    //string
    public static void assert(string actual, string expected)
    {
      SetLocation();
      mAsserter.assert(null, actual, expected);
    }
    public static void assert(string msg, string actual, string expected)
    {
      SetLocation();
      mAsserter.assert(msg, (object) actual, (object) expected);
    }
    public static void assertnot(string actual, string expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual, expected);
    }
    public static void assertnot(string msg, string actual, string expected)
    {
      SetLocation();
      mAsserter.assertnot(msg, (object) actual, (object) expected);
    }

    //ICollection
    public static void assert(ICollection actual, ICollection expected)
    {
      SetLocation();
      mAsserter.assert(null, actual, expected);
    }
    public static void assert(string msg, ICollection actual, ICollection expected)
    {
      SetLocation();
      mAsserter.assert(msg, actual, expected);
    }
    public static void assertnot(ICollection actual, ICollection expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual, expected);
    }
    public static void assertnot(string msg, ICollection actual, ICollection expected)
    {
      SetLocation();
      mAsserter.assertnot(msg, actual, expected);
    }

    //objects
    public static void assert(object actual, object expected)
    {
      SetLocation();
      mAsserter.assert(null, actual, expected);
    }
    public static void assert(string msg, object actual, object expected)
    {
      SetLocation();
      mAsserter.assert(msg, actual, expected);
    }
    public static void assertnot(object actual, object expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual, expected);
    }
    public static void assertnot(string msg, object actual, object expected)
    {
      SetLocation();
      mAsserter.assertnot(null, actual, expected);
    }

    private static void SetLocation()
    {
      StackTrace st = new StackTrace(true);
      StackFrame mSFrame = st.GetFrame(2);

      mReporter.SetLocation(mSFrame.GetFileName(), mSFrame.GetFileLineNumber() - 1, 1);
    }
  }
}

Asserter.cs

Synopsis
using System;
using System.Collections;

namespace ut
{
  internal class Asserter
  {
    private Reporter mReporter;

    public Asserter(Reporter rep)
    {
      mReporter = rep;
    }
    //object
    public void assert(string msg, object actual, object expected)
    {
      mReporter.IncAsserts();
      if (ConditionIsTrue(actual, expected)) return;
      mReporter.ReportFailedAssert(msg, actual, expected);
    }
    public void assertnot(string msg, object actual, object expected)
    {
      mReporter.IncAsserts();
      if (ConditionIsFalse(actual, expected)) return;
      mReporter.ReportFailedAssertNot(msg, actual, expected);
    }
    //double
    public void assert(string msg, double actual, double expected, double epsilon)
    {
      mReporter.IncAsserts();
      //if (NullConditionsHandled(actual, expected)) return true;
      //todo: check for NAN
      if (ConditionEquals(DoublesEqual(actual, expected, epsilon), actual, expected))
        return;
      mReporter.ReportFailedAssert(msg, actual.ToString("0.0##"), expected.ToString("0.0##"));
    }
    public void assertnot(string msg, double actual, double expected, double epsilon)
    {
      mReporter.IncAsserts();
      //if (NotNullConditionsHandled(actual, expected)) return true;
      //todo: check for NAN
      if (ConditionEquals(!DoublesEqual(actual, expected, epsilon), actual, expected))
        return;
      mReporter.ReportFailedAssertNot(msg, actual.ToString("0.0##"), expected.ToString("0.0##"));
    }
    private bool DoublesEqual(double actual, double expected, double epsilon)
    {
      return actual - epsilon <= expected && expected <= actual + epsilon;
    }
    //ICollection
    public void assert(string msg, ICollection actual, ICollection expected)
    {
      if (NullConditionsHandled(actual, expected)) return;
      if (CountConditionsHandled(actual, expected)) return;
      
      IEnumerator enumActual = actual.GetEnumerator();
      IEnumerator enumExp = expected.GetEnumerator();
      while(enumActual.MoveNext() && enumExp.MoveNext())
        assert(mReporter.message(msg, "items do not match"), enumActual.Current, enumExp.Current);
    }
    public void assertnot(string msg, ICollection actual, ICollection expected)
    {
      if (NotNullConditionsHandled(actual, expected)) return;
      if (NotCountConditionsHandled(actual, expected)) return;

      IEnumerator enumActual = actual.GetEnumerator();
      IEnumerator enumExp = expected.GetEnumerator();
      int mismatches = 0;
      while(enumActual.MoveNext() && enumExp.MoveNext())
      {
        if (!enumActual.Current.Equals(enumExp.Current)) mismatches++;
      }

      assertnot(mReporter.message(msg, "all items match"), mismatches, 0);
    }

    //private
    private bool ConditionIsTrue(object actual, object expected)
    {
      if (NullConditionsHandled(actual, expected)) return true;
      return ConditionEquals(expected.Equals(actual), actual, expected);
    }
    private bool ConditionIsFalse(object actual, object expected)
    {
      if (NotNullConditionsHandled(actual, expected)) return true;
      return ConditionEquals(!expected.Equals(actual), actual, expected);
    }
    private bool ConditionEquals(bool condition, object actual, object expected)
    {
      if (!condition) return false;
      mReporter.CheckMissingAssertFailure();
      return true;
    }
    private bool NotNullConditionsHandled(object actual, object expected)
    {
      if (actual == null && expected == null) 
      {
        mReporter.ReportBothObjectsAreNull();
        return true;
      }
      if (actual == null ^ expected == null)
      {
        mReporter.CheckMissingAssertFailure();
        return true;
      }
      return false;
    }
    private bool NullConditionsHandled(object actual, object expected)
    {
      if (actual == null && expected == null) 
      {
        mReporter.CheckMissingAssertFailure();
        return true;
      }
      if (actual == null ^ expected == null)
      {
        mReporter.ReportSingleNullObject(actual, expected);
        return true;
      }

      return false;
    }
    private bool CountConditionsHandled(ICollection actual, ICollection expected)
    {
      if (actual.Count != expected.Count)
      {
        mReporter.ReportCountsDontMatch();
        return true;
      }

      return false;
    }
    private bool NotCountConditionsHandled(ICollection actual, ICollection expected)
    {
      if (actual.Count != expected.Count)
      {
        mReporter.CheckMissingAssertFailure();
        return true;
      }
      if (actual.Count == 0 && expected.Count == 0)
      {
        mReporter.ReportBothObjectsAreEmpty();
        return true;
      }

      return false;
    }
  }
}

Globals.cs

Synopsis
using System;

namespace ut
{
	internal class Globals
	{
    public static readonly string ClassNamePrefix = "test";
    public static readonly string MethodNamePrefix = "test";

  }
}

MessageWriter.cs

Synopsis
using System;

namespace ut
{
  internal class MessageWriter
  {
    private string mTestName;
    private string mFilename = "unknown";
    private int mLineno = -1;
    private int mColno = -1;

    public string TestName
    {
      set { mTestName = value; }
    }
    public void SetLocation(string fname, int lineno, int colno)
    {
      mFilename = fname;
      mLineno = lineno;
      mColno = colno;
    }
    public void Error(string s)
    {
      Line(Location() + "EXCP   : " + mTestName + ": " + s);
    }
    public void Failure(string s)
    {
      Line(Location() + "ASSERT : " + mTestName + ": " + s);
    }
    public void Warning(string s)
    {
      Line(Location() + "WARNING: " + mTestName + ": " + s);
    }
    public void Line(string s)
    {
      Console.WriteLine(s);
    }
    private string Location()
    {
      return mFilename + "(" + mLineno + "," + mColno + "): ";
    }
  }
}

Reporter.cs

Synopsis
using System;

namespace ut
{
	internal class Reporter
	{
    private MessageWriter mWriter;
    private Statistics mStats;
    private bool mNextAssertFails = false;

		public Reporter()
		{
      mWriter = new MessageWriter();
      mStats = new Statistics(mWriter);
    }
    public void SetLocation(string fname, int lineno, int colno)
    {
      mWriter.SetLocation(fname, lineno, colno);
    }
    public string TestName
    {
      set { mWriter.TestName = value; }
    }
    public void SetNextAssertFails()
    {
        mNextAssertFails = true;
    }
    public void dump()
    {
      mStats.dump();
    }
    public void IncAsserts()
    {
      mStats.mNumAsserts++;
    }
    public void IncUnitTests()
    {
      mStats.mNumUnitTests++;
    }
    public void IncTestMethods()
    {
      mStats.mNumTestMethods++;
    }
    public void ReportFailedAssert(string msg, object actual, object expected)
    {
      ReportFailedAssert(message(msg, "expected '" + expected + "', actual '" + actual + "'"));
    }
    public void ReportFailedAssertNot(string msg, object actual, object expected)
    {
      ReportFailedAssert(message(msg, "expected not '" + expected + "', actual '" + actual + "'"));
    }
    public string message(string msg, string text)
    {
      if (msg == null) return text;
      return msg + ": " + text;
    }
    public void ReportFailedAssert(string msg)
    {
      mStats.mNumErrors++;
      if (!mNextAssertFails)
        mWriter.Failure(msg);
      mNextAssertFails = false;
    }
    public void CheckMissingAssertFailure()
    {
      if (mNextAssertFails)
        mWriter.Failure("Expected the assert() to fail.");
      mNextAssertFails = false;
    }
    public void ReportInvalidTest(string msg)
    {
      mWriter.Warning(msg);
    }
    public void ReportException(string msg)
    {
      mStats.mNumExcps++;
      mWriter.Error("unhandled exception was thrown");
      mWriter.Line(String.Format("\t: {0}", msg));
    }
    public void ReportSingleNullObject(object actual, object expected)
    {
      if (actual == null)
        ReportFailedAssert("the 'actual' object is null, the 'expected' is not");
      else
        ReportFailedAssert("the 'expected' object is null, the 'actual' is not");
    }
    public void ReportBothObjectsAreNull()
    {
      ReportFailedAssert("both 'actual' and 'expected' objects are null");
    }
    public void ReportBothObjectsAreEmpty()
    {
      ReportFailedAssert("both 'actual' and 'expected' have zero items");
    }
    public void ReportCountsDontMatch()
    {
      ReportFailedAssert("item counts don't match");
    }
	}
}

Statistics.cs

Synopsis
using System;

namespace ut
{
  internal class Statistics
  {
    private MessageWriter mWriter;
    public Statistics(MessageWriter writer)
    {
      mWriter = writer;
    }

    public int mNumUnitTests = 0;
    public int mNumTestMethods = 0;
    public int mNumAsserts = 0;
    public int mNumErrors = 0;
    public int mNumExcps  = 0;
  
    public void dump()
    {
      mWriter.Line("Number of unit tests  : " + mNumUnitTests);
      mWriter.Line("Number of test methods: " + mNumTestMethods);
      mWriter.Line("Number of assert calls: " + mNumAsserts);
      mWriter.Line("Number of errors      : " + mNumErrors);
      mWriter.Line("Number of exceptions  : " + mNumExcps);
    }
  }

}

TestRunner.cs

Synopsis
using System;
using System.Reflection;

namespace ut
{
  internal class TestRunner
  {
    private Reporter mReporter;

    public TestRunner(Reporter rep)
    {
      mReporter = rep;
    }
    public void RunTestsInAssembly(string path)
    {
      foreach (Type type in Assembly.LoadFrom(path).GetTypes())
        RunAllTests(type);
    }
    private void RunAllTests(Type type)
    {
      if (!type.Name.StartsWith(Globals.ClassNamePrefix)) return;

      mReporter.IncUnitTests();
      UnitTestClass utc = new UnitTestClass(mReporter, type);
      utc.CreateInstance();
      utc.CheckMethods();
    }
  }
}

UnitTestClass.cs

Synopsis
using System;
using System.Reflection;

namespace ut
{
  internal class UnitTestClass
  {
    private Reporter mReporter;
    private Type mType;
    private object mInstance;

    public UnitTestClass(Reporter rep, Type type)
    {
      mReporter = rep;
      mType = type;
    }
    public void CreateInstance()
    {
      mInstance = Activator.CreateInstance(mType);
    }
    public void CheckMethods()
    {
      UnitTestMethod utm = new UnitTestMethod(mReporter, mInstance);
      foreach (MethodInfo mi in mType.GetMethods())
        utm.Check(mi);
    }
  }
}

UnitTestMethod.cs

Synopsis
using System;
using System.Reflection;

namespace ut
{
  internal class UnitTestMethod
  {
    private Reporter mReporter;
    private MethodInfo mMethod;
    private object mClassInstance;

    public UnitTestMethod(Reporter rep, object instance)
    {
      mReporter = rep;
      mClassInstance = instance;
    }
    public void Check(MethodInfo mi)
    {
      if (!IsATest(mi)) return;
      mMethod = mi;
      mReporter.TestName = mMethod.Name;
      try
      {
        CheckSignature();
        Invoke();
      } 
      catch (InvalidUnitTestMethodException ex)
      {
        mReporter.ReportInvalidTest(ex.Message);
      }
      catch(Exception ex)
      {
        mReporter.ReportException(ex.InnerException.Message);
      }
    }
    private bool IsATest(MethodInfo mi)
    {
      return mi.Name.StartsWith(Globals.MethodNamePrefix);
    }
    private void Invoke()
    {
      mReporter.IncTestMethods();
      mMethod.Invoke(mClassInstance, null);
    }
    private void CheckSignature()
    {
      if (!HasVoidReturnType()) 
        throw new InvalidUnitTestMethodException("return type must be void");

      if (!HasNoParameters())
        throw new InvalidUnitTestMethodException("must take 0 parameters");
    }
    private bool HasNoParameters()
    {
      return mMethod.GetParameters().Length == 0;
    }
    private bool HasVoidReturnType()
    {
      return mMethod.ReturnType.Name.Equals("Void");
    }
    class InvalidUnitTestMethodException : Exception
    {
      public InvalidUnitTestMethodException(string m) : base(m)
      {
      }
    }
  }
}

utcs.cs

Synopsis
using System;

namespace ut 
{
  public class utcs
  {
    public utcs(string[] args)
    {
      Reporter reporter = new Reporter();
      utx.Set(reporter, new Asserter(reporter));
      TestRunner runner = new TestRunner(reporter);
      foreach(string arg in args)
        runner.RunTestsInAssembly(arg);
      reporter.dump();
    }
  }
}

utcstest.cs

Synopsis
using System;
using System.IO;
using System.Collections;
using ut;

public class testutcs
{
  public void testcsharpequalequal()
  {
    //verify the '==' works the way I think it does
    object oA = "s";
    object oB = "s";
    utx.assert(oA == oB);

    object o1 = "s";
    object o2 = "s ".Trim();
    utx.assert(o1 != o2);
    utx.assert("objs as strings", (string) o1, (string) o2);

    object obj1 = new object();
    object obj2 = new object();
    utx.assert(obj1 != obj2);
    utx.assert(!obj1.Equals(obj2)); //compare is equivalent to 'obj1 != obj2'
    utx.assert(obj1.ToString(), obj2.ToString()); //bogus! compares the types!

    object t1 = new ArrayList();
    object t2 = new object();
    utx.assert(t1 != t2);
    utx.assert(!t1.Equals(t2)); //compare is equivalent to 'obj1 != obj2'
    
    //bogus! just compares the types!
    utx.assert(t1.ToString(), t1.ToString());
  }

  public void test_sample_failure_message()
  {
//    utx.assert(1, 0);
//    utx.assert("message here", 1, 0);
  }

  //bools
  public void testliterals_bool()
  {
    utx.assert("bool", true);
    utx.assert(true);
    utx.assertNextAssertFails();
    utx.assert(false);

    utx.assertnot("!bool", false);
    utx.assertnot(false);
    utx.assertNextAssertFails();
    utx.assertnot(true);
  }
  public void testvariables_bool()
  {
    bool b = true;
    utx.assert("bool", b);
    utx.assert(b);
    utx.assertNextAssertFails();
    utx.assert(!b);

    utx.assertnot("bool", !b);
    utx.assertnot(!b);
    utx.assertNextAssertFails();
    utx.assertnot(b);
  }

  //int
  public void testliterals_int()
  {
    utx.assert("ints", 1, 1);
    utx.assert(1, 1);
    utx.assertNextAssertFails();
    utx.assert(1, 2);

    utx.assertnot("ints", 1, 2);
    utx.assertnot(1, 2);
    utx.assertNextAssertFails();
    utx.assertnot(1, 1);
  }
  public void testvariables_int()
  {
    int i1 = 1;
    int i2 = 1;
    int i3 = 1;
    int i4 = 2;
    utx.assert((object) i1 != (object)i2);
    utx.assert("ints", i1, i2);
    utx.assert(i1, i2);
    utx.assertNextAssertFails();
    utx.assert(i3, i4);

    utx.assert((object) i3 != (object)i4);
    utx.assertnot("!ints", i3, i4);
    utx.assertnot(i3, i4);
    utx.assertNextAssertFails();
    utx.assertnot(i1, i2);
  }

  //chars
  public void testliterals_chars()
  {
    utx.assert("chars", 'a', 'a');
    utx.assert('a', 'a');
    utx.assertNextAssertFails();
    utx.assert('a', 'b');

    utx.assertnot("!chars", 'a', 'b');
    utx.assertnot('a', 'b');
    utx.assertNextAssertFails();
    utx.assertnot('a', 'a');
  }
  public void testvariables_char()
  {
    char c1 = 'a';
    char c2 = 'a';
    char c3 = 'a';
    char c4 = 'b';
    utx.assert((object) c1 != (object)c2);
    utx.assert("chars", c1, c2);
    utx.assert(c1, c2);
    utx.assertNextAssertFails();
    utx.assert(c3, c4);

    utx.assert((object) c3 != (object)c4);
    utx.assertnot("!chars", c3, c4);
    utx.assertnot(c3, c4);
    utx.assertNextAssertFails();
    utx.assertnot(c1, c2);
  }

  //bytes
  public void testliterals_bytes()
  {
    utx.assert("bytes", (byte) 0x01, (byte) 0x01);
    utx.assert((byte) 0x01, (byte) 0x01);
    utx.assertNextAssertFails();
    utx.assert((byte) 0x01, (byte) 0x02);

    utx.assertnot("bytes", (byte) 0x01, (byte) 0x02);
    utx.assertnot((byte) 0x01, (byte) 0x02);
    utx.assertNextAssertFails();
    utx.assertnot((byte) 0x01, (byte) 0x01);
  }
  public void testvariables_byte()
  {
    byte b1 = 0x01;
    byte b2 = 0x01;
    byte b3 = 0x01;
    byte b4 = 0x02;

    utx.assert((object) b1 != (object)b2);
    utx.assert("bytes", b1, b2);
    utx.assert(b1, b2);
    utx.assertNextAssertFails();
    utx.assert(b3, b4);

    utx.assert((object) b3 != (object)b4);
    utx.assertnot("!bytes", b3, b4);
    utx.assertnot(b3, b4);
    utx.assertNextAssertFails();
    utx.assertnot(b1, b2);
  }

  //double
  public void testliterals_doubles()
  {
    utx.assert("doubles", 1.0, 1.0, 0.0);
    utx.assert(1.0, 1.0, 0.01);
    utx.assertNextAssertFails();
    utx.assert(1.0, 1.1, 0.01);

    utx.assertnot("doubles", 1.0, 2.0, 0.1);
    utx.assertnot(1.0, 2.0, 0.1);
    utx.assertNextAssertFails();
    utx.assertnot(1.0, 1.01, 0.01);
  }
  public void testliterals_doubles_tolerance()
  {
    utx.assert(1.0, 1.0001, 0.1);
    utx.assert(1.0, 1.0001, 0.001);
    utx.assert(1.0, 1.0001, 0.0001);
    utx.assertNextAssertFails();
    utx.assert(1.0, 1.0001, 0.00001);
  }
  public void testvariables_double()
  {
    double d1 = 1.0;
    double d2 = 1.0;
    double d3 = 1.0;
    double d4 = 2.0;

    utx.assert((object) d1 != (object)d2);
    utx.assert("doubles", d1, d2);
    utx.assert(d1, d2);
    utx.assertNextAssertFails();
    utx.assert(d3, d4);

    utx.assert((object) d3 != (object)d4);
    utx.assertnot("!doubles", d3, d4);
    utx.assertnot(d3, d4);
    utx.assertNextAssertFails();
    utx.assertnot(d1, d2);
  }

  //strings
  public void testliterals_strings()
  {
    utx.assert("strings", "s1", "s1");
    utx.assert("s1", "s1");
    utx.assertNextAssertFails();
    utx.assert("s1", "s2");

    utx.assertnot("!strings", "s1", "s2");
    utx.assertnot("s1", "s2");
    utx.assertNextAssertFails();
    utx.assertnot("s1", "s1");
  }
  public void testvariables_string()
  {
    string s1 = "s";
    string s2 = "s ".Trim();  //creates a new object
    string s3 = "s";
    string s4 = "x ".Trim();  //creates a new object
    utx.assert((object) s1 != (object)s2);
    utx.assert("strings", s1, s2);
    utx.assert(s1, s2);
    utx.assertNextAssertFails();
    utx.assert(s3, s4);

    utx.assert((object) s3 != (object)s4);
    utx.assertnot("strings", s3, s4);
    utx.assertnot(s3, s4);
    utx.assertNextAssertFails();
    utx.assertnot(s1, s2);
  }

  //objects
  public void test_objects()
  {
    object s1 = "s";
    object s2 = s1;  //creates a new object
    object s3 = "s";
    object s4 = "x";  //creates a new object
    utx.assert("objects", s1, s2);
    utx.assert(s1, s2);
    utx.assertNextAssertFails();
    utx.assert(s3, s4);

    utx.assertnot("objects", s3, s4);
    utx.assertnot(s3, s4);
    utx.assertNextAssertFails();
    utx.assertnot(s1, s2);
  }
  public void test_object_nulls()
  {
    object x = null;
    utx.assert(x, null);
    utx.assert(null, x);
    
    utx.assertNextAssertFails();
    utx.assertnot(null, x);

    utx.assertNextAssertFails();
    utx.assertnot(x, null);
  }

  //lists
  public void test_list()
  {
    ArrayList l1 = new ArrayList(new object[] {"a", "b"});
    ArrayList l2 = new ArrayList(new object[] {"a", "b"});
    utx.assert("list", l1, l2);
    utx.assert(l1, l1);
    utx.assert(l1, l2);

    utx.assertNextAssertFails();
    utx.assertnot(l1, l1);
    utx.assertNextAssertFails();
    utx.assertnot("list", l1, l1);
    utx.assertNextAssertFails();
    utx.assertnot(l1, l2);
    utx.assertNextAssertFails();
    utx.assertnot("list", l1, l2);
  }
  public void test_list_empty()
  {
    utx.assert("list2",  new ArrayList(), new ArrayList());
    utx.assert(new ArrayList(), new ArrayList());

    utx.assertNextAssertFails();
    utx.assertnot("list2",  new ArrayList(), new ArrayList());
    utx.assertNextAssertFails();
    utx.assertnot(new ArrayList(), new ArrayList());
  }
  public void test_list_null()
  {
    utx.assert("list", (ICollection) null, (ICollection) null);
    utx.assert((ICollection) null, (ICollection) null);
    
    utx.assertNextAssertFails();
    utx.assert("list", (ICollection) null, new ArrayList());
    utx.assertNextAssertFails();
    utx.assert((ICollection) null, new ArrayList());
  
    utx.assertnot("list2", (ICollection) null, new ArrayList());
    utx.assertnot((ICollection) null, new ArrayList());
    
    utx.assertNextAssertFails();
    utx.assertnot((ICollection) null, (ICollection) null);
    utx.assertNextAssertFails();
    utx.assertnot("list", (ICollection) null, (ICollection) null);
  }
  public void test_list_lengths()
  {
    ArrayList l1 = new ArrayList(new object[] {"a", "b", "c"});
    ArrayList l2 = new ArrayList(new object[] {"a", "b"});
    utx.assertnot("list", l1, l2);
    utx.assertnot(l1, l2);

    utx.assertNextAssertFails();
    utx.assert(l1, l2);
    utx.assertNextAssertFails();
    utx.assert("list", l1, l2);
  }

//  public void test_excp()
//  {
//    int x = 0;
//    x = 6 / x;
//  }

  public void test_junk()
  {
    ArrayList list1 = new ArrayList(new object[] {"a", "<missing>", "c"});
    ArrayList list2 = new ArrayList(new object[] {"a", "b", "c"});
    utx.assertnot(list1, list2);
  }
}






Contact me about content on this page using john_web-at-arrizza-dot-com
For Web Master or site problems contact: webadmin-at-arrizza-dot-com
Copyright John Arrizza (c) 2001-2010