Armstrong-numbers: test case against overflow

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?

You could add a list of scenarios to it so test generators can include or exclude that test.

@ErikSchierboom maybe "overflow" is a new scenario to add?

1 Like

Are there languages incapable of handling overflow?

Well, some languages will quietly overflow, which might not be what we want.

Sounds like a good idea. PR is welcome :)

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?

I’m not entirely convinced how useful this test case is TBH. Do others think it would be a useful test case?

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.

For more info on Python’s int:

  1. SO Post
  2. int type Python
  3. integer objects
  4. OverflowError

But agree that it’s a great test case for languages where overflow is an issue.