public void TestMove1()
        {
            var list = new PartitionableList <int>();
            var part = list.CreatePartialView(x => 0 == x % 2);

            list.Add(81);
            list.Add(67);
            list.Add(46);
            list.Add(49);

            Assert.AreEqual(1, part.Count);

            list.Move(0, 2);
            Assert.AreEqual(1, part.Count);
            Assert.AreEqual(46, part[0]);
        }
        public void TestMove2()
        {
            var list = new PartitionableList <int>();
            var part = list.CreatePartialView(x => 0 == x % 2);

            list.Add(24);
            list.Add(74);
            list.Add(84);

            Assert.AreEqual(3, part.Count);

            list.Move(1, 2);
            Assert.AreEqual(3, part.Count);
            Assert.AreEqual(24, part[0]);
            Assert.AreEqual(84, part[1]);
            Assert.AreEqual(74, part[2]);
        }
        public void TestRandomActions1()
        {
            var actionGenerator = new ActionGenerator();
            var rndIndex        = new System.Random();
            var rndNewNumber    = new System.Random();

            var list = new PartitionableList <int>();

            var part1 = list.CreatePartialView(Condition1);
            var part2 = list.CreatePartialView(Condition2);
            var part3 = list.CreatePartialView(Condition3);

            var maxTimeToRun = TimeSpan.FromSeconds(1);
            var watch        = new System.Diagnostics.Stopwatch();

            watch.Start();
            var  actionStatistics     = new int[Enum.GetValues(typeof(ListAction)).Length];
            long accumulatedListCount = 0;
            int  maxListCount         = 0;

            int numberOfActionsTested = 0;

            for (; watch.Elapsed < maxTimeToRun; ++numberOfActionsTested)
            {
                var action = actionGenerator.GetNextAction(list);
                ++actionStatistics[(int)action];
                int idx;
                int idx2;
                int newNumber;
                int?oldItem = null;

                switch (action)
                {
                case ListAction.Clear:
                    list.Clear();
                    Assert.AreEqual(0, list.Count);
                    break;

                case ListAction.RemoveAt:
                    if (list.Count > 0)
                    {
                        var oldCount = list.Count;
                        idx     = rndIndex.Next(list.Count);
                        oldItem = list[idx];
                        list.RemoveAt(idx);
                        Assert.AreEqual(oldCount - 1, list.Count);
                    }
                    break;

                case ListAction.Add:
                {
                    var oldCount = list.Count;
                    list.Add(newNumber = rndNewNumber.Next(100));
                    Assert.AreEqual(oldCount + 1, list.Count);
                    Assert.AreEqual(newNumber, list[list.Count - 1]);
                }
                break;

                case ListAction.InsertAt:
                {
                    var oldCount = list.Count;
                    idx = rndIndex.Next(list.Count + 1);
                    list.Insert(idx, newNumber = rndNewNumber.Next(100));
                    Assert.AreEqual(oldCount + 1, list.Count);
                    Assert.AreEqual(newNumber, list[idx]);
                }
                break;

                case ListAction.Set:
                    if (list.Count > 0)
                    {
                        var oldCount = list.Count;
                        idx       = rndIndex.Next(list.Count);
                        oldItem   = list[idx];
                        list[idx] = (newNumber = rndNewNumber.Next(100));
                        Assert.AreEqual(oldCount, list.Count);
                        Assert.AreEqual(newNumber, list[idx]);
                    }
                    break;

                case ListAction.Move:
                    if (list.Count > 0)
                    {
                        var oldCount = list.Count;
                        idx     = rndIndex.Next(list.Count);
                        idx2    = rndIndex.Next(list.Count);
                        oldItem = list[idx];
                        list.Move(idx, idx2);
                        Assert.AreEqual(oldCount, list.Count);
                        Assert.AreEqual(oldItem, list[idx2]);
                    }
                    break;

                default:
                    break;
                }

                accumulatedListCount += list.Count;
                maxListCount          = Math.Max(maxListCount, list.Count);

                bool succ1 = IsOrderingTestSuccessfull(list, part1, Condition1);
                bool succ2 = IsOrderingTestSuccessfull(list, part2, Condition2);
                bool succ3 = IsOrderingTestSuccessfull(list, part3, Condition3);

                if (!succ1)
                {
                }
                if (!succ2)
                {
                }
                if (!succ3)
                {
                }

                Assert.IsTrue(succ1);
                Assert.IsTrue(succ2);
                Assert.IsTrue(succ3);
            }

            double averageListCount = accumulatedListCount / numberOfActionsTested;

            watch.Stop();
        }