Exemplo n.º 1
0
        public override bool Do(int seed, StochasticControls control)
        {
            IOrderedMap <int, float>[] collections = new IOrderedMap <int, float>[]
            {
                new ReferenceMap <int, float>(), // must be first

                new SplayTreeMap <int, float>(),
                new SplayTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new SplayTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new SplayTreeArrayList <KeyValue <int, float> >()),

                new RedBlackTreeMap <int, float>(),
                new RedBlackTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new RedBlackTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new RedBlackTreeArrayList <KeyValue <int, float> >()),

                new AVLTreeMap <int, float>(),
                new AVLTreeArrayMap <int, float>(),
                new AdaptListToMap <int, float>(new AVLTreeList <KeyValue <int, float> >()),
                new AdaptListToMap <int, float>(new AVLTreeArrayList <KeyValue <int, float> >()),
            };

            Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >[] actions = new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >[]
            {
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), ContainsKeyAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200, 200), SetOrAddValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200 - 50, 200 + 50), TryAddAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(300, 300), TryRemoveAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), TryGetValueAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), TrySetValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(200 - 50, 200 + 50), AddAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(300, 300), RemoveAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), GetValueAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), SetValueAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(50, 50), ConditionalAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), LeastAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), GreatestAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestLessOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestLessAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestGreaterOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(100, 100), NearestGreaterAction),

                new Tuple <Tuple <int, int>, InvokeAction <IOrderedMap <int, float> > >(new Tuple <int, int>(50, 50), EnumerateAction),
            };

            return(StochasticDriver(
                       "Map Stochastic Test",
                       seed,
                       control,
                       collections,
                       actions,
                       delegate(IOrderedMap <int, float> _collection) { return _collection.Count; },
                       delegate(IOrderedMap <int, float>[] _collections) { Validate <int, float>(_collections); }));
        }
Exemplo n.º 2
0
        public override bool Do(int seed, StochasticControls control)
        {
            IRangeList[] collections = new IRangeList[]
            {
                new ReferenceRangeList(), // must be first

                new SplayTreeRangeList(),
                new SplayTreeArrayRangeList(),
                new AdaptRangeListToRangeListLong(new SplayTreeRangeListLong()),

                new RedBlackTreeRangeList(),
                new RedBlackTreeArrayRangeList(),
                new AdaptRangeListToRangeListLong(new RedBlackTreeRangeListLong()),

                new AVLTreeRangeList(),
                new AVLTreeArrayRangeList(),
                new AdaptRangeListToRangeListLong(new AVLTreeRangeListLong()),
            };

            Tuple <Tuple <int, int>, InvokeAction <IRangeList> >[] actions = new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >[]
            {
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), ContainsAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(300 - 90, 300 + 100), TryInsertAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(300, 300), TryDeleteAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), TryGetLengthAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), TrySetLengthAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(300 - 90, 300 + 100), InsertAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(300, 300), DeleteAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), GetLengthAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), SetLengthAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(150, 150), AdjustLengthAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(100, 100), GetExtentAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(150, 150), NearestLessOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(150, 150), NearestLessAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(150, 150), NearestGreaterOrEqualAction),
                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(150, 150), NearestGreaterAction),

                new Tuple <Tuple <int, int>, InvokeAction <IRangeList> >(new Tuple <int, int>(75, 75), EnumerateAction),
            };

            return(StochasticDriver(
                       "Range Map Stochastic Test",
                       seed,
                       control,
                       collections,
                       actions,
                       delegate(IRangeList _collection) { return _collection.Count; },
                       delegate(IRangeList[] _collections) { Validate(_collections); }));
        }
Exemplo n.º 3
0
            public StochasticTestEntry(string token, TestBase testObject, ConsoleBuffer consoleBuffer, int seed, StochasticControls control)
            {
                this.token         = token;
                this.testObject    = testObject;
                this.consoleBuffer = consoleBuffer;
                this.control       = control;
                this.seed          = seed;

                testObject.ConsoleBuffer = consoleBuffer;
                consoleBuffer.Status     = "not started";

                this.thread          = new Thread(Do);
                this.thread.Priority = ThreadPriority.BelowNormal;
            }
Exemplo n.º 4
0
        public override bool Do(int seed, StochasticControls control)
        {
            script.AppendLine(String.Format("Seed: {0}", seed));

            IHugeList <int>[] lists = new IHugeList <int>[]
            {
                new ReferenceHugeList <int>(), // must be first

                new HugeList <int>(typeof(SplayTreeRangeMap <>), 47),
                new HugeList <int>(typeof(AVLTreeRangeMap <>), 512),

                new AdaptHugeListToHugeListLong <int>(new HugeListLong <int>(typeof(RedBlackTreeRangeMapLong <>), 47)),
                new AdaptHugeListToHugeListLong <int>(new HugeListLong <int>(typeof(SplayTreeRangeMapLong <>), 512)),
            };

            Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >[] actions = new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >[]
            {
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 400), ContainsAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 400), InsertAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 400), RemoveAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(1000, 2000), InsertRangeAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 400), RemoveRangeAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 400), ReplaceRangeAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(400, 200), RemoveAllAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(200, 200), CopyToAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(200, 200), IndexSearchAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(200, 200), LastIndexSearchAction),
                new Tuple <Tuple <int, int>, InvokeAction <IHugeList <int> > >(new Tuple <int, int>(100, 100), InsertRangeHugeListAction),
            };

            return(StochasticDriver(
                       "HugeList Stochastic Test",
                       seed,
                       control,
                       lists,
                       actions,
                       delegate(IHugeList <int> _list) { return (uint)_list.Count; },
                       delegate(IHugeList <int>[] _lists) { Validate(_lists); CheckScript(lists[0].Count); }));
        }
Exemplo n.º 5
0
        private static bool StochasticTests(Options options, bool enabled)
        {
            Console.Write("Stochastic Tests - Started [Seed ");
            ConsoleColor savedColor = Console.ForegroundColor;

            Console.ForegroundColor = ConsoleColor.Yellow;
            Console.Write("{0}", options.seed);
            Console.ForegroundColor = savedColor;
            Console.WriteLine("]");

            TestResultCode result = TestResultCode.Skipped;

            if (enabled)
            {
                result = TestResultCode.Failed;

                StochasticControls control = new StochasticControls();

                int bufferHeight1           = Math.Max(1, (Console.WindowHeight - 6) / StochasticTestCount - 2);
                StochasticTestEntry[] tests = new StochasticTestEntry[StochasticTestCount]
                {
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "map")],
                        new StochasticTestMap(options.breakIterations, 0),
                        new ConsoleBuffer("Map/List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rangemap")],
                        new StochasticTestRangeMap(options.breakIterations, 0),
                        new ConsoleBuffer("Range Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rangelist")],
                        new StochasticTestRangeList(options.breakIterations, 0),
                        new ConsoleBuffer("Range List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "range2map")],
                        new StochasticTestRange2Map(options.breakIterations, 0),
                        new ConsoleBuffer("Range2 Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "range2list")],
                        new StochasticTestRange2List(options.breakIterations, 0),
                        new ConsoleBuffer("Range2 List Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "rankmap")],
                        new StochasticTestRankMap(options.breakIterations, 0),
                        new ConsoleBuffer("Rank Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "multirankmap")],
                        new StochasticTestMultiRankMap(options.breakIterations, 0),
                        new ConsoleBuffer("MultiRank Map Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                    new StochasticTestEntry(
                        StochasticTokens[Array.IndexOf(StochasticTokens, "hugelist")],
                        new StochasticTestHugeList(options.breakIterations, 0),
                        new ConsoleBuffer("HugeList Stochastic Test:", Console.BufferWidth, bufferHeight1),
                        options.seed, control),
                };
                for (int i = 0; i < tests.Length; i++)
                {
                    tests[i].actuallyDo = Array.Find(options.stochasticEnables, x => String.Equals(x.Key, tests[i].token)).Value;
                    tests[i].Start();
                }

                int totalHeight = tests.Length * (bufferHeight1 + 1) + 2;
                for (int i = 0; i < totalHeight; i++)
                {
                    Console.WriteLine();
                }
                Console.CursorTop = Math.Max(0, Console.CursorTop - totalHeight);

                Stopwatch started          = Stopwatch.StartNew();
                const int PollIntervalMSec = 250;
                while (true)
                {
                    if (!Array.TrueForAll(tests, delegate(StochasticTestEntry candidate) { return(!candidate.consoleBuffer.Changed); }))
                    {
                        int y = Console.CursorTop;
                        RefreshConsoles(tests);
                        Console.CursorTop = y;
                    }

                    while (Console.KeyAvailable)
                    {
                        ConsoleKeyInfo keyInfo = Console.ReadKey(true /*intercept*/);
                        if (keyInfo.Key == ConsoleKey.Q)
                        {
                            goto Done;
                        }
                        else if (keyInfo.KeyChar == '+')
                        {
                            int i = Array.BinarySearch(ReportingIntervals, control.ReportingInterval);
                            i = i >= 0 ? i + 1 : ~i;
                            control.ReportingInterval = i < ReportingIntervals.Length ? ReportingIntervals[i] : control.ReportingInterval * 2;
                        }
                        else if (keyInfo.KeyChar == '-')
                        {
                            int i = Array.BinarySearch(ReportingIntervals, control.ReportingInterval);
                            i = i >= 0 ? i - 1 : ~i - 1;
                            control.ReportingInterval = Math.Max(i >= 0 ? ReportingIntervals[i] : control.ReportingInterval / 2, 1);
                        }
                    }

                    Thread.Sleep(PollIntervalMSec);

                    if (options.timeLimit.HasValue && (started.ElapsedMilliseconds >= 1000L * options.timeLimit.Value))
                    {
                        break;
                    }
                }
Done:
                control.Stop = true;
                bool allStopped = false;
                while (!allStopped)
                {
                    allStopped = true;
                    foreach (StochasticTestEntry test in tests)
                    {
                        if (test.thread.ThreadState != System.Threading.ThreadState.Stopped)
                        {
                            allStopped = false;
                            break;
                        }
                    }
                }
                RefreshConsoles(tests);

                Console.WriteLine();

                if (!control.Failed)
                {
                    result = TestResultCode.Passed;
                }
            }

            WritePassFail("Stochastic Tests - Finished", result);
            return(result == TestResultCode.Passed);
        }