コード例 #1
0
        void SequencedTest(int start, int incr, int stop, string name)
        {
            int          count = Math.Abs(start - stop) / Math.Abs(incr);
            const string myTestValue1 = "T1", myTestValue2 = "t2";
            string       test;

            BTreeDictionary <int, string> tree = new BTreeDictionary <int, string>(8, Comparer);
            FactoryMethod <BTreeDictionary <int, string> > verify = delegate() { tree.DebugAssert(); return(tree); };
            Stopwatch time = new Stopwatch();

            time.Start();
            //large order-forward
            for (int i = start; i != stop; i += incr)
            {
                if (i == 988)
                {
                    i = 988;
                }
                if (!verify().TryAdd(i, myTestValue1))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} insert  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!verify().TryGetValue(i, out test) || test != myTestValue1)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek    {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!verify().TryUpdate(i, myTestValue2))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} modify  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (!verify().TryGetValue(i, out test) || test != myTestValue2)
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} seek#2  {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            int tmpCount = 0;

            foreach (KeyValuePair <int, string> tmp in verify())
            {
                if (tmp.Value != myTestValue2)
                {
                    throw new ApplicationException();
                }
                else
                {
                    tmpCount++;
                }
            }
            if (tmpCount != count)
            {
                throw new ApplicationException();
            }

            Trace.TraceInformation("{0} foreach {1} in {2}", name, count, time.ElapsedMilliseconds);
            time.Reset();
            time.Start();

            for (int i = start; i != stop; i += incr)
            {
                if (i == 16)
                {
                    i = 16;
                }
                if (!verify().Remove(i))
                {
                    throw new ApplicationException();
                }
            }

            Trace.TraceInformation("{0} delete  {1} in {2}", name, count, time.ElapsedMilliseconds);

            for (int i = start; i != stop; i += incr)
            {
                if (verify().TryGetValue(i, out test))
                {
                    throw new ApplicationException();
                }
            }
        }