FsCheck displaying exception C#

120 Views Asked by At

I am playing with FsCheck. And it fails on

0:
[|-1; 1|]
shrink:
[|-1; 0|]
shrink:
[|1; 0|]
shrink:
[|0; 0|]
Falsifiable, after 1 test (3 shrinks) (StdGen (1052297207,296308070)):
Label of failing property: original (0,0) first sum 0, second 0
Original:
[|-1; 1|]
Shrunk:
[|0; 0|]

Why? Two operations ArrayHelpers.SumOfElements(original) and original.Sum() return the same result but iy fails.

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Prop.ForAll<int[]>(original =>
            {
                var firstSum = ArrayHelpers.SumOfElements(original);
                return (!(original.Sum() == firstSum)).When(original.Count() > 1).Label($"original ({string.Join(",", original)}) first sum {firstSum}, second {original.Sum()}");
            }).VerboseCheck();
        }
    }


    public static class ArrayHelpers
    {
        public static int SumOfElements(int[] array)
        {
            int sum = 0;
            for (int i = 0; i < array.Count(); i++)
            {
                sum += array[i];
            }
            return sum;
        }
    }
}
0

There are 0 best solutions below