0

我正在玩 FsCheck。它失败了

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|]

为什么?两个操作ArrayHelpers.SumOfElements(original)和 original.Sum() 返回相同的结果但 iy 失败。

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;
        }
    }
}
4

0 回答 0