public void RollForwardToPastNextSnapshot() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 30; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } // The snapshot is at 2 storage.RollBackTo(new TimeMarker(16)); storage.RollForwardTo(new TimeMarker(26)); Assert.AreEqual(26, storage.Count); int index = 0; foreach (var pair in storage) { Assert.AreEqual(index, pair.Key); Assert.AreEqual(index, pair.Value); index++; } }
public void ClearVoidsForwardStack() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); } storage.StoreCurrent(new TimeMarker(1)); storage[5] = maximumValue; storage.StoreCurrent(new TimeMarker(2)); storage.RollBackTo(new TimeMarker(1)); storage.Clear(); storage.Add(maximumValue + 1, maximumValue + 1); storage.StoreCurrent(new TimeMarker(3)); storage.RollForwardTo(new TimeMarker(2)); Assert.AreEqual(1, storage.Count); Assert.IsTrue(storage.ContainsKey(maximumValue + 1)); }
public void RollForwardPastLastValue() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } storage.RollBackTo(new TimeMarker(5)); storage.RollForwardTo(new TimeMarker((ulong)(maximumValue + 1))); Assert.AreEqual(maximumValue, storage.Count); int index = 0; foreach (var pair in storage) { Assert.AreEqual(index, pair.Key); Assert.AreEqual(index, pair.Value); index++; } }
public void RollBackThroughUpdate() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); } storage.StoreCurrent(new TimeMarker(1)); storage[5] = maximumValue; storage.StoreCurrent(new TimeMarker(2)); storage.RollBackTo(new TimeMarker(1)); Assert.AreEqual(maximumValue, storage.Count); int index = 0; foreach (var pair in storage) { Assert.AreEqual(index, pair.Key); Assert.AreEqual(index, pair.Value); index++; } }
public void RollBackToLastSnapshot() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 30; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } // The first snapshot is at 1, the next one is 20 further so it is at 21 storage.RollBackTo(new TimeMarker(21)); Assert.AreEqual(21, storage.Count); int index = 0; foreach (var pair in storage) { Assert.AreEqual(index, pair.Key); Assert.AreEqual(index, pair.Value); index++; } }
public void RollBackPastFirstValue() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 1; i < maximumValue; i++) { storage.Add(i, i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } storage.RollBackTo(new TimeMarker(0)); Assert.AreEqual(0, storage.Count); }
public void AddVoidsForwardStack() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); } storage.StoreCurrent(new TimeMarker(1)); storage[5] = maximumValue; storage.StoreCurrent(new TimeMarker(2)); storage.RollBackTo(new TimeMarker(1)); storage.Add(11, 11); storage.StoreCurrent(new TimeMarker(3)); storage.RollForwardTo(new TimeMarker(2)); Assert.AreEqual(maximumValue + 1, storage.Count); int index = 0; foreach (var pair in storage) { if (index < maximumValue) { Assert.AreEqual(index, pair.Key); Assert.AreEqual(index, pair.Value); } else { Assert.AreEqual(index + 1, pair.Key); Assert.AreEqual(index + 1, pair.Value); } index++; } }
public void RollBackMultipleTimes() { var storage = new DictionaryHistory <int, int>(); int maximumValue = 10; for (int i = 0; i < maximumValue; i++) { storage.Add(i, i); storage.StoreCurrent(new TimeMarker((ulong)(i + 1))); } for (int i = maximumValue; i > 0; i--) { storage.RollBackTo(new TimeMarker((ulong)i)); Assert.AreEqual(i, storage.Count); for (int j = 1; j <= i; j++) { Assert.IsTrue(storage.ContainsKey(j - 1)); } } }
public void RollBackWithNoValues() { var storage = new DictionaryHistory <int, int>(); Assert.DoesNotThrow(() => storage.RollBackTo(new TimeMarker(1))); }