I have always found it annoying that the exercism specifications
do not spell things out, so you HAVE to read the tests to find out
what you are supposed to do, which pretty much spoils the point of
them BEING tests.

In this case, we note that there is a test case where the number
of hours is 100, and it is to be accepted as meaning '04'.
There is also a test case where the number of minutes is 160
and it is to be taken as 40 minutes plus 2 hours.

So the only way you can pass the tests is something like
class methods for: 'instance creation'
  hours: h minutes: m
    ^self new setMinutesSinceMidnight: (h * 60 + m bitOr: 0) \\ 1440

methods for: 'private'
  setMinutesSinceMidnight: m
    minutesSinceMidnight := m.

methods for: 'accessing'
  hour
    ^minutesSinceMidnight // 60

  minute
    ^minutesSinceMidnight \\ 60

The only *checking* that is involved is that the hour and minute counts
must be integers, which I used " bitOr: 0" to do.  What's the best way to
do thisE?

As for where to do checking in general,
put it as close to the encapsulation boundary as you reasonably can.
If there is a PUBLIC method for changing the time on a Clock,
you need to put the checking in that method.  If (as here) a clock value
is supposed to be immutable, put it in the instance creation method.



On Mon, 31 Aug 2020 at 18:18, Roelof Wobben via Pharo-users <
pharo-users@lists.pharo.org> wrote:

> Hello,
>
> I have this challenge from exercism :
> https://github.com/exercism/pharo-smalltalk/tree/master/exercises/clock
>
> and this function is given :
>
> hour: anInteger minute: anInteger2
>      self shouldBeImplemented
>
>
> Schould I make it on this class method work that the minutes will not
> exceed the 59 minutes
> So when for example when 70 min are given so hour:0  minute:70 it will
> be converted to hour: 1 minutes: 10
> or can I better do this on the instance side.
>
> Regards,
>
> Roelof
>
>
>

Reply via email to