exercism / problem-specifications

Shared metadata for exercism exercises.
MIT License
326 stars 541 forks source link

grains: test `description` values contain "raises an exception" #2197

Closed ee7 closed 1 year ago

ee7 commented 1 year ago

But not all languages have exceptions.

At the time of writing, grains is the only exercise that mentions "exception" in the test description:

$ git rev-parse --short HEAD
89237c5d
$ git grep --ignore-case --break --heading 'exception'
README.md
52:- Test cases are immutable, which means that once a test case has been added, it never changes. There are two exceptions:

exercises/bowling/canonical:data.json
20:    "whether that be via exceptions, optional values, or otherwise."

exercises/circular:buffer/canonical-data.json
19:    "Raising an exception, returning (int, error), returning Option<int>, etc.",

exercises/dominoes/canonical:data.json
17:    "return Option<Vector<Domino>>, return ([]Domino, error), raise exception, etc.",

exercises/grains/canonical:data.json
76:          "description": "square 0 raises an exception",
87:          "description": "negative square raises an exception",
98:          "description": "square greater than 64 raises an exception",

exercises/hamming/canonical:data.json
8:    "indicated with an error object.  Language idioms of errors or exceptions",

exercises/largest:series-product/canonical-data.json
5:    "e.g. raise exceptions, return (int, error), return Option<int>, etc.",

exercises/triangle/canonical:data.json
17:    " or exception. Choose what is idiomatic for your language.             "
kytrinyx commented 1 year ago

How about changing them to say that they are invalid? Then languages can decide what that looks like.

suraj-mandal commented 1 year ago

I was also facing exception while creating the grains exercise for the gleam track!

BethanyG commented 1 year ago

Our current Grains template checks the description for "error", and then generates a with raises check that the student raises with an appropriate error message. But we could also as easily check for 'invalid' in the description, or some other tag for error case.

kytrinyx commented 1 year ago

In my generators I check whether the expected is a hash with exactly one key called error. I haven't made generators for every exercise in problem-specifications, but so far it's worked consistently:

https://github.com/exercism/problem-specifications/blob/89237c5ddafb5e0c4954d7cc4805a91d165a95a1/exercises/grains/canonical-data.json#L81-L83