exercism / ocaml

Exercism exercises in OCaml.
https://exercism.org/tracks/ocaml
MIT License
94 stars 50 forks source link

Broken test-generation for exercise space-age #474

Open georgyo opened 1 year ago

georgyo commented 1 year ago

This exercise has been marked as having a broken test generator. There are a lots of reasons for test generation to break for a given exercise including

Useful links

GitHub doesn't allow for linking the diff of an individual file making the relevant canonical-data.json diff impossible to link to. It may be easier to run this in your terminal

git submodule update --init
git -C problem-specifications diff 2af3c9b0074f16c62366c5c533eaacd3ff27b583 -- exercises/space-age/canonical-data.json

Check List

keiravillekode commented 11 months ago

A test case was added to problem-specifications:

      "input": {
        "planet": "Sun",
        "seconds": 680804807
      },
      "expected": {"error": "not a planet"}

One option would be to support this test case: we would require solutions to define a type like

type celestial_body = ... | ... | ... | Sun

We would also need to decide how errors should be reported for this exercise, for example using exceptions or Result.

The other option would be to omit this test case, using include = false

georgyo commented 11 months ago

I don't think we need a celestial_body type. The test says the name of the planet is Sun, but our Sun is not a planet it is a star. There is no consideration for anything that is not a planet.

Likely excluding this test is the best case, because currently Sun would be a compiler error, ocaml doesn't need any explicit tests to prevent or catch the input of Sun.

In order to even accept Sun as input we would need to change the everything to work with strings instead of a variant type. This would make the easiest solution to pattern match on strings instead of a variant type, which is not ideal ocaml.

Any way you chose to solve this is good by me, just consider what would be best for a person who is just starting to learn Ocaml.