ruby icon indicating copy to clipboard operation
ruby copied to clipboard

Idea: add test to Clock for non-clock value passed to '==' operator

Open PatrickMcSweeny opened this issue 4 years ago • 3 comments

When defining the equals '==' operator on a class in Ruby, it is important to account for values being passed that are of unexpected types. Currently, the tests for the '==' method in the Clock exercise only pass instances of the same class to that method. Adding a test that passes 'nil' or some other value would necessitate some way of dealing with non-clock objects being passed.

PatrickMcSweeny avatar Jun 07 '20 12:06 PatrickMcSweeny

The test could check for an equivalent number of minutes and pass, for example. But are we teaching that as a concept, or are the current tests sufficient for what is wanted to teach in this exercise?

For instance, your idea of checking a non-clock for equivalence is an excellent mentoring point, and suitable for v2 without the test that checks for this, as it leaves that discussion open for exploration.

kotp avatar Jun 07 '20 16:06 kotp

Maybe there could be two different tests with non-clock objects so that way they couldn't just call something like 'nil?' and would have to truly deal with dynamic types.

PatrickMcSweeny avatar Jun 07 '20 19:06 PatrickMcSweeny

When mentoring, I will often encourage adding and subtracting minutes as represented by an integer, which accomplishes the same thing kind of thing. But is it a mentoring point, rather than an exercise focus point.

kotp avatar Jun 26 '20 01:06 kotp

But is it a mentoring point, rather than an exercise focus point.

I think this is a reasonable conclusion for now.

If you want to add more tests I would suggest that they be added to the problem-specifications repository (including a scenario for each new test, as we would want to make it possible to filter out these scenarios in languages that do static type checking on inputs).

I'm going to go ahead and close this issue.

kytrinyx avatar Oct 12 '22 22:10 kytrinyx