The Scala series exercise tests 3 of the 11 canonical cases. Five of the missing ones are error cases, and the exercise has no way to report an error:
| input | canonical | Scala today |
|---|---|---|
slices(6, "12345") |
error: slice length cannot be greater than series length | List() |
slices(0, "12345") |
error: slice length cannot be zero | undefined |
slices(-1, "123") |
error: slice length cannot be negative | undefined |
slices(1, "") |
error: series cannot be empty | List() (the suite asserts this) |
Fixing this changes the exercise’s contract, so existing solutions would stop passing. The stub is empty, so only solutions break, not a signature.
Options:
- A.
Option[Seq[Seq[Int]]]—Nonefor invalid input. This is what most of the track already does (say,all-your-base,change,phone-number,bank-account). It doesn’t distinguish between the error messages. - B.
Either[String, Seq[Seq[Int]]]—Leftwith the canonical message. Closest to the spec, but onlyforthdoes this on the track, and it ties the tests to upstream’s wording. - C. Throw
IllegalArgumentException— common on other tracks, but nowhere on this one. - D. Keep the current contract — mark the error cases
include = falsewith a comment and sync only the six valid cases. Nothing breaks.
In all four options, the six valid cases are synced to the canonical inputs and descriptions.
My preference is A, for consistency with the rest of the track. D is the fallback if the breakage isn’t worth it.
- A. Option
- B. Either with messages
- C. Exception
- D. Keep the contract, document the divergence
Details: Decide how series should represent the canonical error cases · Issue #895 · exercism/scala · GitHub