Open Chrono79 opened 5 years ago
Needs fixing: None that I know of now.
Closing because there's no more left. Feel free to comment if there's more. Also, consider making a wiki page if the number is high.
https://www.codewars.com/kata/form-the-largest
this task is also vulerable: this code works even for tests on 100 random values
i.e. this code unexpectedly passes all the tests because there is no declare(strict=1)
or type hinting of return type:
function maxNumber($n) {
return true;
}
@IgorKharchenko in general, please use kata discussion page for kata issues and let the author know. GitHub issues are not for kata issues. If there's many kata with the problem, please let me know so I can help with organizing the information for the community to contribute.
@IgorKharchenko that particular kata was already fixed some hours ago, before you posted. Try clicking reset to see the changes.
I reopen this thread again because some more katas with this problem were found.
@kazk could you run a query to get a list of PHP katas that use assertEquals to check them?
Ugh, we have 824 kata matching this->assertEquals
.
Is there a reason to use assertEquals
? I can replace with assertSame
and test it before saving the change.
I have my doubts about objects, if they're primitives, then assertSame is the way to go. Could we have a list of those katas?
Or.... we could replace and then fix only those that become broken.
These failed to update:
I've found a problem, for example in this kata the function is typed: Sum Arrays when comparing against 0 it failed because the current solutions returned a float. I've already changed that single test to use assertEquals.
But in this other kata: Calculate average there are mixed results, some arrays contain integers and some other floats, the function isn't typed so the type is inferred. Should we change the fixed tests to comply?
Would it be possible to fix the translation in a way so it does not expect mixed output types anymore? Translation with mixed input and output types are a PITA anyway and in many cases they are just an unnecessary nuisance rather than an actual value.
I could make all the tests expect a float and add the type to the initial code too to make it clear. But this would render invalid a lot of solutions, is that ok? But, there is also another problem, it says "empty array should return 0", but it should be 0.0 if a float is expected, now it's not even tested.
Ok, for Calculate average, added the function's type, changed tests to expect a float and finally added the missing empty array test both to sample and attempt tests.
While it's not a PHP issue, the language behaves different than other languages when doing implicit conversion, so when the expected result is a number, and the test suite uses assertEquals, the numbers are converted to booleans instead of the other way around, so with luck, you could pass all tests simply returning true. Sometimes the output of the function is explicitly typed, but removing that from the user's solution, makes this work. This is a list of katas already fixed (changing assertEquals for assertSame):
https://www.codewars.com/kata/find-the-stray-number https://www.codewars.com/kata/playing-with-digits https://www.codewars.com/kata/points-in-the-circle https://www.codewars.com/kata/smallest-possible-sum https://www.codewars.com/kata/evaluate-mathematical-expression https://www.codewars.com/kata/calculate-the-area-of-a-regular-n-sides-polygon-inside-a-circle-of-radius-r https://www.codewars.com/kata/financing-plan-on-planet-xy140z-n https://www.codewars.com/kata/number-zoo-patrol https://www.codewars.com/kata/5a512f6a80eba857280000fc
If you know of any other kata vulnerable to this, just list it in a reply and I'll try to fix it or warn the author/translator to fix it him/herself.
Thanks.