Skip to content
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

Clock - extreme values test cases? #150

Closed
kukimik opened this issue Oct 11, 2024 · 6 comments
Closed

Clock - extreme values test cases? #150

kukimik opened this issue Oct 11, 2024 · 6 comments

Comments

@kukimik
Copy link

kukimik commented Oct 11, 2024

What do you think about adding tests that check the program works correctly for extreme values of hours and minutes, i.e.: -9_223_372_036_854_775_808 and 9_223_372_036_854_775_807?

On the one hand, it is simple and elegant to define subtract in terms of add by setting:

subtract = \clock, {hours, minutes} -> add clock {hours : -hours, minutes : -minutes}

and in practice this is often the "right" thing to do. This approach teaches code reuse.

On the other hand, subtract defined as above will fail if either hours or minutes have value -9_223_372_036_854_775_808. If this case is included in the tests, it can teach being careful about overflows.


Also, for such inputs some reasonable programs will fail at converting hours to minutes and other similar operations.

@kukimik kukimik changed the title Clock - extremal test cases? Clock - extreme values test cases? Oct 11, 2024
@ageron
Copy link
Contributor

ageron commented Oct 11, 2024

Great idea! Would you like to submit a PR or would you prefer I do it (I'm fine either way)? Adding extra tests requires adding a .meta/additional_tests.json file, then you can iterate over these test cases at the end of template.j2 using {% for case in additional_cases %}...{% endfor %}, see #149 for an example. Then you can generate the new test file by running bin/generate_tests.py clock. You may need to install Python and the libraries listed in requirements-generator.txt (using python -m pip install -r requirements-generator.txt).

@kukimik
Copy link
Author

kukimik commented Oct 12, 2024

Thanks for your kind words! And I really appreciate the instructions you gave, I think it's a very good approach towards new contributors. Unfortunately I've been feeling somewhat overloaded recently, and I'd rather not add this to my TODO list. So if you are fine with creating a PR, that would be great.

@ageron
Copy link
Contributor

ageron commented Oct 15, 2024

Hi @kukimik ,
I've submitted PR #155 if you want to take a look? It complicates the solution quite a bit, so I'm thinking it might be better to test that the program either returns Ok with the correct answer, or an Err, but never crashes. This way the users learn to be careful about overflows, but they can choose to fully support extreme values, or to return an Err when the input is larger than some threshold (if they're a bit lazy). Wdyt?

@kukimik
Copy link
Author

kukimik commented Oct 17, 2024

@ageron Thanks, I'll take a look at it in a few days.

@ageron ageron closed this as completed in d99ef97 Oct 19, 2024
@kukimik
Copy link
Author

kukimik commented Oct 20, 2024

Looks like I'm late. Sorry. Anyway, thanks for handling this!

@ageron
Copy link
Contributor

ageron commented Oct 20, 2024

No worries at all, thanks for the suggestion!

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

No branches or pull requests

2 participants