add solution for lasagne task
This commit is contained in:
parent
16a076cb0d
commit
21fe698bc0
|
@ -2,9 +2,10 @@
|
||||||
# TODO: consider defining the 'PREPARATION_TIME' constant
|
# TODO: consider defining the 'PREPARATION_TIME' constant
|
||||||
# equal to the time it takes to prepare a single layer
|
# equal to the time it takes to prepare a single layer
|
||||||
|
|
||||||
|
EXPECTED_BAKE_TIME = 40
|
||||||
|
|
||||||
# TODO: define the 'bake_time_remaining()' function
|
|
||||||
def bake_time_remaining():
|
def bake_time_remaining(elapsed_bake_time):
|
||||||
"""Calculate the bake time remaining.
|
"""Calculate the bake time remaining.
|
||||||
|
|
||||||
:param elapsed_bake_time: int baking time already elapsed.
|
:param elapsed_bake_time: int baking time already elapsed.
|
||||||
|
@ -15,9 +16,30 @@ def bake_time_remaining():
|
||||||
based on the `EXPECTED_BAKE_TIME`.
|
based on the `EXPECTED_BAKE_TIME`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
pass
|
return EXPECTED_BAKE_TIME - elapsed_bake_time
|
||||||
|
|
||||||
# TODO: define the 'preparation_time_in_minutes()' function
|
|
||||||
# and consider using 'PREPARATION_TIME' here
|
|
||||||
|
|
||||||
# TODO: define the 'elapsed_time_in_minutes()' function
|
def preparation_time_in_minutes(number_of_layers):
|
||||||
|
"""Calculate the amout of time it takes to prepare the desired number of
|
||||||
|
layers.
|
||||||
|
|
||||||
|
:param number_of_layers: int desired number of layers to prepare
|
||||||
|
:return: int time required to prepare layers
|
||||||
|
|
||||||
|
"""
|
||||||
|
return number_of_layers * 2
|
||||||
|
|
||||||
|
|
||||||
|
def elapsed_time_in_minutes(number_of_layers, elapsed_bake_time):
|
||||||
|
"""
|
||||||
|
Return elapsed cooking time.
|
||||||
|
|
||||||
|
This function takes two numbers representing the number of layers & the time already spent
|
||||||
|
baking and calculates the total elapsed minutes spent cooking the lasagna.
|
||||||
|
|
||||||
|
:param number_of_layers: int desired number of layers to prepare
|
||||||
|
:param elapsed_bake_time int
|
||||||
|
:return: int elapsed cooking time
|
||||||
|
"""
|
||||||
|
preparation_time = preparation_time_in_minutes(number_of_layers)
|
||||||
|
return preparation_time + elapsed_bake_time
|
||||||
|
|
|
@ -26,12 +26,10 @@ except ImportError as import_fail:
|
||||||
|
|
||||||
class LasagnaTest(unittest.TestCase):
|
class LasagnaTest(unittest.TestCase):
|
||||||
|
|
||||||
@pytest.mark.task(taskno=1)
|
|
||||||
def test_EXPECTED_BAKE_TIME(self):
|
def test_EXPECTED_BAKE_TIME(self):
|
||||||
failure_msg = 'Expected a constant of EXPECTED_BAKE_TIME with a value of 40.'
|
failure_msg = 'Expected a constant of EXPECTED_BAKE_TIME with a value of 40.'
|
||||||
self.assertEqual(EXPECTED_BAKE_TIME, 40, msg=failure_msg)
|
self.assertEqual(EXPECTED_BAKE_TIME, 40, msg=failure_msg)
|
||||||
|
|
||||||
@pytest.mark.task(taskno=2)
|
|
||||||
def test_bake_time_remaining(self):
|
def test_bake_time_remaining(self):
|
||||||
input_data = [1, 2, 5, 10, 15, 23, 33, 39]
|
input_data = [1, 2, 5, 10, 15, 23, 33, 39]
|
||||||
result_data = [40 - item for item in input_data]
|
result_data = [40 - item for item in input_data]
|
||||||
|
@ -39,9 +37,9 @@ class LasagnaTest(unittest.TestCase):
|
||||||
for variant, (time, result) in enumerate(zip(input_data, result_data), start=1):
|
for variant, (time, result) in enumerate(zip(input_data, result_data), start=1):
|
||||||
with self.subTest(f'variation #{variant}', time=time, result=result):
|
with self.subTest(f'variation #{variant}', time=time, result=result):
|
||||||
failure_msg = f'Expected: {result} but the bake time remaining was calculated incorrectly.'
|
failure_msg = f'Expected: {result} but the bake time remaining was calculated incorrectly.'
|
||||||
self.assertEqual(bake_time_remaining(time), result, msg=failure_msg)
|
self.assertEqual(bake_time_remaining(
|
||||||
|
time), result, msg=failure_msg)
|
||||||
|
|
||||||
@pytest.mark.task(taskno=3)
|
|
||||||
def test_preparation_time_in_minutes(self):
|
def test_preparation_time_in_minutes(self):
|
||||||
input_data = [1, 2, 5, 8, 11, 15]
|
input_data = [1, 2, 5, 8, 11, 15]
|
||||||
result_data = [item * 2 for item in input_data]
|
result_data = [item * 2 for item in input_data]
|
||||||
|
@ -49,22 +47,24 @@ class LasagnaTest(unittest.TestCase):
|
||||||
for variant, (layers, time) in enumerate(zip(input_data, result_data), start=1):
|
for variant, (layers, time) in enumerate(zip(input_data, result_data), start=1):
|
||||||
with self.subTest(f'variation #{variant}', layers=layers, time=time):
|
with self.subTest(f'variation #{variant}', layers=layers, time=time):
|
||||||
failure_msg = f'Expected: {time} minutes, but preparation time was calculated incorrectly.'
|
failure_msg = f'Expected: {time} minutes, but preparation time was calculated incorrectly.'
|
||||||
self.assertEqual(preparation_time_in_minutes(layers), time, msg=failure_msg)
|
self.assertEqual(preparation_time_in_minutes(
|
||||||
|
layers), time, msg=failure_msg)
|
||||||
|
|
||||||
@pytest.mark.task(taskno=4)
|
|
||||||
def test_elapsed_time_in_minutes(self):
|
def test_elapsed_time_in_minutes(self):
|
||||||
layer_data = (1, 2, 5, 8, 11, 15)
|
layer_data = (1, 2, 5, 8, 11, 15)
|
||||||
time_data = (3, 7, 8, 4, 15, 20)
|
time_data = (3, 7, 8, 4, 15, 20)
|
||||||
result_data = [prep * 2 + elapsed for prep, elapsed in zip(layer_data, time_data)]
|
result_data = [prep * 2 + elapsed for prep,
|
||||||
|
elapsed in zip(layer_data, time_data)]
|
||||||
|
|
||||||
for variant, (layers, time, total_time) in enumerate(zip(layer_data, time_data, result_data), start=1):
|
for variant, (layers, time, total_time) in enumerate(zip(layer_data, time_data, result_data), start=1):
|
||||||
with self.subTest(f'variation #{variant}', layers=layers, time=time, total_time=total_time):
|
with self.subTest(f'variation #{variant}', layers=layers, time=time, total_time=total_time):
|
||||||
failure_msg = f'Expected {time} minutes elapsed, but the timing was calculated incorrectly.'
|
failure_msg = f'Expected {time} minutes elapsed, but the timing was calculated incorrectly.'
|
||||||
self.assertEqual(elapsed_time_in_minutes(layers, time), total_time, msg=failure_msg)
|
self.assertEqual(elapsed_time_in_minutes(
|
||||||
|
layers, time), total_time, msg=failure_msg)
|
||||||
|
|
||||||
@pytest.mark.task(taskno=5)
|
|
||||||
def test_docstrings_were_written(self):
|
def test_docstrings_were_written(self):
|
||||||
functions = [bake_time_remaining, preparation_time_in_minutes, elapsed_time_in_minutes]
|
functions = [bake_time_remaining,
|
||||||
|
preparation_time_in_minutes, elapsed_time_in_minutes]
|
||||||
|
|
||||||
for variant, function in enumerate(functions, start=1):
|
for variant, function in enumerate(functions, start=1):
|
||||||
with self.subTest(f'variation #{variant}', function=function):
|
with self.subTest(f'variation #{variant}', function=function):
|
||||||
|
|
Loading…
Reference in New Issue