From: Donald L M. Jr. <lu...@us...> - 2004-12-10 18:25:09
|
Update of /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5667/src/Nullables.Tests Modified Files: NullableBooleanFixture.cs NullableByteFixture.cs NullableDateTimeFixture.cs NullableDecimalFixture.cs NullableDoubleFixture.cs NullableGuidFixture.cs NullableInt16Fixture.cs NullableInt32Fixture.cs NullableInt64Fixture.cs NullableSingleFixture.cs Added Files: NullableSByteFixture.cs Log Message: Implemented IComparable. Added NullableSByte, but it is inactive until further investigation. Index: NullableBooleanFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableBooleanFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableBooleanFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableBooleanFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 19,22 **** --- 19,47 ---- // } + + [Test] + public void BooleanIComparableTest() + { + NullableBoolean x; + NullableBoolean y; + + //one null, one not + x = NullableBoolean.Default; + y = new NullableBoolean(true); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableBoolean.Default; + y = NullableBoolean.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableBoolean(false); + y = new NullableBoolean(true); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableGuidFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableGuidFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableGuidFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableGuidFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void GuidIComparableTest() + { + NullableGuid x; + NullableGuid y; + + //one null, one not + x = NullableGuid.Default; + y = new NullableGuid(new Guid("12345678-1234-1234-1234-123456789012")); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableGuid.Default; + y = NullableGuid.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableGuid(new Guid("12345678-1234-1234-1234-123456789001")); + y = new NullableGuid(new Guid("12345678-1234-1234-1234-123456789099")); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableDateTimeFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableDateTimeFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDateTimeFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableDateTimeFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void DateTimeIComparableTest() + { + NullableDateTime x; + NullableDateTime y; + + //one null, one not + x = NullableDateTime.Default; + y = new NullableDateTime(new DateTime(2000, 12, 25)); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableDateTime.Default; + y = NullableDateTime.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableDateTime(new DateTime(2000, 11, 1)); + y = new NullableDateTime(new DateTime(2000, 12, 25)); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableInt16Fixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableInt16Fixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt16Fixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableInt16Fixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void Int16IComparableTest() + { + NullableInt16 x; + NullableInt16 y; + + //one null, one not + x = NullableInt16.Default; + y = new NullableInt16(16); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableInt16.Default; + y = NullableInt16.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableInt16(5); + y = new NullableInt16(43); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableDoubleFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableDoubleFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDoubleFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableDoubleFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void DoubleIComparableTest() + { + NullableDouble x; + NullableDouble y; + + //one null, one not + x = NullableDouble.Default; + y = new NullableDouble(0.5); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableDouble.Default; + y = NullableDouble.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableDouble(0.6); + y = new NullableDouble(0.67); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableInt64Fixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableInt64Fixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt64Fixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableInt64Fixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 44,47 **** --- 44,72 ---- } + [Test] + public void Int64IComparableTest() + { + NullableInt64 x; + NullableInt64 y; + + //one null, one not + x = NullableInt64.Default; + y = new NullableInt64(16); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableInt64.Default; + y = NullableInt64.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableInt64(5); + y = new NullableInt64(43); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } + } } \ No newline at end of file Index: NullableDecimalFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableDecimalFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableDecimalFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableDecimalFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void DecimalIComparableTest() + { + NullableDecimal x; + NullableDecimal y; + + //one null, one not + x = NullableDecimal.Default; + y = new NullableDecimal(10.03m); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableDecimal.Default; + y = NullableDecimal.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableDecimal(15.3m); + y = new NullableDecimal(18.02m); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } --- NEW FILE: NullableSByteFixture.cs --- using System; using Nullables; using NUnit.Framework; namespace Nullables.Tests { /// <summary> /// Summary description for NullableSByteFixture. /// </summary> [TestFixture] public class NullableSByteFixture { public NullableSByteFixture() { } [Test] public void BasicTestSByte() { NullableSByte v1 = 32; //should take an int literal Assert.IsTrue(v1.HasValue); //should have a value; Assert.IsTrue(v1.Equals(32)); //implicit casting should make this result in true. Assert.IsTrue(v1.Value == 32); Assert.IsFalse(v1.Equals(NullableSByte.Default)); Assert.IsTrue(v1.Equals(new NullableSByte(32))); //should == a new instance with the same inner value. //same thing, but with == instead of .Equals() Assert.IsTrue(v1 == 32); Assert.IsFalse(v1 == 33); Assert.IsFalse(v1 == NullableSByte.Default); Assert.IsTrue(v1 == new NullableSByte(32)); //now null v1. v1 = DBNull.Value; Assert.IsTrue(v1 == NullableSByte.Default); v1 = NullableSByte.Default; Assert.IsTrue(v1 == NullableSByte.Default); NullableSByte v2 = NullableSByte.Default; //should start as "null" Assert.IsFalse(v2.HasValue); Assert.IsFalse(v2.Equals(12)); Assert.IsTrue(v2.Equals(NullableSByte.Default)); Assert.IsTrue(v2.Equals(DBNull.Value)); } [Test] public void SByteIComparableTest() { NullableSByte x; NullableSByte y; //one null, one not x = NullableSByte.Default; y = new NullableSByte(16); Assert.IsTrue(x.CompareTo(y) < 0); Assert.IsTrue(y.CompareTo(x) > 0); //now both null x = NullableSByte.Default; y = NullableSByte.Default; Assert.IsTrue(x.CompareTo(y) == 0); Assert.IsTrue(y.CompareTo(x) == 0); //now both with a value x = new NullableSByte(5); y = new NullableSByte(43); Assert.IsTrue(x.CompareTo(y) < 0); Assert.IsTrue(y.CompareTo(x) > 0); } } } Index: NullableSingleFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableSingleFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableSingleFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableSingleFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void SingleIComparableTest() + { + NullableSingle x; + NullableSingle y; + + //one null, one not + x = NullableSingle.Default; + y = new NullableSingle(1.6f); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableSingle.Default; + y = NullableSingle.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableSingle(5.1f); + y = new NullableSingle(8.9f); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableByteFixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableByteFixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableByteFixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableByteFixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 43,46 **** --- 43,71 ---- Assert.IsTrue(v2.Equals(DBNull.Value)); } + + [Test] + public void ByteIComparableTest() + { + NullableByte x; + NullableByte y; + + //one null, one not + x = NullableByte.Default; + y = new NullableByte(12); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableByte.Default; + y = NullableByte.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableByte(5); + y = new NullableByte(101); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } Index: NullableInt32Fixture.cs =================================================================== RCS file: /cvsroot/nhibernate/NHibernateContrib/src/Nullables.Tests/NullableInt32Fixture.cs,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** NullableInt32Fixture.cs 6 Dec 2004 03:17:00 -0000 1.1 --- NullableInt32Fixture.cs 10 Dec 2004 18:24:20 -0000 1.2 *************** *** 44,47 **** --- 44,72 ---- Assert.IsTrue( v2==null ); } + + [Test] + public void Int32IComparableTest() + { + NullableInt32 x; + NullableInt32 y; + + //one null, one not + x = NullableInt32.Default; + y = new NullableInt32(16); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + + //now both null + x = NullableInt32.Default; + y = NullableInt32.Default; + Assert.IsTrue(x.CompareTo(y) == 0); + Assert.IsTrue(y.CompareTo(x) == 0); + + //now both with a value + x = new NullableInt32(5); + y = new NullableInt32(43); + Assert.IsTrue(x.CompareTo(y) < 0); + Assert.IsTrue(y.CompareTo(x) > 0); + } } } |