Example #1
0
            public static bool Equals(MetaProgram.List thisObj, MetaProgram.List obj)
            {
                //If not a list
                //if (!(obj is List))
                //    return false;

                if (obj.Count() != thisObj.Count())
                {
                    return(false);
                }
                //Same length
                else
                {
                    //Deep check
                    List current = thisObj;
                    List temp    = obj;
                    while (current != null)
                    {
                        //Iterate
                        if (temp.value != current.value)
                        {
                            return(false);
                        }
                        current = current.next;
                        temp    = temp.next;
                    }
                }
                return(true);
            }
Example #2
0
 public static MetaProgram.List CreateList([PexAssumeNotNull] int[] arr)
 {
     MetaProgram.List list = new MetaProgram.List();
     for (int i = 0; i < arr.Length; i++)
     {
         list.addToEndSolutionForReal(arr[i]); //Instructor factory
     }
     return(list);
 }
Example #3
0
 public static MetaProgram.List CreateList_Student([PexAssumeNotNull] int[] arr)
 {
     MetaProgram.List list = new MetaProgram.List();
     for (int i = 0; i < arr.Length; i++)
     {
         list.addToEnd(arr[i]); //Invoke students' addToEnd
     }
     return(list);
 }
Example #4
0
        public static void Check1([PexAssumeUnderTest] MetaProgram.List l, [PexAssumeUnderTest] MetaProgram.List l2, int x)
        {
            PexAssume.IsTrue(MetaProgram.List.Equals(l, l2));
            PexAssume.AreNotSame(l, l2);

            PexAssume.IsTrue(l.Count() <= 1);

            //int oldCount = l.Count();
            PexObserve.ValueForViewing("old_count", l.Count());
            //PexObserve.ValueForViewing("old_last", l.Last());
            //l.addToEnd(x); //bad
            //l.addToEnd2(x); //bad
            l.addToEnd3(x); //bad
            PexObserve.ValueForViewing("new_count", l.Count());
            //PexObserve.ValueForViewing("new_last", l.Last());

            l2.addToEndSolutionForReal(x); //Reference
            PexAssert.IsTrue(MetaProgram.List.Equals(l, l2));
        }
Example #5
0
        public static void Check([PexAssumeUnderTest] MetaProgram.List l, [PexAssumeUnderTest] MetaProgram.List l2, int x, int numIterations)
        {
            //Use PexAssume.IsTrue instead of Clone(), as not to give Pex any issues
            PexAssume.IsTrue(l.Equals(l2));
            //Ensure that Pex generates two distinct MetaProgram.List objects
            PexAssume.AreNotSame(l, l2);

            bool firstNull  = false;
            bool secondNull = false;

            try
            {
                for (int i = 0; i < numIterations; i++)
                {
                    l.addToEnd(x);
                }
            }
            catch (NullReferenceException)
            {
                firstNull = true;
            }

            try
            {
                for (int j = 0; j < numIterations; j++)
                {
                    l2.addToEndSolution(x);
                }
            }
            catch (NullReferenceException)
            {
                secondNull = true;
            }

            bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && l2.Equals(l)));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception();
            }
        }
Example #6
0
        public static void Check([PexAssumeUnderTest] MetaProgram.List l, [PexAssumeUnderTest] MetaProgram.List l2, [PexAssumeUnderTest] MetaProgram.List l3, int x, Boolean b, int numIterations)
        {
            bool firstNull  = false;
            bool secondNull = false;

            PexAssume.IsTrue(l.Equals(l2));
            PexAssume.IsTrue(l.Equals(l3));
            //Ensure that Pex generates three distinct MetaProgram.List objects
            PexAssume.AreNotSame(l, l2);
            PexAssume.AreNotSame(l, l3);


            // List l2 = l.Clone();
            //List l3 = l.Clone();


            try
            {
                for (int i = 0; i < numIterations; i++)
                {
                    l.addToEnd(x);
                }
            }
            catch (NullReferenceException)
            {
                firstNull = true;
            }

            try
            {
                for (int j = 0; j < numIterations; j++)
                {
                    l2.addToEndSolution(x);
                }
            }
            catch (NullReferenceException)
            {
                secondNull = true;
            }

            try
            {
                for (int j = 0; j < numIterations; j++)
                {
                    l3.addToEndSolutionForReal(x);
                }
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("addToEndSolutionForReal got  null refence exception!");
            }

            bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && l2.Equals(l)));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission.");
            }

            //Implement Subsumption PUT
            //Purpose: Determine if subsumption exists across submissions in different child...
            //...clusters within same parent cluster
            if (passingCondition)
            {
                if (b)
                {
                    if (l3.Equals(l))
                    {
                        if (!l2.Equals(l))
                        {
                            throw new Exception("Exception 1: Student submission is equivalent to correct solution, but is not equal to reference submission.");
                        }
                    }
                }
                else
                {
                    if (l3.Equals(l2))
                    {
                        if (!l2.Equals(l))
                        {
                            throw new Exception("Exception 2: Reference submission is equivalent to correct solution, but is not equal to student submission.");
                        }
                    }
                }
            }
        }
Example #7
0
        public static void Check([PexAssumeUnderTest] MetaProgram.List l, [PexAssumeUnderTest] MetaProgram.List l4,
                                 [PexAssumeUnderTest] MetaProgram.List l6, [PexAssumeUnderTest] MetaProgram.List l9,
                                 [PexAssumeUnderTest] MetaProgram.List l10, [PexAssumeUnderTest] MetaProgram.List lSoln, int x)
        {
            /*PexAssume.IsTrue(MetaProgram.List.Equals(l, l4));
             * PexAssume.IsTrue(MetaProgram.List.Equals(l4, l6));
             * PexAssume.IsTrue(MetaProgram.List.Equals(l6, l9));
             * PexAssume.IsTrue(MetaProgram.List.Equals(l9, l10));
             * PexAssume.IsTrue(MetaProgram.List.Equals(l10, lSoln));*/

            //PexAssume.AreDistinctReferences(new Object[] { l, l4, l6, l9, l10, lSoln });

            PexAssume.IsTrue(MetaProgram.List.Equals(l9, lSoln));
            PexAssume.AreDistinctReferences(new Object[] { l9, lSoln });

            bool firstNull = false;
            bool fourNull  = false;
            bool sixNull   = false;
            bool nineNull  = false;
            bool tenNull   = false;
            bool solnNull  = false;

            int count = 0;

            /*
             * try
             * {
             *   l.addToEnd(x);
             * }
             * catch (NullReferenceException)
             * {
             *   firstNull = true;
             * }
             *
             *
             *
             * try
             * {
             *   l4.addToEnd4(x);
             * }
             * catch (NullReferenceException)
             * {
             *   fourNull = true;
             * }
             *
             *
             *
             *
             * try
             * {
             *   l6.addToEnd6(x);
             * }
             * catch (NullReferenceException)
             * {
             *   sixNull = true;
             * }
             *
             */

            try
            {
                l9.addToEnd9(x);
            }
            catch (NullReferenceException)
            {
                nineNull = true;
            }

            /*
             * try
             * {
             *   l10.addToEnd10(x);
             * }
             * catch (NullReferenceException)
             * {
             *   tenNull = true;
             * }
             * */

            try
            {
                lSoln.addToEndSolutionForReal(x);
            }
            catch (NullReferenceException)
            {
                solnNull = true;
            }

            /*
             * bool passingCondition1 = ((firstNull == solnNull && firstNull == true) || (firstNull == solnNull && firstNull == false && MetaProgram.List.Equals(l, lSoln)));
             * bool failingCondition1 = !passingCondition1;
             * if (failingCondition1)
             * {
             *   count++;
             *   Console.WriteLine("sub1 not equal to instructor soln");
             * }
             *
             *
             *
             * bool passingCondition4 = ((fourNull == solnNull && fourNull == true) || (fourNull == solnNull && fourNull == false && MetaProgram.List.Equals(l4, lSoln)));
             * bool failingCondition4 = !passingCondition4;
             * if (failingCondition4)
             * {
             *   count++;
             *   Console.WriteLine("sub4 not equal to instructor soln");
             * }
             *
             *
             *
             * bool passingCondition6 = ((sixNull == solnNull && sixNull == true) || (sixNull == solnNull && sixNull == false && MetaProgram.List.Equals(l6, lSoln)));
             * bool failingCondition6 = !passingCondition6;
             * if (failingCondition6)
             * {
             *   count++;
             *   Console.WriteLine("sub6 not equal to instructor soln");
             * }
             *
             */
            bool passingCondition9 = ((nineNull == solnNull && nineNull == true) || (nineNull == solnNull && nineNull == false && MetaProgram.List.Equals(l9, lSoln)));
            bool failingCondition9 = !passingCondition9;

            if (failingCondition9)
            {
                count++;
                Console.WriteLine("sub9 not equal to instructor soln");
            }

            /*
             * bool passingCondition10 = ((tenNull == solnNull && tenNull == true) || (tenNull == solnNull && tenNull == false && MetaProgram.List.Equals(l10, lSoln)));
             * bool failingCondition10 = !passingCondition10;
             * if (failingCondition10)
             * {
             *   count++;
             *   Debug.WriteLine("sub10 not equal to instructor soln");
             * }
             */


            PexObserve.ValueForViewing("count", count);

            PexAssert.IsTrue(count == 1); //<------ SUBJECT TO CHANGE!!!!
        }
Example #8
0
        public static void Check([PexAssumeNotNull] MetaProgram.List l, int x, Boolean b)
        {
            bool firstNull  = false;
            bool secondNull = false;

            List l2 = l.Clone();
            List l3 = l.Clone();

            bool notSubsumption = true;


            try
            {
                l.addToEnd(x);
            }
            catch (NullReferenceException)
            {
                firstNull = true;
            }

            try
            {
                l2.addToEndSolution(x);
            }
            catch (NullReferenceException)
            {
                secondNull = true;
            }

            try
            {
                l3.addToEndSolutionForReal(x);
            }
            catch (NullReferenceException)
            {
                Console.WriteLine("addToEndSolutionForReal got  null refence exception!");
            }

            bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && l2.isEquals(l)));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission.");
            }

            //Implement Subsumption PUT
            //Purpose: Determine if subsumption exists across submissions in different child...
            //...clusters within same parent cluster
            if (passingCondition)
            {
                if (b)
                {
                    //s1 >= s2
                    if (l3.isEquals(l))
                    {
                        if (!l2.isEquals(l))
                        {
                            throw new Exception("Student submission is equivalent to correct solution, but is not equal to reference submission.");
                        }
                    }
                }
                else
                {
                    //s2 >= s1
                    if (!l3.isEquals(l))
                    {
                        if (l3.isEquals(l2))
                        {
                            notSubsumption = false;
                        }
                    }
                }
            }
            //Visualize the val of notSubsumption
            PexObserve.ValueForViewing("notSubsumption", notSubsumption);

            PexAssert.IsTrue(notSubsumption);
        }