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

Change the reactor temperature to something smiliar but executable #179

Open
JensWehner opened this issue Jun 18, 2021 · 7 comments
Open

Comments

@JensWehner
Copy link
Contributor

JensWehner commented Jun 18, 2021

For python we replaced the test by this:

# Hint look at monkeypatching for functions
import time
def check_time_to_now_even(seconds):
    """
    Checks whether time difference between now and given time in seconds is even
    """
    if seconds < 0:
        raise ValueError('received negative input')
   
    now=time.time()
    return (seconds-now)%2 == 0

with the solution

#Solution to #4
def test_check_time(monkeypatch):
  def mocktime():
    return 2
  monkeypatch.setattr(time,"time",mocktime)
  assert check_time_to_now_even(0) == 1
  assert check_time_to_now_even(1) == 0

Advantage is people can actually play around with it. The function is quite nonsensical, but we had a better experience with this.

@bast
Copy link
Member

bast commented Jun 18, 2021

Good suggestion to turn it to something executable. Thanks!

Similar idea could be to test the following function without waiting for 4 years:

import datetime

def we_are_in_a_leap_year():
    year = datetime.datetime.now().year
    try:
        # function throws ValueError if the date (Feb 29) does not exist for
        # this year
        datetime.datetime(year, 2, 29)
        return True
    except ValueError:
        return False

@JensWehner
Copy link
Contributor Author

Yes in the end I do not care, but most students actually wrote tests for this exercise, which was really nice to see how engaged they were. The reactor exercise confused many and we spend a lot of time explaining that this code does not work. So I think the executable code is much better, which exact one you take I do not care. :) Yours is maybe already more relatable and less construed.

@bast
Copy link
Member

bast commented Jun 22, 2021

I agree the reactor one is weird and also full support to replace it.

@JensWehner
Copy link
Contributor Author

So I make a PR and we merge it or is there any reason that would hold this up?

@bast
Copy link
Member

bast commented Jun 24, 2021

Yes please go ahead with the PR. Thanks a lot for this suggestion. When I taught it, I always just skimmed over it so you have more experience here what works well and what doesn't.

@rantahar
Copy link

Am I right in thinking some languages are still missing? I will not merge yet, but we should get back to this.

@JensWehner
Copy link
Contributor Author

The problem with other languages is, that it it requires a lot of boilerplate to make the test work. Or even Macros, dependency injection or other stuff.

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

3 participants