FsCheck显示异常C#

时间:2017-05-29 13:15:04

标签: c# fscheck

我在玩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()返回相同的结果,但是我失败了。

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 个答案:

没有答案