Exemplo n.º 1
0
        public void NonEmptyQueueReadsNotEmptyTest()
        {
            Deque target = new Deque();

            target.AddEnd(0);
            for (int i = 0; i < 1000000; i++)
            {
                target.AddEnd(i);
                Assert.IsFalse(target.IsEmpty);
            }
        }
Exemplo n.º 2
0
        public void MixedTest()
        {
            Deque <int> d = new Deque <int>();

            d.AddFront(5);
            d.AddEnd(6);
            d.AddFront(4);
            d.AddEnd(7);

            Assert.AreEqual(7, (int)d.RemoveEnd());
            Assert.AreEqual(4, (int)d.RemoveFront());
            Assert.AreEqual(6, (int)d.RemoveEnd());
            Assert.AreEqual(5, (int)d.RemoveFront());
        }
Exemplo n.º 3
0
        public void ClearTest()
        {
            Deque <int> d = new Deque <int>();

            d.AddEnd(4);
            d.AddEnd(5);
            d.AddEnd(6);
            d.AddEnd(7);

            Assert.AreEqual(7, (int)d.PeekEnd());
            Assert.AreEqual(4, (int)d.PeekFront());

            d.Clear();
            Assert.AreEqual(0, d.Count);
        }
Exemplo n.º 4
0
        public void CountTest()
        {
            Deque target = new Deque();

            for (int i = 0; i < 1000000; i++)
            {
                Assert.AreEqual <int>(target.Count, i);
                target.AddEnd(i);
            }
        }
Exemplo n.º 5
0
        public void NullTest()
        {
            Deque <object> d = new Deque <object>();

            Assert.IsNull(d.RemoveFront(), "#1");

            object o = new object();

            d.AddEnd(o);
            Assert.AreEqual(o, d.RemoveEnd(), "#2");
            Assert.IsNull(d.RemoveEnd(), "#3");

            d.AddFront(o);
            Assert.AreEqual(o, d.RemoveFront(), "#4");
            Assert.IsNull(d.RemoveFront(), "#5");
        }
Exemplo n.º 6
0
        public void DataOrderPreservedTest()
        {
            Deque target = new Deque(); // TODO: Initialize to an appropriate value

            object[] testData = new object[] { "a", "b", "c", "d", "e", "f", "g", "h", "i", "j" };
            for (int j = 0; j < 10; j++)
            {
                foreach (var x in testData)
                {
                    target.AddEnd(x);
                }
                foreach (var x in testData)
                {
                    Assert.AreEqual <object>(x, target.RemoveFront());
                }
                Assert.AreEqual <int>(0, target.Count);
            }
        }
Exemplo n.º 7
0
        internal void MakePrivateCopyOfUndoRedo()
        {
            // Data in the actions may reference a file buffer that
            // can become invalid (eg after saving a file)
            // Copy the data to private in-memory buffers to avoid data corruption
            // and crashes...
            //

            if (Preferences.Instance["Undo.KeepAfterSave"] == "Never")
            {
                undoDeque.Clear();
                redoDeque.Clear();
                return;
            }

            if (Preferences.Instance["Undo.KeepAfterSave"] == "Always")
            {
                foreach (ByteBufferAction action in undoDeque)
                {
                    action.MakePrivateCopyOfData();
                }

                foreach (ByteBufferAction action in redoDeque)
                {
                    action.MakePrivateCopyOfData();
                }

                return;
            }

            // if Preferences.Instance["Undo.KeepAfterSave"] == "Memory"
            // drop the undo and redo actions that don't fit into memory (and all actions
            // after them in the Deques).
            Deque <ByteBufferAction> newUndoDeque = new Deque <ByteBufferAction>();
            Deque <ByteBufferAction> newRedoDeque = new Deque <ByteBufferAction>();

            foreach (ByteBufferAction action in undoDeque)
            {
                long freeMem = long.MaxValue;
                try {
                    freeMem = Portable.GetAvailableMemory();
                }
                catch (NotImplementedException) {}

                if (freeMem < action.GetPrivateCopySize())
                {
                    break;
                }

                action.MakePrivateCopyOfData();
                newUndoDeque.AddEnd(action);
            }


            foreach (ByteBufferAction action in redoDeque)
            {
                long freeMem = long.MaxValue;
                try {
                    freeMem = Portable.GetAvailableMemory();
                }
                catch (NotImplementedException) {}

                if (freeMem < action.GetPrivateCopySize())
                {
                    break;
                }

                action.MakePrivateCopyOfData();
                newRedoDeque.AddEnd(action);
            }

            undoDeque.Clear();
            redoDeque.Clear();

            undoDeque = newUndoDeque;
            redoDeque = newRedoDeque;
        }