Ejemplo n.º 1
0
        public void ActionScope()
        {
            var target = new UndoRedoList <int, List <int> > {
                100, 200
            };

            using (var scope = new UndoRedoList <int, List <int> > .ActionScope(target)) {
                target.Add(300);
                target.RemoveAt(0);
                target.RemoveAt(1);
                target.Add(400);
                target.Add(500);
            }
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(200, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
Ejemplo n.º 2
0
        public void Undo()
        {
            var target = new UndoRedoList <int, List <int> >();

            Assert.IsFalse(target.Undo());

            target.Add(100);
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);

            target.Add(200);
            Assert.IsTrue(target.CanUndo);
            Assert.IsFalse(target.CanRedo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(100, target[0]);
            Assert.AreEqual(200, target[1]);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(100, target[0]);

            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.CanUndo);
            Assert.AreEqual(0, target.Count);

            target.Add(300);
            Assert.IsTrue(target.CanUndo);
            target.Add(400);
            target.RemoveAt(0);
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(1, target.Count);
            Assert.AreEqual(400, target[0]);

            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.CanUndo);
            Assert.AreEqual(2, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);

            target.Add(500);
            target[target.Count - 1] = 600;
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(600, target[target.Count - 1]);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(500, target[target.Count - 1]);

            target.Clear();
            Assert.AreEqual(0, target.Count);
            Assert.IsTrue(target.CanUndo);
            Assert.IsTrue(target.Undo());
            Assert.AreEqual(3, target.Count);
            Assert.AreEqual(300, target[0]);
            Assert.AreEqual(400, target[1]);
            Assert.AreEqual(500, target[2]);
        }
Ejemplo n.º 3
0
        public void AddRemove()
        {
            var list = new UndoRedoList<int>();
            // Add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();

            Assert.AreEqual(1, list[0]);
            Assert.AreEqual(1, list.Count);
            // AddRange
            UndoRedoManager.Start("");
            list.AddRange(new int[] { 2, 3, 4, 5, 6});
            UndoRedoManager.Commit();

            Assert.AreEqual(6, list.Count);
            // RemoveRange
            UndoRedoManager.Start("");
            list.RemoveRange(4, 2);
            UndoRedoManager.Commit();

            // RemoveAt
            UndoRedoManager.Start("");
            list.RemoveAt(0);
            UndoRedoManager.Commit();

            // Remove
            UndoRedoManager.Start("");
            list.Remove(2);
            UndoRedoManager.Commit();

            Assert.AreEqual(3, list[0]);
            Assert.AreEqual(4, list[1]);
            Assert.AreEqual(2, list.Count);

            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            UndoRedoManager.Undo();
            Assert.AreEqual(6, list.Count);

            UndoRedoManager.Undo(); // undo AddRange
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo Add
            Assert.AreEqual(0, list.Count);

            UndoRedoManager.Redo(); // redo Add
            UndoRedoManager.Redo(); // redo AddRange
            Assert.AreEqual(6, list.Count);
            Assert.IsTrue(list[0] == 1 && list[1] == 2 && list[2] == 3 && list[3] == 4 && list[4] == 5 && list[5] == 6);

            UndoRedoManager.Redo(); // redo RemoveRange
            UndoRedoManager.Redo(); // redo RemoveAt
            UndoRedoManager.Redo(); // redo Remove
            Assert.AreEqual(2, list.Count);
        }
Ejemplo n.º 4
0
        public void AnotherUndoRedoList()
        {
            // List which support undo/redo.
            var target = new UndoRedoList <int>(maximumUndoTimes: 2);

            target.Add(100);
            target.RemoveAt(0);
            Assert.IsTrue(target.Undo());
            Assert.IsTrue(target.Undo());
            Assert.IsFalse(target.Undo());
            Assert.IsTrue(target.Redo());
            Assert.IsTrue(target.Redo());
            Assert.IsFalse(target.Redo());
        }
Ejemplo n.º 5
0
        static void RemoveTest(UndoRedoList <int, List <int> > list)
        {
            for (var count = 1; count <= times; count++)
            {
                list.RemoveAt(times - count);
            }

            for (var count = 1; count <= times; count++)
            {
                list.Undo();
            }

            for (var count = 1; count <= times; count++)
            {
                list.Redo();
            }
        }