public void HistoricalProperty01() { History history = new History(); IntHolder ih = new IntHolder(); ih.IP = 5; HistoricalProperty<int> ip = new HistoricalProperty<int>(history, ih, "IP"); int s1 = history.TakeSnapshot(); HistoricalStack<int> stack = new HistoricalStack<int>(history); ip.Value = 6; ip.Value = 7; stack.Push(ip.Value); int s2 = history.TakeSnapshot(); stack.Push(++ip.Value); stack.Push(ip.Value = stack.Pop() * stack.Pop()); int s3 = history.TakeSnapshot(); history.RevertToSnapshot(s1); Assert.AreEqual(ih.IP, 5); Assert.IsTrue(stack.IsEmpty); history.RevertToSnapshot(s2); Assert.AreEqual(7, ih.IP); Assert.AreEqual(7, stack[0]); history.RevertToSnapshot(s3); Assert.AreEqual(56, ih.IP); Assert.AreEqual(56, stack[0]); // Once again history.RevertToSnapshot(s1); Assert.AreEqual(ih.IP, 5); Assert.IsTrue(stack.IsEmpty); history.RevertToSnapshot(s2); Assert.AreEqual(7, ih.IP); Assert.AreEqual(7, stack[0]); history.RevertToSnapshot(s3); Assert.AreEqual(56, ih.IP); Assert.AreEqual(56, stack[0]); }
public void HistoricalStack02() { History history = new History(); var hs = new HistoricalStack<int>(history); var hs2 = new HistoricalStack<int>(history); var hs3 = new HistoricalStack<int>(history); for (int i = 0; i < 30; ++i) { switch (i % 3) { case 0: hs.Push(i); break; case 1: hs2.Push(i); break; case 2: hs3.Push(i); break; } } // Take snapshot int snapShot = history.TakeSnapshot(); hs2.Push(hs.Pop()); hs2.Push(hs3.Pop()); hs.Push(hs2.Pop()); hs.Push(hs2.Pop()); hs3.Push(hs.Pop()); hs3.Push(hs.Pop()); // Take another snapshot int ss2 = history.TakeSnapshot(); // Revert to first snapshot history.RevertToSnapshot(snapShot); Assert.AreEqual(10, hs.Count); Assert.AreEqual(10, hs2.Count); Assert.AreEqual(10, hs3.Count); // Revert to second snapshot history.RevertToSnapshot(ss2); Assert.AreEqual(9, hs.Count); Assert.AreEqual(10, hs2.Count); Assert.AreEqual(11, hs3.Count); }