public void PUT_EnqueueContract([PexAssumeUnderTest] Queue.Queue <int> s1, int x)
        {
            AssumePrecondition.IsTrue(true);

            int Old_s1Count = s1.Count;

            int Old_Top = s1.Count > 0 ? s1.Peek() :  PexChoose.Value <int>("old_top");
            //int Old_Top = s1.Count > 0 ? s1.Peek() : x - 1; // OldTop = x; x updates x = x-1

            int  Old_x           = x;
            bool Old_s1ContainsX = s1.Contains(x);

            //bool Old_Empty = s1.Count == 0;

            s1.Enqueue(x);

            int  New_s1Count     = s1.Count;
            int  New_Top         = s1.Peek();
            bool New_s1ContainsX = s1.Contains(x);

            //bool New_Empty = s1.Count == 0;

            PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            PexObserve.ValueForViewing("$old_s1_x", Old_x);
            PexObserve.ValueForViewing("$old_s1_contains_x", Old_s1ContainsX);
            PexObserve.ValueForViewing("$new_s1_contains_x", New_s1ContainsX);
            //PexObserve.ValueForViewing("$Old_NotEmpty", Old_Empty);
            //PexObserve.ValueForViewing("$New_NotEmpty", New_Empty);
            Assert.True(((New_s1ContainsX && New_s1Count == 1 + Old_s1Count && (!(Old_s1ContainsX)) && New_s1Count >= 1) || (New_s1ContainsX && New_s1Count == 1 + Old_s1Count && New_Top == Old_Top && New_s1Count >= 2)));
        }
Пример #2
0
        public void PUT_EnqueueContract([PexAssumeUnderTest] Queue.Queue <int> s1, int x)
        {
            AssumePrecondition.IsTrue(true);

            int Old_s1Count = s1.Count;
            int Old_Top     = s1.Count > 0 ? s1.Peek() :  PexChoose.Value <int>("old_top");
            //int Old_Top = s1.Count > 0 ? s1.Peek() : x+1;

            //int Old_Top = PexChoose.Value<int>("old_top");
            int  Old_x           = x;
            bool Old_s1ContainsX = s1.Contains(x);

            s1.Enqueue(x);

            int  New_s1Count     = s1.Count;
            int  New_Top         = s1.Peek();
            int  New_x           = x;
            bool New_s1ContainsX = s1.Contains(x);

            PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            PexObserve.ValueForViewing("$old_s1_x", Old_x);
            PexObserve.ValueForViewing("$new_s1_x", New_x);
            PexObserve.ValueForViewing("$old_s1_contains_x", Old_s1ContainsX);
            PexObserve.ValueForViewing("$new_s1_contains_x", New_s1ContainsX);

            Assert.True(((New_s1ContainsX && New_s1Count == 1 + Old_s1Count && New_x == Old_x && (!(Old_Top == New_s1Count)))));
        }
        public void PUT_ContainsContract([PexAssumeUnderTest] Queue.Queue <int> s1, int x)
        {
            int undefinedTop = PexChoose.Value <int>("old_top");

            AssumePrecondition.IsTrue(true);

            int Old_s1Count = s1.Count;
            int Old_Top     = s1.Count > 0 ? s1.Peek() : undefinedTop;
            //bool Old_s1ContainsX = s1.Contains(x);

            /*Code */
            bool New_Ret = s1.Contains(x);

            int New_s1Count = s1.Count;
            int New_Top     = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top");

            //int New_Top = s1.Count > 0 ? s1.Peek() : Old_Top;

            //bool New_s1ContainsX = s1.Contains(x);

            PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            PexObserve.ValueForViewing("$new_ret", New_Ret);
            //PexObserve.ValueForViewing("$old_s1_contains_x", Old_s1ContainsX);
            //PexObserve.ValueForViewing("$new_s1_contains_x", New_s1ContainsX);

            Assert.True(((New_s1Count <= Old_s1Count && Old_s1Count <= New_s1Count && (!(New_Ret)) && New_s1Count >= 0) || (New_s1Count <= Old_s1Count && Old_s1Count <= New_s1Count && Old_Top <= New_Top && New_Top <= Old_Top && New_s1Count >= 1)));
        }
Пример #4
0
        public void PUT_DequeueContract([PexAssumeUnderTest] Queue.Queue <int> s1)
        {
            AssumePrecondition.IsTrue(s1.Count > 0);
            int Old_s1Count = s1.Count;
            //int Old_Ret = PexChoose.Value<int>("old_ret");
            int Old_Top = s1.Peek();

            /*code*/
            int New_Ret = s1.Dequeue();

            //Old_ret = New_ret;
            int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_ret");
            //int New_Top = s1.Count > 0 ? s1.Peek() : Old_Top - 2;
            int  New_s1Count          = s1.Count;
            bool New_s1ContainsNewRet = s1.Contains(New_Ret);

            PexObserve.ValueForViewing("$Old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$New_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$Old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            //PexObserve.ValueForViewing("$Old_ret", Old_Ret);
            PexObserve.ValueForViewing("$New_ret", New_Ret);
            PexObserve.ValueForViewing("$New_s1ContainsNewRet", New_s1ContainsNewRet);

            Assert.True(((New_s1Count == -1 + Old_s1Count && New_Ret == Old_Top && (!(New_Ret == Old_s1Count)))));
        }
Пример #5
0
        public void EnTest()
        {
            var q = new Queue.Queue <int>();

            q.Enqueue(6);
            q.Enqueue(7);
            Assert.Equal(6, q.Peek());
        }
Пример #6
0
        public void DeTest()
        {
            var q = new Queue.Queue <int>();

            q.Enqueue(6);
            q.Enqueue(7);
            q.Dequeue();
            Assert.Equal(7, q.Peek());
        }
Пример #7
0
 public void Test_Queue_string()
 {
     Queue.Queue <string> myQ = new Queue.Queue <string>();
     myQ.Enqueue("appels");
     myQ.Enqueue("peren");
     myQ.Enqueue("sinaasappels");
     myQ.Enqueue("kiwi's");
     Assert.AreEqual(myQ.First, "appels");
     myQ.Dequeue();
     Assert.AreEqual(myQ.First, "peren");
 }
Пример #8
0
 public static Queue.Queue <int> Create([PexAssumeNotNull] int[] elems)
 {
     //PexAssume.AreDistinctValues(elems);
     PexAssume.TrueForAll(elems, e => e <= -6 || e > -6);
     //PexAssume.TrueForAll(0, elems.Length, _i => elems[_i] > -11 && elems[_i] < 11);
     Queue.Queue <int> ret = new Queue.Queue <int>();// DataStructure has big enough capacity for Commutativity Test
     for (int i = 0; i < elems.Length; i++)
     {
         ret.Enqueue(elems[i]);
     }
     return(ret);
 }
Пример #9
0
        public void ClearTest()
        {
            var q = new Queue.Queue <int>();

            q.Enqueue(6);
            q.Enqueue(7);
            q.Clear();
            var d = new Queue.Queue <int>();

            d.Enqueue(6);
            d.Enqueue(7);
            Assert.True(q != d);
        }
Пример #10
0
        static void Main(string[] args)
        {
            var queue = new Queue.Queue <int>();

            for (int i = 0; i < 10; i++)
            {
                queue.Enqueue(i);
            }

            foreach (var item in queue)
            {
                System.Console.WriteLine(item);
            }
        }
        public void PUT_PeekContract([PexAssumeUnderTest] Queue.Queue <int> s1)
        {
            AssumePrecondition.IsTrue(s1.Count > 0);
            int Old_s1Count = s1.Count;
            //int Old_Top = s1.Peek();

            /*Code */
            int New_Ret = s1.Peek();

            int New_s1Count = s1.Count;
            //int New_Top = s1.Peek();
            bool New_s1ContainsNewRet = s1.Contains(New_Ret);

            PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            //PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            //PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            PexObserve.ValueForViewing("$new_ret", New_Ret);
            PexObserve.ValueForViewing("$New_s1ContainsNewRet", New_s1ContainsNewRet);

            Assert.True(((New_s1Count == Old_s1Count && New_s1ContainsNewRet && Old_s1Count >= 1)));
        }
Пример #12
0
        public void Test_Queue_int()
        {
            Queue.Queue <int> myQ = new Queue.Queue <int>();
            myQ.Enqueue(1); myQ.Enqueue(2);
            myQ.Enqueue(3);
            myQ.Enqueue(4);
            Assert.AreEqual(myQ.Length, 4);
            myQ.Dequeue();
            Assert.AreEqual(myQ.Length, 3);
            Assert.AreEqual(myQ.IsEmpty, false);
            var TestList = new List <string>()
            {
                "2", "3", "4"
            };
            int i = 0;

            foreach (int elem in myQ)
            {
                Assert.AreEqual(elem.ToString(), TestList[i]);
                i++;
            }
        }
Пример #13
0
        public void PUT_CountContract([PexAssumeUnderTest] Queue.Queue <int> s1)
        {
            AssumePrecondition.IsTrue(true);
            int Old_s1Count = s1.Count;
            //int Old_Ret = PexChoose.Value<int>("old_ret");
            int Old_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top");

            /*Code */
            int New_Ret = s1.Count;

            int New_s1Count = s1.Count;
            int New_Top     = Old_Top; // consult about this decision later

            PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            //PexObserve.ValueForViewing("$old_s1_ret", Old_Ret);
            PexObserve.ValueForViewing("$new_ret", New_Ret);


            Assert.True(((New_Top == Old_Top && New_Ret == Old_s1Count && New_Ret == New_s1Count)));
        }
        public void PUT_CountContract([PexAssumeUnderTest] Queue.Queue <int> s1)
        {
            AssumePrecondition.IsTrue(true);
            //int Old_s1Count = s1.Count;
            int Old_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("old_top");

            /*Code */
            int New_Ret = s1.Count;

            //int New_s1Count = s1.Count;
            int New_Top = s1.Count > 0 ? s1.Peek() : PexChoose.Value <int>("new_top");

            //int New_Top = Old_Top; // alternate semantics
            //bool New_ContainsNewRet = s1.Contains(New_Ret);

            //PexObserve.ValueForViewing("$old_s1_Count", Old_s1Count);
            //PexObserve.ValueForViewing("$new_s1_Count", New_s1Count);
            PexObserve.ValueForViewing("$old_s1_Peek", Old_Top);
            PexObserve.ValueForViewing("$new_s1_Peek", New_Top);
            PexObserve.ValueForViewing("$new_ret", New_Ret);
            //PexObserve.ValueForViewing("$new_containsNewRet", New_ContainsNewRet);

            Assert.True(((New_Top == Old_Top && New_Ret >= 0) || New_Ret == 0));
        }