I came across this additional test case while syncing the Rust version of armstrong numbers:
{
"uuid": "e82ac0f4-a8d8-4cf7-8d78-c4fd678fccbd",
"description": "Handles overflow correctly",
"comments": [
"This number has an Armstrong sum equal to 2^32 plus itself,",
"and therefore will be detected as an Armstrong number",
"if the user is incorrectly using wrapping arithmetic with unsigned 32-bit integers."
],
"property": "isArmstrongNumber",
"input": {
"number": 4106098957
},
"expected": false
}
It doesn’t apply to all languages, but it doesn’t hurt either. Should I create a PR?
Well, some languages will quietly overflow, which might not be what we want.
I don’t understand. Many languages overflow quietly. That’s exactly what the test is for. To check that silent overflow is handled correctly.
I think we should only add a scenario if there is at least one language that has to handle an overflow test case differently than other test cases. Does such a language exist?
In PHP we don’t have 32-bit integers anymore. So this test case would not do anything useful.
Nevertheless, in my career I had to fix a good handful of programs that didn’t care for possible overflows and these were hard to find. So for languages where overflows are likely, this is a really good test case.
Python’s int type doesn’t really overflow, and has unlimited precision…within the limits of system memory. So this test case wouldn’t exactly apply. Yes – you can run into a MemoryError, but its not common for core Python applications.