Closed maribu closed 8 years ago
Thanks, this is a bug. Counter intuitive behavior is exactly what i was going for - that's the point of testing-, but I apparently managed to confuse myself while writing it. In my defence writing test is boring as hell and I usually do that late at night.
The test case was actually correct according to the original proposal (n3554), which defined the neutral element as T{0}
, but we changed it at some point to be the default constructor. I forgot to update the test case.
Good catch, thanks.
I think the unit tests for reduce using the custom type aren't correct. I believe the result of an empty reduce without providing an initial value should return the value of the default constructor of the custom type. Also reduce over a non-empty collection of a custom type without providing a initial value should return the sum of that collection plus the value of the default constructor of the custom type.
I'm not totally sure if I read the specification correctly here, as this behavior is a bit counterintuitive (I would intuitively expect the sum of an empty collection to be 0, and a sum of 100 elements each having a value of 1 to be 100).