Skip to content

resistor-color-trio: Add exercise (with extensions)#869

Merged
sshine merged 9 commits intoexercism:masterfrom
sshine:resistor-color-trio
Nov 9, 2019
Merged

resistor-color-trio: Add exercise (with extensions)#869
sshine merged 9 commits intoexercism:masterfrom
sshine:resistor-color-trio

Conversation

@sshine
Copy link
Copy Markdown
Contributor

@sshine sshine commented Oct 14, 2019

This adds the exercise from exercism/problem-specifications#1551.

In addition to the canonical exercise, this implementation extends:

  • Add a "zero" test case (Black, Black, Black).

  • Add a Data.Text hint in .meta/hints.md.

  • Export both a label function and an ohms function: While the
    exercise is mainly about printing a formatted string, this nudges
    the student towards separating print and calculate.

  • For totality, since Resistor allows expressing resistors in the
    megaohm and gigaohm ranges, extend the exercise so that the correct
    unit beyond kiloohms are returned.

  • Extended unit tests are added, and coverage is described as such:

    Canonical tests are marked with 'x'.
    Extended tests are marked with 'y'.
    Optional (commented out) tests are marked with 'z'.

    Color       1, 2      3
    -------------------------
    Black       xyyyyy    xyy
    Brown       xyz       x
    Red         xyz       xz
    Orange      xxz       x
    Yellow      xyz       x
    Green       xyz       yz
    Blue        xyz       y
    Violet      xy        y
    Grey        xy        yz
    White       yy        y
    

    The over-representation of Black is partly caused by the fact that
    canonical and extended tests avoid edge cases like "4.7 kiloohms".
    There is some didactial point in incremental improvements, and as
    such, canonical and extended tests partially validates solutions.

    Optional (commented out) tests make the exercise considerably more
    difficult, so they are accompanied with a disclaimer that students
    may choose freely to include them or not.

    This way, students who are oblivious to the edge cases will not be
    aware of them, and students who are not (either by thinking or by
    inspecting the unit tests) will be able to choose.

This adds the exercise from exercism/problem-specifications#1551.

In addition to the canonical exercise, this implementation extends:
 - Add a "zero" test case (Black, Black, Black).

 - Add a `Data.Text` hint in `.meta/hints.md`.

 - Export both a `label` function *and* an `ohms` function: While the
   exercise is mainly about printing a formatted string, this nudges
   the student towards separating print and calculate.

 - For totality, since `Resistor` allows expressing resistors in the
   megaohm and gigaohm ranges, extend the exercise so that the correct
   unit beyond kiloohms are returned.

 - Extended unit tests are added, and coverage is described as such:

   Canonical tests are marked with 'x'.
   Extended tests are marked with 'y'.
   Optional (commented out) tests are marked with 'z'.

   ```
   Black       xyyyyy    xyy
   Brown       xyz       x
   Red         xyz       xz
   Orange      xxz       x
   Yellow      xyz       x
   Green       xyz       yz
   Blue        xyz       y
   Violet      xy        y
   Grey        xy        yz
   White       yy        y
   ```

   The over-representation of Black is partly caused by the fact that
   canonical and extended tests avoid edge cases like "4.7 kiloohms".
   There is some didactial point in incremental improvements, and as
   such, canonical and extended tests partially validates solutions.

   Optional (commented out) tests make the exercise considerably more
   difficult, so they are accompanied with a disclaimer that students
   may choose freely to include them or not.

   This way, students who are oblivious to the edge cases will not be
   aware of them, and students who are not (either by thinking or by
   inspecting the unit tests) will be able to choose.
@sshine
Copy link
Copy Markdown
Contributor Author

sshine commented Oct 14, 2019

This PR is currently marked as WIP because the example solutions don't handle the optional tests.

@sshine
Copy link
Copy Markdown
Contributor Author

sshine commented Oct 14, 2019

Currently no special-cases for "1 ohm", "1 kiloohm", "1 megaohm" and "1 gigaohm".

I'm unsure if they should be added as additional optional tests, or simply not be mentioned at all.

@sshine
Copy link
Copy Markdown
Contributor Author

sshine commented Oct 14, 2019

Also, I learned something very cool: 1.2e3 :: Int using the NumDecimals pragma.

Make it a non-core exercise unlocked after resistor-color-duo,
which is also a non-core exercise. Both are unlocked by pangram.
This should make maintenance easier.  Although the linebreaks seem
arbitrary to the student, they are not particularly invasive.
@sshine
Copy link
Copy Markdown
Contributor Author

sshine commented Oct 14, 2019

I've realized that the derived Eq instance is problematic:

let ten1 = Resistor (Brown, Black, Black)
    ten2 = Resistor (Black, Brown, Brown)

ohms ten1 == ohms ten2 -- True
ten1      == ten2      -- False

Fortunately, since we only test label and ohms, we never compare Color or Resistor.

I have an idea for making a subsequent refactoring exercise where this insufficiency could come handy.

@sshine
Copy link
Copy Markdown
Contributor Author

sshine commented Nov 4, 2019

I've not enabled the optional tests, so CI does not reveal that the example solutions work for them.

The following demonstrates that this is the case

success-standard

$ stack test
...
label
  ...
  (Brown,Red,Red) should give 1.2 kiloohms
  (Orange,Yellow,Green) should give 3.4 megaohms
  (Green,Blue,Grey) should give 5.6 gigaohms

ohms
  ...
  (Brown,Red,Red) should give 1200
  (Orange,Yellow,Green) should give 3400000
  (Green,Blue,Grey) should give 5600000000

Finished in 0.0013 seconds
30 examples, 0 failures

success-text

The exact same.

@sshine sshine requested a review from petertseng November 4, 2019 13:13
@sshine sshine changed the title [WIP] resistor-color-trio: Add exercise (with extensions) resistor-color-trio: Add exercise (with extensions) Nov 4, 2019
Comment thread exercises/resistor-color-trio/test/Tests.hs
Comment thread exercises/resistor-color-trio/test/Tests.hs Outdated
@sshine sshine merged commit 27866b4 into exercism:master Nov 9, 2019
@sshine sshine deleted the resistor-color-trio branch November 9, 2019 12:59
sshine added a commit that referenced this pull request Jan 14, 2020
resistor-color-duo was added in #808.

resistor-color-trio was added in #869.

Yet there is no resistor-color. I argue that there shouldn't be.

A reasonable solution might look like

```haskell
data Color = ...
  deriving (Eq, Enum, Bounded)

colorCode :: Color -> Int
colorCode = fromEnum

colors :: [Color]
colors = [minBound..]
```

which makes it approximately as simple as the gigasecond exercise which
was marked as deprecated in #280 (decision made in #230). Still, if it
is simply missing, it will appear as an exercise that is potentially
implementable on https://tracks.exercism.io/haskell/master/unimplemented

Since a question was raised about this exercise once, marking it as
foregone will limit further requests made in vain.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants