How you handle invalid triangles is up to you. These tests suggest a
triangle is returned, but all of its properties are false. But you
could also have the creation of an invalid triangle return an error
or exception. Choose what is idiomatic for your language.
It would make it easier for tracks with generators if there was a scenario there. Then the generator could more easily decide when to throw an error, versus simply test for “not isosceles”.
This would not be a major change as the Readme says:
The scenarios field can be mutated additively, by adding new scenarios. Existing scenarios must not be changed or removed. Adding new scenarios does therefore does not mean adding a new test case.
How would that differentiate between a valid non-isosceles triangle and an invalid isosceles-looking triangle? The expected: false on both scenarios seems to suggest there is a specific expected behavior for invalid triangles.
Within the new scenario, a generator could expect an “invalid triangle” exception to be thrown. Outside the new scenario, a generator could expected isosceles? to return true/false according to expected. So the generator would no longer need to contain its own triangle-validation logic.
Got it. I think. If I understand correctly, “input-validation” implies “invalid input”. I would suggest being explicit. With a more explicit name, this sounds good to me.
Of course I do have a self-serving reason for bringing this up. I’ve been poking away at creating a MoonScript track. (MoonScript is like CoffeeScript for Lua)
A test generator function might look like
generate_test: (case, level) ->
if type(case.expected) == 'number'
indent "assert.are.equal #{case.expected}, prime #{case.input.number}", level
else
indent "assert.has.errors (-> prime #{case.input.number}), #{quote case.expected.error}", level
In this case I’m branching between a “normal” test and an “error” test based on the type of the expected property of a test case in the canonical data: “expected” is a number or it’s an object with an “error” property. But for the triangle exercise, there’s nothing to branch on.
I wouldn’t want to require the test maintainer to analyze the data to determine if it is or isn’t valid. The data itself ought to clearly indicate that it is invalid.
Maintainers already have to do that for this exercise. Reread the comments at the top of the canonical data.
What I hear that you’re saying: if maintainers want to write a test generator and also choose to throw errors for this case, then they have to implement the program logic in the test generator as well as the example solution.
I will also point out that adding a scenario to these test cases is simply the addition of a piece of data that is used to clearly indicate …