コード例 #1
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]);
        }
コード例 #2
0
ファイル: ListTest.cs プロジェクト: EmbraceUnity/DejaVu
        public void Clear()
        {
            var list = new UndoRedoList<int>(new int[] {1, 2, 3});
            Assert.AreEqual(3, list.Count);
            // clear
            UndoRedoManager.Start("");
            list.Clear();
            UndoRedoManager.Commit();
            Assert.AreEqual(0, list.Count);
            // add
            UndoRedoManager.Start("");
            list.Add(1);
            UndoRedoManager.Commit();
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Undo(); // undo add
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Undo(); // undo clear
            Assert.AreEqual(3, list.Count);

            UndoRedoManager.Redo(); // redo clear
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Redo(); // redo add
            Assert.AreEqual(1, list.Count);

            UndoRedoManager.Start("");
            list.Add(1);
            list.Add(2);
            Assert.AreEqual(3, list.Count);
            list.Clear();
            Assert.AreEqual(0, list.Count);
            UndoRedoManager.Commit();

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