Ejemplo n.º 1
0
        public static void Check([PexAssumeNotNull] int[] inputArr, int x)
        {
            LastTen sub1Arr = new LastTen();

            sub1Arr.tenArray = inputArr;

            LastTenSolution sub2Arr = new LastTenSolution();

            sub2Arr.array = inputArr;

            LastTenSolutionForReal sub3Arr = new LastTenSolutionForReal();

            sub3Arr.array = inputArr;

            bool firstNull = false, secondNull = false;

            try
            {
                sub1Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                firstNull = true;
            }

            try
            {
                sub2Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                secondNull = true;
            }

            try
            {
                sub3Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("addSolutionForReal got index out of range!");
            }


            bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && sub2Arr.getLastTen().Equals(sub1Arr.getLastTen())));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception();
            }
        }
Ejemplo n.º 2
0
        public static void Check([PexAssumeNotNull] int[] inputArr, int x, Boolean b)
        {
            // IDEA FROM ZIRUI: Pass in array rather than type LastTen to Check()...THEN construct 3 diff types
            // This way we won't need the Clone() method to polute student's code

            LastTen sub1Arr = new LastTen();

            sub1Arr.tenArray = inputArr;     //TODO: Replace LastTen class' "array" variable!!

            LastTenSolution sub2Arr = new LastTenSolution();

            sub2Arr.array = inputArr;     //TODO: Replace LastTenSolution class' "array" variable!!

            LastTenSolutionForReal sub3Arr = new LastTenSolutionForReal();

            sub3Arr.array = inputArr;

            bool firstNull = false, secondNull = false;

            try
            {
                sub1Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                firstNull = true;
            }

            try
            {
                sub2Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                secondNull = true;
            }

            try
            {
                sub1Arr.add(x);
            }
            catch (IndexOutOfRangeException)
            {
                Console.WriteLine("addSolutionForReal got index out of range!");
            }


            bool passingCondition = ((firstNull == secondNull && firstNull == true) || (firstNull == secondNull && firstNull == false && sub2Arr.getLastTen().Equals(sub1Arr.getLastTen())));
            bool failingCondition = !passingCondition;

            if (failingCondition)
            {
                throw new Exception("Failed test: Reference solution not equal to student submission.");
            }

            if (passingCondition)
            {
                //Implement Tao's PUT:
                if (b)     //Bool to force Pex to explore diff paths
                {
                    if (sub3Arr.getLastTen().Equals(sub1Arr.getLastTen()))
                    {
                        if (!sub2Arr.getLastTen().Equals(sub1Arr.getLastTen()))
                        {
                            throw new Exception();
                        }
                    }
                }
                else
                {
                    if (sub3Arr.getLastTen().Equals(sub2Arr.getLastTen()))
                    {
                        if (!sub2Arr.getLastTen().Equals(sub1Arr.getLastTen()))
                        {
                            throw new Exception();
                        }
                    }
                }
            }
        }