1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152
|
//
// BooleanTest.cs - NUnit Test Cases for the System.Boolean class
//
// Authors
// Bob Doan <bdoan@sicompos.com>
// Sebastien Pouliot <sebastien@ximian.com>
//
// (C) Ximian, Inc. http://www.ximian.com
// Copyright (C) 2004 Novell (http://www.novell.com)
//
using NUnit.Framework;
using System;
using System.Globalization;
namespace MonoTests.System {
[TestFixture]
public class BooleanTest {
[Test]
public void Strings ()
{
Assert.AreEqual("False", Boolean.FalseString, "Wrong False string");
Assert.AreEqual("True", Boolean.TrueString, "Wrong True string");
}
[Test]
public void CompareTo ()
{
Boolean t=true,f=false;
Assert.IsTrue (f.CompareTo(t) < 0, "f.CompareTo(t) < 0");
Assert.IsTrue (f.CompareTo(f) == 0, "f.CompareTo(f)");
Assert.IsTrue (t.CompareTo(t) == 0, "t.CompareTo(t) == 0");
Assert.IsTrue (t.CompareTo(f) > 0, "t.CompareTo(f) > 0");
Assert.IsTrue (t.CompareTo(null) > 0, "t.CompareTo(null) > 0");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (f.CompareTo(t2) < 0, "f.CompareTo(t2) < 0");
Assert.IsTrue (t2.CompareTo(t2) == 0, "t2.CompareTo(t2) == 0");
Assert.IsTrue (t2.CompareTo(f) > 0, "t2.CompareTo(f) > 0");
Assert.IsTrue (t2.CompareTo(null) > 0, "t2.CompareTo(null) > 0");
}
[Test]
[ExpectedException (typeof (ArgumentException))]
public void CompareToInvalidString ()
{
true.CompareTo ("What Ever");
}
[Test]
public void TestEquals ()
{
Boolean t=true, f=false;
string s = "What Ever";
Assert.IsTrue (t.Equals(t), "t.Equals(t)");
Assert.IsTrue (f.Equals(f), "f.Equals(f)");
Assert.IsTrue (!t.Equals(f), "!t.Equals(f)");
Assert.IsTrue (!f.Equals(t), "!f.Equals(t)");
Assert.IsTrue (!t.Equals(null), "!t.Equals(null)");
Assert.IsTrue (!f.Equals(null), "!f.Equals(null)");
Assert.IsTrue (!t.Equals(s), "!t.Equals(s)");
Assert.IsTrue (!f.Equals(s), "!f.Equals(s)");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (t2.Equals(t2), "t2.Equals(t2)");
Assert.IsTrue (t.Equals(t2), "t.Equals(t2)");
Assert.IsTrue (t2.Equals(t), "t2.Equals(t)");
Assert.IsTrue (!f.Equals(t2), "!f.Equals(t2)");
}
#pragma warning disable 1718
[Test]
public void TestEqualOperator ()
{
Boolean t=true, f=false;
Assert.IsTrue (t==t, "t==t");
Assert.IsTrue (f==f, "f==f");
Assert.IsTrue (t!=f, "t!=f");
Assert.IsTrue (f!=t, "f!=t");
byte[] array = new byte [1] { 0x02 };
bool t2 = BitConverter.ToBoolean (array, 0);
Assert.IsTrue (t2==t2, "t2==t2");
Assert.IsTrue (t==t2, "t==t2");
Assert.IsTrue (t2==t, "t2==t");
Assert.IsTrue (f!=t2, "f!=t2");
}
#pragma warning restore 1718
[Test]
public void TestGetHashCode ()
{
Boolean t=true, f=false;
Assert.AreEqual(1, t.GetHashCode(), "GetHashCode True failed");
Assert.AreEqual(0, f.GetHashCode(), "GetHashCode True failed");
}
[Test]
public void TestGetType ()
{
Boolean t=true, f=false;
Assert.AreEqual(true, Object.ReferenceEquals(t.GetType(), f.GetType()), "GetType failed");
}
[Test]
public void GetTypeCode ()
{
Boolean b=true;
Assert.AreEqual(TypeCode.Boolean, b.GetTypeCode(), "GetTypeCode failed");
}
[Test]
public void Parse ()
{
Assert.AreEqual(true, Boolean.Parse("True"), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse(" True"), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse("True "), "Parse True failed");
Assert.AreEqual(true, Boolean.Parse("tRuE"), "Parse True failed");
Assert.AreEqual(false, Boolean.Parse("False"), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse(" False"), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse("False "), "Parse False failed");
Assert.AreEqual(false, Boolean.Parse("fAlSe"), "Parse False failed");
}
[Test]
[ExpectedException (typeof (FormatException))]
public void ParseInvalid ()
{
Boolean.Parse ("not-t-or-f");
}
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public void ParseNull ()
{
Boolean.Parse (null);
}
[Test]
public void TestToString ()
{
Boolean t=true,f=false;
Assert.AreEqual(Boolean.TrueString, t.ToString(), "ToString True Failed");
Assert.AreEqual(Boolean.FalseString, f.ToString(), "ToString False Failed");
}
}
}
|