GetHashCode() 공개 메소드

public GetHashCode ( ) : int
리턴 int
예제 #1
0
		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!=");
		}
예제 #2
0
        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));
            }
        }