Beispiel #1
0
        public static void Check([PexAssumeNotNull] int[] arr1, [PexAssumeNotNull] int[] arr2)
        {
            PexAssume.AreNotSame(arr1, arr2);       //Don't refer to same mem locations
            PexAssume.IsTrue(isEquals(arr1, arr2)); //Deep check

            bool ans1Except = false, ans2Except = false;
            int  ans1 = -100, ans2 = -100;

            try
            {
                ans1 = Partitioner.partition(arr1);
            }
            catch (IndexOutOfRangeException)
            {
                ans1Except = true;
            }

            try
            {
                ans2 = PartitionerSolution.partition(arr2);
            }
            catch (IndexOutOfRangeException)
            {
                ans2Except = true;
            }

            bool passingCondition = ((ans1Except == ans2Except && ans1Except == true) || (ans1Except == ans2Except && ans1Except == false && ans1 == ans2));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception();
            }
        }
Beispiel #2
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));
        }
Beispiel #3
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();
            }
        }
Beispiel #4
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.");
                        }
                    }
                }
            }
        }
Beispiel #5
0
        public static void Check([PexAssumeUnderTest] BinaryTree tree1, [PexAssumeUnderTest] BinaryTreeSolution tree2, double x, string inputString, bool treeType, int numIterations)
        {
            //Assume both trees have same contents
            PexAssume.IsTrue(isEqual(tree1.root, tree2.root));
            //Assume both trees have same number of nodes
            PexAssume.IsTrue(Count(tree1.root).Equals(Count(tree2.root)));
            //Assume trees don't point to same mem locations
            PexAssume.AreNotSame(tree1, tree2);

            bool tree1Exception = false;
            bool tree2Exception = false;

            try
            {
                if (treeType)
                {
                    for (int i = 0; i < numIterations; i++)
                    {
                        tree1.add(inputString); //treeType = true => input string
                    }
                }
                else
                {
                    for (int i = 0; i < numIterations; i++)
                    {
                        tree1.add(x); //treeType = false => input double
                    }
                }
            }
            catch (Exception)
            {
                tree1Exception = true;
            }
            try
            {
                if (treeType)
                {
                    for (int i = 0; i < numIterations; i++)
                    {
                        tree2.add(inputString);
                    }
                }
                else
                {
                    for (int i = 0; i < numIterations; i++)
                    {
                        tree2.add(x);
                    }
                }
            }
            catch (Exception)
            {
                tree2Exception = true;
            }

            bool passingCondition = ((tree1Exception == tree2Exception && tree1Exception == true) ||
                                     (tree1Exception == tree2Exception && tree1Exception == false &&
                                      tree1.countLessThan(x).Equals(tree2.countLessThan(x))));
            bool failingCondition = !passingCondition;
            if (failingCondition)
            {
                throw new Exception();
            }
        }