public static void GetHashCodeTest() { BitVector32 original = new BitVector32(); Assert.Equal(original.GetHashCode(), original.GetHashCode()); Assert.Equal(new BitVector32().GetHashCode(), original.GetHashCode()); Assert.Equal(new BitVector32(0).GetHashCode(), original.GetHashCode()); BitVector32 other = new BitVector32(int.MaxValue / 2 - 1); Assert.Equal(other.GetHashCode(), other.GetHashCode()); Assert.Equal(new BitVector32(int.MaxValue / 2 - 1).GetHashCode(), other.GetHashCode()); }
/// <inheritdoc/> public override int GetHashCode() { int result = keys.GetHashCode(); result = 29 * result + flags.GetHashCode(); return(result); }
public void Constructors() { var bitVector = new BitVector32((uint)31); Assert.AreEqual(31, bitVector); Assert.IsTrue(bitVector[31]); Assert.IsFalse(bitVector[32]); Assert.AreEqual(bitVector.ToString(), "BitVector32{00000000000000000000000000011111}"); var bitVector2 = new BitVector32(bitVector); Assert.IsTrue(bitVector == bitVector2); Assert.AreEqual(bitVector.GetHashCode(), bitVector2.GetHashCode()); bitVector2[32] = true; Assert.IsFalse(bitVector == bitVector2); Assert.IsFalse(bitVector.GetHashCode() == bitVector2.GetHashCode()); }
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 Section_GetHashCodeTest(BitVector32.Section left, BitVector32.Section right) { Assert.Equal(left.GetHashCode(), left.GetHashCode()); Assert.Equal(left.GetHashCode(), right.GetHashCode()); }
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 code = 0; int code_1 = 0; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0001, HashCodes of two default structs: {0} != {1}", code, code_1); } 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); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0002, HashCodes of two equal vectors: {0} != {1}", code, code_1); } Console.WriteLine("3. two different vectors"); strLoc = "Loc_003oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) { data++; } else { data--; } bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code == code_1) { iCountErrors++; Console.WriteLine("Err_0003, HashCodes of two different vectors: {0} == {1}", code, code_1); } Console.WriteLine("4. same vector - default struct"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0004, HashCodes the same default struct: {0} != {1}", code, code_1); } Console.WriteLine("5. same vector"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0005, HashCodes the same vector: {0} != {1}", code, code_1); } data = 0; Console.WriteLine("6. two vectors({0})", data); strLoc = "Loc_006oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0006, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = 1; Console.WriteLine("7. two vectors({0})", data); strLoc = "Loc_007oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0007, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = -1; Console.WriteLine("8. two vectors({0})", data); strLoc = "Loc_008oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0008, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = Int32.MaxValue; Console.WriteLine("9. two vectors({0})", data); strLoc = "Loc_009oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0009, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = Int32.MinValue; Console.WriteLine("10. two vectors({0})", data); strLoc = "Loc_010oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0010, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } } 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 code = 0; int code_1 = 0; int data = 0; try { Console.WriteLine("1. two default structs"); strLoc = "Loc_001oo"; iCountTestcases++; bv32 = new BitVector32(); bv32_1 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0001, HashCodes of two default structs: {0} != {1}", code, code_1); } 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); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0002, HashCodes of two equal vectors: {0} != {1}", code, code_1); } Console.WriteLine("3. two different vectors"); strLoc = "Loc_003oo"; iCountTestcases++; bv32 = new BitVector32(data); if (data < Int32.MaxValue) data++; else data--; bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code == code_1) { iCountErrors++; Console.WriteLine("Err_0003, HashCodes of two different vectors: {0} == {1}", code, code_1); } Console.WriteLine("4. same vector - default struct"); strLoc = "Loc_004oo"; iCountTestcases++; bv32 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0004, HashCodes the same default struct: {0} != {1}", code, code_1); } Console.WriteLine("5. same vector"); strLoc = "Loc_005oo"; iCountTestcases++; bv32 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0005, HashCodes the same vector: {0} != {1}", code, code_1); } data = 0; Console.WriteLine("6. two vectors({0})", data); strLoc = "Loc_006oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0006, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = 1; Console.WriteLine("7. two vectors({0})", data); strLoc = "Loc_007oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0007, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = -1; Console.WriteLine("8. two vectors({0})", data); strLoc = "Loc_008oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0008, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = Int32.MaxValue; Console.WriteLine("9. two vectors({0})", data); strLoc = "Loc_009oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0009, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } data = Int32.MinValue; Console.WriteLine("10. two vectors({0})", data); strLoc = "Loc_010oo"; iCountTestcases++; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { iCountErrors++; Console.WriteLine("Err_0010, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data); } } 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 void Test01() { BitVector32 bv32; BitVector32 bv32_1; // extra BitVector32 - for comparison int code = 0; // HashCode of bv32 int code_1 = 0; // HashCode of bv32_1 int data = 0; // [] two BitVectors that are the same should return the same HashCode //----------------------------------------------------------------- bv32 = new BitVector32(); bv32_1 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two default structs: {0} != {1}", code, code_1)); } // 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); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two equal vectors: {0} != {1}", code, code_1)); } bv32 = new BitVector32(data); if (data < Int32.MaxValue) { data++; } else { data--; } bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code == code_1) { Assert.False(true, string.Format("Error, HashCodes of two different vectors: {0} == {1}", code, code_1)); } bv32 = new BitVector32(); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes the same default struct: {0} != {1}", code, code_1)); } bv32 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes the same vector: {0} != {1}", code, code_1)); } data = 0; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data)); } data = 1; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data)); } data = -1; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data)); } data = Int32.MaxValue; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data)); } data = Int32.MinValue; bv32 = new BitVector32(data); bv32_1 = new BitVector32(data); code = bv32.GetHashCode(); code_1 = bv32_1.GetHashCode(); if (code != code_1) { Assert.False(true, string.Format("Error, HashCodes of two {2}-vectors: {0} != {1}", code, code_1, data)); } }