예제 #1
0
        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));
        }
예제 #2
0
        public void RollForwardWithLocalChange()
        {
            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.RollBackToStart();
            storage.Add(maximumValue + 1, maximumValue + 1);

            for (int i = 1; i < maximumValue; i++)
            {
                storage.RollForwardTo(new TimeMarker((ulong)i));
                Assert.AreEqual(i, storage.Count);
                for (int j = 1; j <= i; j++)
                {
                    Assert.IsTrue(storage.ContainsKey(j - 1));
                }
            }
        }
예제 #3
0
        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++;
            }
        }
예제 #4
0
        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++;
            }
        }
예제 #5
0
        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++;
            }
        }
예제 #6
0
        public void RollForwardThroughRemove()
        {
            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.Remove(5);
            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackToStart();
            storage.RollForwardTo(new TimeMarker(2));

            Assert.AreEqual(maximumValue - 1, storage.Count);

            int index = 0;

            foreach (var pair in storage)
            {
                if (index < 5)
                {
                    Assert.AreEqual(index, pair.Key);
                    Assert.AreEqual(index, pair.Value);
                }
                else
                {
                    Assert.AreEqual(index + 1, pair.Key);
                    Assert.AreEqual(index + 1, pair.Value);
                }

                index++;
            }
        }