コード例 #1
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();
            }
        }
コード例 #2
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.");
                        }
                    }
                }
            }
        }