public void Add() { const int len = 1024; Document doc = new Document(); EditHistory history = new EditHistory(); EditAction action; Assert.AreEqual(null, history.GetUndoAction()); Assert.AreEqual(false, history.CanUndo); Assert.AreEqual(false, history.CanRedo); for (int i = 0; i < len; i++) { history.Add( new EditAction(doc, i, i.ToString(), (i + 'a').ToString(), 0, 0, null) ); } Assert.AreEqual(true, history.CanUndo); Assert.AreEqual(false, history.CanRedo); for (int i = len - 1; 0 <= i; i--) { action = history.GetUndoAction(); Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString()); } Assert.AreEqual(null, history.GetUndoAction()); Assert.AreEqual(false, history.CanUndo); Assert.AreEqual(true, history.CanRedo); }
public void Case2() { const int len1 = 1024; const int len2 = 512; const int len3 = 768; Document doc = new Document(); EditHistory history = new EditHistory(); EditAction action; Assert.AreEqual(null, history.GetUndoAction()); Assert.AreEqual(false, history.CanUndo); Assert.AreEqual(false, history.CanRedo); // add some for (int i = 0; i < len1; i++) { history.Add( new EditAction(doc, i, i.ToString(), (i + 'a').ToString(), 0, 0, null) ); } Assert.AreEqual(true, history.CanUndo); Assert.AreEqual(false, history.CanRedo); // pop some for (int i = len1 - 1; len2 <= i; i--) { action = history.GetUndoAction(); Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString()); } Assert.AreEqual(true, history.CanUndo); Assert.AreEqual(true, history.CanRedo); // redo some for (int i = len2; i < len3; i++) { action = history.GetRedoAction(); Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString()); } Assert.AreEqual(true, history.CanUndo); Assert.AreEqual(true, history.CanRedo); // add one and ensure that it can redo no more history.Add( new EditAction(doc, len3, (len3).ToString(), (len3 + 'a').ToString(), 0, 0, null) ); Assert.AreEqual(true, history.CanUndo); Assert.AreEqual(false, history.CanRedo); // pop all for (int i = len3; 0 <= i; i--) { action = history.GetUndoAction(); Assert.AreEqual(i + "-[" + i + "]+[" + (i + 'a') + "]", action.ToString()); } Assert.AreEqual(false, history.CanUndo); Assert.AreEqual(true, history.CanRedo); Assert.AreEqual(null, history.GetUndoAction()); Assert.AreEqual("0-[0]+[97]", history.GetRedoAction().ToString()); }