public void Test01() { BitVector32 bv32; BitVector32 bv32_1; // extra BitVector32 - for comparison int data = 0; // [] two BitVectors that are the same - expected true //----------------------------------------------------------------- bv32 = new BitVector32(); bv32_1 = new BitVector32(); if (!bv32.Equals(bv32_1)) { Assert.False(true, string.Format("Error, two default structs are not equal")); } // generate random data value data = -55; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); if (!bv32.Equals(bv32_1)) { Assert.False(true, string.Format("Error, two vectores with random data are not equal")); } if (bv32.Equals(null)) { Assert.False(true, string.Format("Error, vector and null are equal")); } bv32 = new BitVector32(data); if (data < Int32.MaxValue) { data++; } else { data--; } bv32_1 = new BitVector32(data); if (bv32.Equals(bv32_1)) { Assert.False(true, string.Format("Error, two different vectors are equal")); } bv32 = new BitVector32(data); if (bv32.Equals(data)) { Assert.False(true, string.Format("Error, vector and non-vector-object are equal")); } }
public void Test01() { BitVector32 bv32; BitVector32 bv32Temp; // extra BitVector32 - for comparison // [] BitVector is constructed as expected //----------------------------------------------------------------- bv32 = new BitVector32(); if (bv32.Data != 0) { Assert.False(true, string.Format("Error, Data = {0} after default ctor", bv32.Data)); } string result = bv32.ToString(); if (result.IndexOf("BitVector32") == -1) { // "BitVector32" is not a part of ToString() Assert.False(true, "Error: ToString() doesn't contain \"BitVector32\""); } bool item = bv32[1]; if (item) { Assert.False(true, string.Format("Error: Item(0) returned {0} instead of {1}", item, false)); } bv32Temp = new BitVector32(); if (!bv32.Equals(bv32Temp)) { Assert.False(true, string.Format("Error: two default vectors are not equal")); } }
public void Constructors() { BitVector32 b = new BitVector32(31); Assert.AreEqual(31, b.Data, "Data"); Assert.IsTrue(b.Equals(b), "Equals(self)"); Assert.IsTrue(b[31], "31"); Assert.IsFalse(b[32], "32"); Assert.AreEqual(b.ToString(), "BitVector32{00000000000000000000000000011111}", b.ToString()); BitVector32 b2 = new BitVector32(b); Assert.IsTrue(b.Equals(b2), "Equals(b2)"); Assert.AreEqual(b.GetHashCode(), b2.GetHashCode(), "GetHashCode=="); b2[32] = true; Assert.IsFalse(b.Equals(b2), "Equals(b32)"); Assert.IsFalse(b.GetHashCode() == b2.GetHashCode(), "GetHashCode!="); }
public static void EqualsTest() { BitVector32 original = new BitVector32(); Assert.True(original.Equals(original)); Assert.True(new BitVector32().Equals(original)); Assert.True(original.Equals(new BitVector32())); Assert.True(new BitVector32(0).Equals(original)); Assert.True(original.Equals(new BitVector32(0))); BitVector32 other = new BitVector32(int.MaxValue / 2 - 1); Assert.True(other.Equals(other)); Assert.True(new BitVector32(int.MaxValue / 2 - 1).Equals(other)); Assert.True(other.Equals(new BitVector32(int.MaxValue / 2 - 1))); Assert.False(other.Equals(original)); Assert.False(original.Equals(other)); Assert.False(other.Equals(null)); Assert.False(original.Equals(null)); Assert.False(other.Equals(int.MaxValue / 2 - 1)); Assert.False(original.Equals(0)); }
public static void EqualsTest() { BitVector32 original = new BitVector32(); Assert.True(original.Equals(original)); Assert.True(new BitVector32().Equals(original)); Assert.True(original.Equals(new BitVector32())); Assert.True(new BitVector32(0).Equals(original)); Assert.True(original.Equals(new BitVector32(0))); BitVector32 other = new BitVector32(int.MaxValue / 2 - 1); Assert.True(other.Equals(other)); Assert.True(new BitVector32(int.MaxValue / 2 - 1).Equals(other)); Assert.True(other.Equals(new BitVector32(int.MaxValue / 2 - 1))); Assert.False(other.Equals(original)); Assert.False(original.Equals(other)); Assert.False(other.Equals(null)); Assert.False(original.Equals(null)); Assert.False(other.Equals(int.MaxValue / 2 - 1)); Assert.False(original.Equals(0)); }
public static void Section_Unequal_EqualsTest(BitVector32.Section left, BitVector32.Section right) { Assert.False(left.Equals(right)); Assert.False(right.Equals(left)); Assert.False(left.Equals((object)right)); Assert.False(right.Equals((object)left)); Assert.False(left.Equals(new object())); Assert.False(left == right); Assert.False(right == left); Assert.True(left != right); Assert.True(right != left); }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32Temp; try { Console.WriteLine("--- default ctor ---"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); Console.WriteLine("1. check Data"); if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } iCountTestcases++; Console.WriteLine("2. check returned Type"); string type = bv32.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + type); if (type.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0002: returned type doesn't contain \"BitVector32\""); } bv32Temp = new BitVector32(3); string type1 = bv32Temp.GetType().ToString().Trim(); if (String.Compare(type, type1) != 0) { iCountErrors++; Console.WriteLine("Err_0003: returned types of two vectors differ"); } iCountTestcases++; Console.WriteLine("3. call ToString()"); string result = bv32.ToString(); Console.WriteLine(" ToString(): " + result); if (result.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0004: ToString() doesn't contain \"BitVector32\""); } iCountTestcases++; Console.WriteLine("4. Item(1)"); bool item = bv32[1]; Console.WriteLine(" Item(1): " + item); if (item) { iCountErrors++; Console.WriteLine("Err_0005: Item(0) returned {0} instead of {1}", item, false); } iCountTestcases++; Console.WriteLine("5. Equals"); bv32Temp = new BitVector32(); if (! bv32.Equals(bv32Temp) ) { iCountErrors++; Console.WriteLine("Err_0006: two default vectors are not equal"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32Temp; try { Console.WriteLine("--- default ctor ---"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); Console.WriteLine("1. check Data"); if (bv32.Data != 0) { iCountErrors++; Console.WriteLine("Err_0001, Data = {0} after default ctor", bv32.Data); } iCountTestcases++; Console.WriteLine("2. check returned Type"); string type = bv32.GetType().ToString().Trim(); Console.WriteLine(" GetType(): " + type); if (type.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0002: returned type doesn't contain \"BitVector32\""); } bv32Temp = new BitVector32(3); string type1 = bv32Temp.GetType().ToString().Trim(); if (String.Compare(type, type1) != 0) { iCountErrors++; Console.WriteLine("Err_0003: returned types of two vectors differ"); } iCountTestcases++; Console.WriteLine("3. call ToString()"); string result = bv32.ToString(); Console.WriteLine(" ToString(): " + result); if (result.IndexOf("BitVector32") == -1) { iCountErrors++; Console.WriteLine("Err_0004: ToString() doesn't contain \"BitVector32\""); } iCountTestcases++; Console.WriteLine("4. Item(1)"); bool item = bv32[1]; Console.WriteLine(" Item(1): " + item); if (item) { iCountErrors++; Console.WriteLine("Err_0005: Item(0) returned {0} instead of {1}", item, false); } iCountTestcases++; Console.WriteLine("5. Equals"); bv32Temp = new BitVector32(); if (!bv32.Equals(bv32Temp)) { iCountErrors++; Console.WriteLine("Err_0006: two default vectors are not equal"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("Pass. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("Fail! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32_1; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); if (!bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0001, two default structs are not equal"); } Console.WriteLine("2. two random vectors"); DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); if (!bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0002, two vectores with random data are not equal"); } Console.WriteLine("3. vector and null"); strLoc = "Loc_003oo"; iCountTestcases++; if (bv32.Equals(null)) { iCountErrors++; Console.WriteLine("Err_0003, vector and null are equal"); } Console.WriteLine("4. two different vectors"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) { data++; } else { data--; } bv32_1 = new BitVector32(data); if (bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0004, two different vectors are equal"); } Console.WriteLine("5. vector and non-vector-object"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Equals(data)) { iCountErrors++; Console.WriteLine("Err_0005, vector and non-vector-object are equal"); } } catch (Exception exc_general) { ++iCountErrors; Console.WriteLine(s_strTFAbbrev + " : Error Err_general! strLoc==" + strLoc + ", exc_general==\n" + exc_general.ToString()); } if (iCountErrors == 0) { Console.WriteLine("Pass. " + s_strTFPath + " " + s_strTFName + " ,iCountTestcases==" + iCountTestcases); return(true); } else { Console.WriteLine("Fail! " + s_strTFPath + " " + s_strTFName + " ,iCountErrors==" + iCountErrors + " , BugNums?: " + s_strActiveBugNums); return(false); } }
public static void Main() { // Creates and initializes a BitVector32 with the value 123. // This is the BitVector32 that will be compared to different types. BitVector32 myBV = new BitVector32(123); // Creates and initializes a new BitVector32 which will be set up as sections. BitVector32 myBVsect = new BitVector32(0); // Compares myBV and myBVsect. Console.WriteLine("myBV : {0}", myBV.ToString()); Console.WriteLine("myBVsect : {0}", myBVsect.ToString()); if (myBV.Equals(myBVsect)) { Console.WriteLine(" myBV({0}) equals myBVsect({1}).", myBV.Data, myBVsect.Data); } else { Console.WriteLine(" myBV({0}) does not equal myBVsect({1}).", myBV.Data, myBVsect.Data); } Console.WriteLine(); // Assigns values to the sections of myBVsect. BitVector32.Section mySect1 = BitVector32.CreateSection(5); BitVector32.Section mySect2 = BitVector32.CreateSection(1, mySect1); BitVector32.Section mySect3 = BitVector32.CreateSection(20, mySect2); myBVsect[mySect1] = 3; myBVsect[mySect2] = 1; myBVsect[mySect3] = 7; // Compares myBV and myBVsect. Console.WriteLine("myBV : {0}", myBV.ToString()); Console.WriteLine("myBVsect with values : {0}", myBVsect.ToString()); if (myBV.Equals(myBVsect)) { Console.WriteLine(" myBV({0}) equals myBVsect({1}).", myBV.Data, myBVsect.Data); } else { Console.WriteLine(" myBV({0}) does not equal myBVsect({1}).", myBV.Data, myBVsect.Data); } Console.WriteLine(); // Compare myBV with an Int32. Console.WriteLine("Comparing myBV with an Int32: "); Int32 myInt32 = 123; // Using Equals will fail because Int32 is not compatible with BitVector32. if (myBV.Equals(myInt32)) { Console.WriteLine(" Using BitVector32.Equals, myBV({0}) equals myInt32({1}).", myBV.Data, myInt32); } else { Console.WriteLine(" Using BitVector32.Equals, myBV({0}) does not equal myInt32({1}).", myBV.Data, myInt32); } // To compare a BitVector32 with an Int32, use the "==" operator. if (myBV.Data == myInt32) { Console.WriteLine(" Using the \"==\" operator, myBV.Data({0}) equals myInt32({1}).", myBV.Data, myInt32); } else { Console.WriteLine(" Using the \"==\" operator, myBV.Data({0}) does not equal myInt32({1}).", myBV.Data, myInt32); } }
public virtual bool runTest() { Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver: " + s_strDtTmVer); int iCountErrors = 0; int iCountTestcases = 0; String strLoc = "Loc_000oo"; BitVector32 bv32; BitVector32 bv32_1; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); if (! bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0001, two default structs are not equal"); } Console.WriteLine("2. two random vectors"); DateTime time = DateTime.Now; data = time.DayOfYear + time.Hour + time.Minute + time.Second; System.Random random = new System.Random(data); data = random.Next(System.Int32.MinValue, System.Int32.MaxValue); iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); if (! bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0002, two vectores with random data are not equal"); } Console.WriteLine("3. vector and null"); strLoc = "Loc_003oo"; iCountTestcases++; if (bv32.Equals(null)) { iCountErrors++; Console.WriteLine("Err_0003, vector and null are equal"); } Console.WriteLine("4. two different vectors"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) data++; else data--; bv32_1 = new BitVector32(data); if (bv32.Equals(bv32_1)) { iCountErrors++; Console.WriteLine("Err_0004, two different vectors are equal"); } Console.WriteLine("5. vector and non-vector-object"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); if (bv32.Equals(data)) { iCountErrors++; Console.WriteLine("Err_0005, vector and non-vector-object are equal"); } } catch (Exception exc_general ) { ++iCountErrors; Console.WriteLine (s_strTFAbbrev + " : Error Err_general! strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString()); } if ( iCountErrors == 0 ) { Console.WriteLine( "Pass. "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases); return true; } else { Console.WriteLine("Fail! "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums ); return false; } }