Clock

Clock

Medium

Instructions

Implement a clock that handles times without dates.

You should be able to add and subtract minutes to it.

Two clocks that represent the same time should be equal to each other.

The tests for this exercise expect that your clock will be implemented using a data declaration in Pyret. If you are unfamiliar with data declarations, the official documentation is a good place to start.

As part of the exercise, you'll be comparing values constructed by a Clock data variant. Because a clock's hours and minutes can roll over in either direction, the following combinations are the same on a clock: 1 hour 1 minute, 0 hours 61 minutes, 25 hours 1 minutes, and 2 hours -59 minutes. Pyret's is testing operator uses structural equality, which will result in none of these combinations being equal by default. To that end, you'll need to define your own equality method for comparing time between values from a Clock data variant. If you're unfamiliar with how Pyret handles equality, review the official docs on equality.


Source

Pairing session with Erin Drummond
Edit via GitHub The link opens in a new window or tab
Pyret Exercism

Ready to start Clock?

Sign up to Exercism to learn and master Pyret with 52 exercises, and real human mentoring, all for free.