Ejemplo n.º 1
0
        public void MyCircularQueueTestCase1()
        {
            var queue = new MyCircularQueue(3);

            queue.IsEmpty().Should().BeTrue();
            queue.EnQueue(1).Should().BeTrue();
            queue.ToString().Should().Be("1");
            queue.Rear().Should().Be(1);
            queue.Front().Should().Be(1);
            queue.EnQueue(2).Should().BeTrue();
            queue.ToString().Should().Be("1, 2");
            queue.Front().Should().Be(1);
            queue.EnQueue(3).Should().BeTrue();
            queue.ToString().Should().Be("1, 2, 3");
            queue.EnQueue(4).Should().BeFalse();
            queue.Front().Should().Be(1);
            queue.Rear().Should().Be(3);
            queue.IsFull().Should().BeTrue();
            queue.DeQueue().Should().BeTrue();
            queue.ToString().Should().Be("2, 3");
            queue.Front().Should().Be(2);
            queue.EnQueue(4).Should().BeTrue();
            queue.ToString().Should().Be("2, 3, 4");
            queue.Rear().Should().Be(4);
            queue.Front().Should().Be(2);
            queue.DeQueue().Should().BeTrue();
            queue.DeQueue().Should().BeTrue();
            queue.DeQueue().Should().BeTrue();
            queue.DeQueue().Should().BeFalse();
            queue.IsEmpty().Should().BeTrue();
            queue.IsFull().Should().BeFalse();
            queue.EnQueue(1).Should().BeTrue();
            queue.IsEmpty().Should().BeFalse();
        }
Ejemplo n.º 2
0
        public void isFullTest()
        {
            MyCircularQueue c = new MyCircularQueue(1);

            Assert.False(c.IsFull());
            Assert.True(c.EnQueue(36));
            Assert.True(c.IsFull());
Ejemplo n.º 3
0
        public void ST_MyCircularQueue_Test()
        {
            var _q = new MyCircularQueue(5);

            _q.EnQueue(1);
            _q.EnQueue(2);
            _q.EnQueue(3);
            _q.EnQueue(4);
            _q.EnQueue(5);
            Assert.False(_q.EnQueue(6));
            Assert.Equal(1, _q.Front());
            Assert.Equal(5, _q.Rear());
            Assert.True(_q.IsFull());

            Assert.True(_q.DeQueue());
            Assert.True(_q.DeQueue());
            Assert.True(_q.EnQueue(6));
            Assert.True(_q.EnQueue(7));
            Assert.True(_q.IsFull());
            Assert.False(_q.EnQueue(8));
            _q.DeQueue();
            _q.DeQueue();
            _q.DeQueue();
            _q.DeQueue();
            Assert.True(_q.Front() == 7 && _q.Rear() == 7);
            _q.DeQueue();
            Assert.True(_q.IsEmpty());


            MyCircularQueue circularQueue = new MyCircularQueue(2);

            circularQueue.EnQueue(8);
            circularQueue.EnQueue(8);
            var a = circularQueue.Front();

            circularQueue.EnQueue(4);
            circularQueue.DeQueue();

            circularQueue.EnQueue(1);
            circularQueue.EnQueue(1);
            circularQueue.DeQueue();
            Assert.True(circularQueue.Front() == 1 && circularQueue.Rear() == 1);
        }
Ejemplo n.º 4
0
        public void Check_MyCircularQueue_BaseCase()
        {
            MyCircularQueue circularQueue = new MyCircularQueue(3);

            Assert.IsTrue(circularQueue.EnQueue(1));            // return true
            Assert.IsTrue(circularQueue.EnQueue(2));            // return true
            Assert.IsTrue(circularQueue.EnQueue(3));            // return true
            Assert.IsFalse(circularQueue.EnQueue(4));           // return false, the queue is full
            Assert.IsTrue(circularQueue.Rear() == 3);           // return 3
            Assert.IsTrue(circularQueue.IsFull());              // return true
            Assert.IsTrue(circularQueue.DeQueue());             // return true
            Assert.IsTrue(circularQueue.EnQueue(4));            // return true
            Assert.IsTrue(circularQueue.Rear() == 4);           // return 4
        }
 static void Main(string[] args)
 {
     MyCircularQueue obj      = new MyCircularQueue(3);
     bool            param_1  = obj.EnQueue(7);
     bool            param_7  = obj.DeQueue();
     int             front1   = obj.Front();
     bool            param_8  = obj.DeQueue();
     int             front2   = obj.Front();
     int             rear     = obj.Rear();
     bool            param_2  = obj.EnQueue(0);
     bool            isfull   = obj.IsFull();
     bool            param_9  = obj.DeQueue();
     int             rear2    = obj.Rear();
     bool            param_10 = obj.EnQueue(3);
 }
        public void CircularQueuePush10ItemAndIsFull()
        {
            int maxSize = 10;
            var myQueue = new MyCircularQueue(maxSize);

            myQueue.Push("A");
            myQueue.Push("B");
            myQueue.Push("C");
            myQueue.Push("D");
            myQueue.Push("E");
            myQueue.Push("F");
            myQueue.Push("G");
            myQueue.Push("H");
            myQueue.Push("I");
            myQueue.Push("J");
            Assert.AreEqual(true, myQueue.IsFull());
        }
Ejemplo n.º 7
0
        public void Test1()
        {
            MyCircularQueue obj = new MyCircularQueue(3);

            bool param_1 = obj.EnQueue(1);
            bool param_2 = obj.EnQueue(2);
            bool param_3 = obj.EnQueue(3);
            bool param_4 = obj.EnQueue(4);

            bool d_1     = obj.DeQueue();
            bool param_5 = obj.EnQueue(4);

            bool d_2 = obj.DeQueue();
            bool d_3 = obj.DeQueue();
            bool d_4 = obj.DeQueue();
            bool d_5 = obj.DeQueue();
            int  f_1 = obj.Front();

            int r_1 = obj.Rear();

            bool e_1 = obj.IsEmpty();

            bool full_1 = obj.IsFull();
        }