Skip to content

Add split-second-stopwatch exercise #2547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
Apr 15, 2025
Merged

Conversation

ErikSchierboom
Copy link
Member

@ErikSchierboom ErikSchierboom commented Mar 26, 2025

This PR is intended as a starting point for a discussion on adding a new practice exercise.
The exercise's goal is to have students work with time, as well as deal with a sort of state machine.

The things I'd like to discuss are:

  1. A nice background story
  2. Ideas on how to best structure/formulate the instructions
  3. Thoughts on how I've setup the canonical data (it's inspired by the canonical data of circular-buffer)

I've done a basic implementation of the exercise in C#: exercism/csharp#2403

@ErikSchierboom
Copy link
Member Author

CC @exercism/reviewers

Copy link
Member

@tasxatzial tasxatzial left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reviewed the instructions and intro as thoroughly as I could. Here are the changes I believe would improve clarity and flow. Hopefully, I haven't overlooked anything. Of course, there's some subjectivity involved, so feel free to adjust and incorporate whatever you find appropriate.

ErikSchierboom and others added 6 commits March 28, 2025 20:06
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>

- Start: start/resume time tracking
- Stop: stop (pause) time tracking
- Current lap: the time tracked for the current lap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Current lap: the time tracked for the current lap
- Current lap: display the time tracked for the current lap

The other list items use a verb to indicate what we're doing with the tracked time.

- Start: start/resume time tracking
- Stop: stop (pause) time tracking
- Current lap: the time tracked for the current lap
- Previous laps: the times of all previously recorded laps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- Previous laps: the times of all previously recorded laps
- Previous laps: display the times of all previously recorded laps

The other list items use a verb to indicate what we're doing with the tracked time.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also is this the running total or all the individual lap times?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"display" implies "STDOUT" to me, which isn't used in most tracks/exercises.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track the time then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Track could work. What would your preference be Isaac? BTW I agree with Isaac's sentiment

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retrieve the previously recorded lap times? I'm not sure if "track" would imply an implementation detail.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also had a lot of trouble with current lap and previous laps when I initially reviewed. I intentionally left out the verbs because I wasn't sure what an appropriate verb would be. I intended to ask a question but completely forgot about it before posting the review.

- Current lap: the time tracked for the current lap
- Previous laps: the times of all previously recorded laps
- Reset: stop time tracking, reset the current lap, and clear all previously recorded laps
- Lap: add the current lap time to the previous laps and start a new lap
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line is unclear. Are we adding the lap time to a running total or keeping a history of the previous laps?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, sort of both. Lap does not influence the total running time, it's just a cutoff point where the current lap time is basically "stopped", then added to the previous laps and then the current lap time is reset in order to start counting from zero again

- Start: start/resume time tracking
- Stop: stop (pause) time tracking
- Current lap: the time tracked for the current lap
- Previous laps: the times of all previously recorded laps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"display" implies "STDOUT" to me, which isn't used in most tracks/exercises.

@IsaacG
Copy link
Member

IsaacG commented Mar 29, 2025

FWIW I wrote a simple semi-flexible tester that reads the tests from the JSON file and tests the implementation, in Python.

@ErikSchierboom
Copy link
Member Author

I've tweaked a bit.

ErikSchierboom and others added 2 commits March 31, 2025 14:34
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
@@ -0,0 +1,194 @@
{
"exercise": "split-second-stopwatch",
"comments": ["Times are formatted as 'HH:mm:ss'."],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may not be clear in terms of "What do these letters mean". I mean to say that it may be intuitive that it is hour, minutes, seconds, but why the change in case for hours?

It can be useful to show a time where the HH is put in place, such as 13:14:15, to show the difference from a 12 hour clock to a twenty four hour clock. To others, it will be clear, but via experience rather than inherent knowledge.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point! I'll update

{
"command": "lap"
},
,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
,

jq says invalid JSON.

},
{
"command": "currentLap",
"expected": ["00:00:00"]
Copy link
Member

@IsaacG IsaacG Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior currentLap commands expect a string. This and the next expect a list.

Same for total below.

"command": "stop"
},
{
"command": "lap"
Copy link
Member

@IsaacG IsaacG Apr 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

error: cannot lap a stopwatch that is not running

The tests suggest after calling stop the state is ready. The last test says lap cannot be called from a ready state. 7 other tests call stop (putting it into a ready state) then lap.

@ErikSchierboom
Copy link
Member Author

Yeah, I'm still working on the canonical data. I'll fix it.

@ErikSchierboom ErikSchierboom marked this pull request as ready for review April 9, 2025 07:31
@ErikSchierboom ErikSchierboom requested a review from a team as a code owner April 9, 2025 07:31
@ErikSchierboom
Copy link
Member Author

I've updated and streamlined the canonical data as well as adding more test cases.
I've also attempted to make the introduction slightly less boring and the instructions more clear.

@IsaacG
Copy link
Member

IsaacG commented Apr 10, 2025

This data works with my implementation.
https://gist.github.com/IsaacG/cb84b0eb3a3e5aebfbb578e034d0ac55

» python stopwatch.py https://raw.githubusercontent.com/exercism/problem-specifications/20911be341111aa85715740890eafff65ba11936/exercises/split-second-stopwatch/canonical-data.json
{'pass': 39, 'fail': 0}

@ErikSchierboom
Copy link
Member Author

This is now ready for another round of reviews

ErikSchierboom and others added 3 commits April 13, 2025 18:52
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
Co-authored-by: Anastasios Chatzialexiou <16361161+tasxatzial@users.noreply.github.com>
@ErikSchierboom
Copy link
Member Author

@BNAndras could you maybe also check the latest version?

Copy link
Member

@BNAndras BNAndras left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving with one small potential tweak.

Co-authored-by: András B Nagy <20251272+BNAndras@users.noreply.github.com>
@ErikSchierboom ErikSchierboom merged commit f8c8521 into main Apr 15, 2025
6 of 7 checks passed
@ErikSchierboom ErikSchierboom deleted the split-second-stopwatch branch April 15, 2025 16:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants