Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        public static void Check([PexAssumeNotNull] int[] arr1, [PexAssumeNotNull] int[] arr2,
                                 [PexAssumeNotNull] int[] arr3, [PexAssumeNotNull] int[] solnArr)
        {
            PexAssume.AreDistinctReferences(new Object[] { arr1, arr2, arr3, solnArr }); //Don't refer to same mem locations
            PexAssume.IsTrue(isEquals(arr1, arr2));                                      //Deep check
            PexAssume.IsTrue(isEquals(arr2, arr3));
            PexAssume.IsTrue(isEquals(arr3, solnArr));



            bool ans1Except = false, ans2Except = false, ans3Except = false, solnExcept = false;
            int  ans1 = -100, ans2 = -100, ans3 = -100, solnAns = -100, count = 0;

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

            /*
             * try
             * {
             *  ans2 = PartitionerSub2.partition(arr2);
             * }
             * catch (IndexOutOfRangeException)
             * {
             *  ans2Except = true;
             * }
             *
             * try
             * {
             *  ans3 = PartitionerSub3.partition(arr3);
             * }
             * catch (IndexOutOfRangeException)
             * {
             *  ans3Except = true;
             * }
             * */

            try
            {
                solnAns = PartitionerSolutionForReal.partition(solnArr);
            }
            catch (IndexOutOfRangeException)
            {
                solnExcept = true;
            }


            bool passingCondition = ((ans1Except == solnExcept && ans1Except == true) || (ans1Except == solnExcept && ans1Except == false && ans1 == solnAns));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                count++;
                Debug.WriteLine("sub1 not equal to instructor soln");
            }

            /*
             * bool passingCondition2 = ((ans2Except == solnExcept && ans2Except == true) || (ans2Except == solnExcept && ans2Except == false && ans2 == solnAns));
             * bool failingCondition2 = !passingCondition2;
             * if (failingCondition2)
             * {
             *  count++;
             *  Debug.WriteLine("sub2 not equal to instructor soln");
             * }
             *
             * bool passingCondition3 = ((ans3Except == solnExcept && ans3Except == true) || (ans3Except == solnExcept && ans3Except == false && ans3 == solnAns));
             * bool failingCondition3 = !passingCondition3;
             * if (failingCondition3)
             * {
             *  count++;
             *  Debug.WriteLine("sub3 not equal to instructor soln");
             * }
             * */


            PexObserve.ValueForViewing("count", count);
            PexAssert.IsTrue(count <= 3);
        }