Ejemplo n.º 1
0
        public void HashCodeTest()
        {
            MutableString ar = new MutableString();

            ar.Clear();
            ar.Append("aba");
            ar.Append("caba");
            ar.Append("abacaba");
            MutableString ar1 = new MutableString();

            ar1.Clear();
            ar1.Append("abacaba");
            ar1.Append("abacaba");
            MutableString ar2 = new MutableString();

            ar2.Assign("abacabaabacaba");
            Assert.AreEqual(ar1.GetHashCode(), ar2.GetHashCode());
            Assert.AreEqual(ar1.GetHashCode(), ar.GetHashCode());
        }
Ejemplo n.º 2
0
        public static void TestHashCodeMultithread(TestedClass testWhat)
        {
            Int32 threadCount     = 2;
            Int32 iterationsCount = 1000000;


            BinaryArray   a           = new BinaryArray();
            MutableString s           = new MutableString();
            Barrier       beforeWrite = new Barrier(threadCount);
            Barrier       beforeRead  = new Barrier(threadCount);

            Action <int> action = (x) =>
            {
                while (index < iterationsCount)
                {
                    beforeWrite.SignalAndWait();
                    if ((previousIndex % threadCount) == x)
                    {
                        index++;
                        expectedHash = index;
                        switch (testWhat)
                        {
                        case TestedClass.BinaryArray: a.Assign(index); break;

                        case TestedClass.MutableString: s.Assign(index); expectedHash = s.Clone().GetHashCode(); break;
                        }
                        a.Assign(index);
                        if ((index % 100000) == 0)
                        {
                            Console.WriteLine("Index = " + index);
                        }
                    }
                    beforeRead.SignalAndWait();
                    int currentHash = 0;
                    switch (testWhat)
                    {
                    case TestedClass.BinaryArray: currentHash = a.GetHashCode(); break;

                    case TestedClass.MutableString: currentHash = s.GetHashCode(); break;
                    }
                    Assert.AreEqual(currentHash, expectedHash);
                    previousIndex = index;
                }
            };

            Task[] t = new Task[threadCount];
            for (int i = 0; i < threadCount; ++i)
            {
                int id = i;
                t[i] = new Task(() => action(id));
                t[i].Start();
            }

            Task.WaitAll(t);
        }
Ejemplo n.º 3
0
        public void op_GetHashCode()
        {
            var obj = new MutableString("Example");

            var expected = obj.ToString().GetHashCode();
            var actual = obj.GetHashCode();

            Assert.Equal(expected, actual);
        }