Should grade-school follow the canonical contract?

The Scala grade-school exercise tests 7 cases, while problem-specifications has 20. The gap can’t be closed just by adding cases: the track’s School behaves differently from the spec.

  1. add returns Unit. The spec expects true when a student is enrolled and false when they are rejected (5 cases check this).
  2. Duplicates are accepted. The spec rejects a student added twice, whether to the same grade or to another one. Today grade(2) can return Vector(Blair, James, James, Paul).
  3. grade(n) keeps insertion order. The spec expects names sorted alphabetically. Only the extra sorted method sorts, and it has no canonical counterpart.

Any fix changes the stub’s API (add, and probably db/sorted), so existing solutions would stop passing.

Options:

  • A. Adopt the canonical contract. add(name, grade): Boolean, reject duplicates, sort each grade, drop or rework sorted/db. Covers all 20 cases.
  • B. Keep the current contract. Mark the incompatible cases include = false with a comment saying the track’s School predates the canonical one, and sync the cases that fit. Nothing breaks.
  • C. Middle ground. Reject duplicates and sort grades, but keep add returning Unit. This still breaks solutions that rely on duplicates, and still skips the 5 add cases.

My preference is A: the exercise is about keeping a valid roster, and today it lets you enrol the same student twice. B is the fallback.

Which would you pick — A, B or C? A one-letter reply is enough; a sentence on why is even better. It’s especially helpful to hear from anyone who has solved or mentored this exercise.

Details: Decide whether grade-school should follow the canonical School contract · Issue #899 · exercism/scala · GitHub