Skip to content

Instantly share code, notes, and snippets.

@edvm
Created February 19, 2016 22:02
Show Gist options
  • Save edvm/4855ab1a67e96e59eaf7 to your computer and use it in GitHub Desktop.
Save edvm/4855ab1a67e96e59eaf7 to your computer and use it in GitHub Desktop.
# 1. Create a Python function that gets an integer between 1 - 12 (as an hour) and returns the exact time in hours
# and minutes at which the hands of the clock overlap at this hour
# (for example, for 1, the result will be close to 1:06)
# 2. create a unit test for this function, using 'assert', or the Python 'unittest' framework
# 3. [BONUS]
# a. add also seconds calculation to the return value of the function.
# b. calculate the angle of the hands in 360 degrees system
# taking 12:00 (noon, midnight) as a point of reference
# ATTENTION: You do not need to import any modules to implement this task
# declaration:
def hour_overlap(hour):
#implement body of the method
mins = hour * 5
secs = mins * 60
angle = hour * 30
return {
"hours": hour,
"mins": mins, #int
"secs": secs, #int
"min_angle": angle # float
}
def test_dict_instance():
try:
res = hour_overlap(1)
assert isinstance(res, dict)
except AssertionError as e:
print("Oh, snap! the test has failed. exception: {}").format(e)
def your_test_one():
res = hour_overlap(2)
assert isinstance(res, dict)
assert res['hours'] == 2
assert res['mins'] == 10
assert res['secs'] == 600
assert res['min_angle'] == 60
def your_test_two():
res = hour_overlap(6)
assert isinstance(res, dict)
assert res['hours'] == 6
assert res['mins'] == 30
assert res['secs'] == 1800
assert res['min_angle'] == 180
if __name__ == '__main__':
for i in range(1, 12):
print(hour_overlap(i))
test_dict_instance()
your_test_one()
your_test_two()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment