[Amending "Wordy" Tests]: Add More Negative Number Scenarios & Check for Zero Operands

Since the “Wordy” problem specification doesn’t say otherwise, the valid operands seem to be any integers including zero. Are there tests to ensure that a zero operand is not treated as a missing operand and is computed correctly (except of course in the case of division by zero)? Or should the problem specification explicitly restrict the domain of the questions to positive integers only?

Can you provide an illustrative example? It seems at a glance that “What is 1 plus 0?” is already covered in part by “What is 1 plus 1?”.

Also, the question about restricting the problem to positive integers might be better served as a separate discussion. It’s unclear how negative integers are related to whether 0 is detected as an operand or not.

I don’t see a problem with someone treating zero as a missing operand, as long as the result is correct. The tests only check the syntax and the final result; they don’t care how someone arrived at it. That appears to be beyond the scope of this exercise.

My concern is that “falsy” is a complicated concept that differs in many languages, and in some languages it is easy to accidentally write code that will explicitly return the “syntax error” instead of a result when one of the operands is zero. That would not be “as long as the result is correct.” If we don’t want to deal with that at this stage, better to explicitly exclude it in the problem specification than just leave it implicit in the tests. Or add some tests and ensure that submissions don’t make that particular mistake.

The discussion about negative integers is here:

This topic was created to discuss the lack of tests for zero separately. We could of course change the problem specification to continue to allow negative numbers and explicitly exclude (only) zero, but that seems a little odd.

I see. So you are basically looking for an explicit test like “What is 1 plus 0?” to make sure that the user returns “1” instead of treating 0 as missing operand and returning “syntax error”. I have no issue adding such test.

2 Likes

Cross-linking my earlier answer as it’s related: Some "Wordy" Dig Deeper Examples Pass Tests but Don't Handle Negative Numbers Correctly - #8 by SleeplessByte


It’s a difficult and fine line to be “exhausitive” and still teaching things.

In this particular case I agree with your assessment that:

  • either the instructions / test need updating to bound the input to “positive integers”
  • or the tests should be more extensive.

Personally, as I just re-did this exercise, in THIS instance, I think we should add a test case for negative numbers, but should update the content that it’s only whole numbers (integers).


Now on this “zero” topic, zero is a number, it’s an integer, it is fine to exist in the sentence. I do think we should have tests for it to catch those that have solutions break when there is a 0. I don’t think it should cause errors.

1 Like

Including 0 and negative values but restricting it to whole numbers sounds reasonable to me.

2 Likes

Agree that we should add more test cases. In particular:

  • zero scenarios (plus, minus, multiplied by)
  • two and three digit negative numbers for the “what is” scenarios
  • perhaps an error handling scenario for non-iteger numbers
  • perhaps an error handling scenario for division by zero — but I am a bit reticent on this one.

agree



There are already quite a few test cases that deal with addition, subtraction, multiplication and division using negative numbers — although it might not hurt to add a couple more where there are only negative numbers, or the numbers are three or more digits.

But there aren’t many “identity” ones (“what is”), so maybe a couple that are “What is -365?” and “What is -42?” and so forth.

I agree that a division by zero test is probably a bit much. I don’t think these exercises need to be exhaustive, just consistent.