Esempio n. 1
0
        private static void TestClear(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            undoList.Clear();

            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);
        }
Esempio n. 2
0
        public static void Test()
        {
            int                count          = 10;
            List <int>         comparisonList = new List <int>(count);
            UndoableList <int> undoList       = new UndoableList <int>(count);

            PopulateLists(comparisonList, undoList, count);
            TestAdd(comparisonList, undoList);
            TestClear(comparisonList, undoList);
            TestInsert(comparisonList, undoList);
            TestInsertRange(comparisonList, undoList);
            TestRemove(comparisonList, undoList);
            TestRemoveAt(comparisonList, undoList);
            TestRemoveRange(comparisonList, undoList);
            TestReverse(comparisonList, undoList);
        }
Esempio n. 3
0
        private static void TestRemoveAt(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            int index = comparisonList.Count / 2;

            int item = comparisonList[index];

            comparisonList.RemoveAt(index);
            undoList.RemoveAt(index);

            TestEquals(comparisonList, undoList);

            comparisonList.Insert(index, item);
            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);
        }
Esempio n. 4
0
        private static void TestRemoveRange(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            int index = comparisonList.Count / 2;
            int count = comparisonList.Count - index;

            List <int> range = comparisonList.GetRange(index, count);

            comparisonList.RemoveRange(index, count);
            undoList.RemoveRange(index, count);

            TestEquals(comparisonList, undoList);

            comparisonList.InsertRange(index, range);
            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);
        }
Esempio n. 5
0
        private static void TestAdd(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            Stack <int> redoStack = new Stack <int>();

            while (comparisonList.Count > 0)
            {
                redoStack.Push(comparisonList[comparisonList.Count - 1]);
                comparisonList.RemoveAt(comparisonList.Count - 1);
                Debug.Assert(undoList.Undo());
                TestEquals(comparisonList, undoList);
            }

            while (redoStack.Count > 0)
            {
                comparisonList.Add(redoStack.Pop());
                Debug.Assert(undoList.Redo());
                TestEquals(comparisonList, undoList);
            }
        }
Esempio n. 6
0
        private static void TestInsertRange(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            int[] range = { 1, 2, 3, 4, 5 };
            int   index = comparisonList.Count / 2;

            comparisonList.InsertRange(index, range);
            undoList.InsertRange(index, range);

            TestEquals(comparisonList, undoList);

            comparisonList.RemoveRange(index, range.Length);
            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);

            comparisonList.InsertRange(index, range);
            Debug.Assert(undoList.Redo());

            TestEquals(comparisonList, undoList);
        }
Esempio n. 7
0
        private static void TestReverse(List <int> comparisonList, UndoableList <int> undoList)
        {
            TestEquals(comparisonList, undoList);

            comparisonList.Reverse();
            undoList.Reverse();

            TestEquals(comparisonList, undoList);

            comparisonList.Reverse();
            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);

            comparisonList.Reverse();
            Debug.Assert(undoList.Redo());

            TestEquals(comparisonList, undoList);

            int count = comparisonList.Count / 2;

            comparisonList.Reverse(0, count);
            undoList.Reverse(0, count);

            TestEquals(comparisonList, undoList);

            comparisonList.Reverse(0, count);
            Debug.Assert(undoList.Undo());

            TestEquals(comparisonList, undoList);

            comparisonList.Reverse(0, count);
            Debug.Assert(undoList.Redo());

            TestEquals(comparisonList, undoList);
        }