Beispiel #1
0
        public void RollForwardWithLocalChange()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 1; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)i));
            }

            storage.RollBackToStart();
            storage.Add(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.Contains(j));
                }
            }
        }
Beispiel #2
0
        public void ClearVoidsForwardStack()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(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);
            storage.StoreCurrent(new TimeMarker(3));

            storage.RollForwardTo(new TimeMarker(2));
            Assert.That(
                storage,
                Is.EquivalentTo(new int[] { maximumValue + 1 }));
        }
Beispiel #3
0
        public void UpdateClearsForwardStack()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
            }

            storage.StoreCurrent(new TimeMarker(1));

            storage[5] = maximumValue;
            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackTo(new TimeMarker(1));
            storage[9] = maximumValue;
            storage.StoreCurrent(new TimeMarker(3));

            storage.RollForwardTo(new TimeMarker(2));

            Assert.That(
                storage,
                Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, maximumValue }));
        }
Beispiel #4
0
        public void RollBackThroughClear()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
            }

            storage.StoreCurrent(new TimeMarker(1));

            storage.Clear();
            storage.Add(maximumValue + 1);

            storage.StoreCurrent(new TimeMarker(2));

            storage.RollBackTo(new TimeMarker(1));
            Assert.That(
                storage,
                Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
Beispiel #5
0
        public void RollBackToStart()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            storage.RollBackToStart();
            Assert.That(
                storage,
                Is.EquivalentTo(new int[0]));
        }
Beispiel #6
0
        public void RollForwardPastLastValue()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            storage.RollBackTo(new TimeMarker(6));
            storage.RollForwardTo(new TimeMarker((ulong)(maximumValue + 1)));
            Assert.That(
                storage,
                Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }));
        }
Beispiel #7
0
        public void RollBackPastLastSnapshot()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 30;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            // The snapshot is at 20
            storage.RollBackTo(new TimeMarker(16));
            Assert.That(
                storage,
                Is.EquivalentTo(
                    new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }));
        }
Beispiel #8
0
        public void RollBackToLastSnapshot()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 30;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            // The first snapshot is at 1, the next one is 20 further so it is at 20
            storage.RollBackTo(new TimeMarker(21));
            Assert.That(
                storage,
                Is.EquivalentTo(
                    new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }));
        }
Beispiel #9
0
        public void RollForwardToPastNextSnapshot()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 30;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(i);
                storage.StoreCurrent(new TimeMarker((ulong)(i + 1)));
            }

            // The snapshot is at 21
            storage.RollBackTo(new TimeMarker(16));
            storage.RollForwardTo(new TimeMarker(26));

            Assert.That(
                storage,
                Is.EquivalentTo(new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25 }));
        }
Beispiel #10
0
        public void RollBackMultipleTimes()
        {
            var storage = new ListHistory <int>();

            int maximumValue = 10;

            for (int i = 0; i < maximumValue; i++)
            {
                storage.Add(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.Contains(j - 1));
                }
            }
        }