You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 25, 2024. It is now read-only.
In this exercise, you will be given a few lines of code that compute the overlap between two time ranges and a unit test that checks that this overlap is computed correctly.
Your task will be to write a further unit test that checks whether the overlap computation is performed correctly on a new set of two time ranges.
Setup
Fork this repository to your personal GitHub account using the Fork button on the top right of this page.
Clone your forked copy of this repository to your laptop git clone https://github.com/<your github username here>/ipls-workshop.git.
Inside your local copy of the repository, checkout the exercises branch: git checkout exercises
Execute ls in the repository - you should see 2 files: times.py and test_times.py.
Exercise 1
Unit tests in Python
As we've discussed in class, unit tests are a way to check that small, modular parts of your code behave as intended.
The de-facto standard framework for unit tests in Python is pytest. pytest automatically detects files that start with test_ and functions therein that start with test_ and runs those.
Comparisons can be done using the assert statement. The typical structure of a pytest unit test is as follows:
Spend some time reading both files, and see whether you understand what's going on.
Do you think the compute_overlap function of overlap.py computes the time overlaps correctly?
Do you understand the code in test_times.py?
Running a test
The test_times.py file contains a test for compute_overlap. Run the test by typing pytest and then hitting Enter on your command line in the local repository. Does the test pass?
Adding another test
Now it's your turn to create a test.
In test_times.py, add an additional unit test named test_workshop_morning_times (there is already a skeleton implementation there, you need to fill in the test function body). You should
create a time range that goes from 2021-04-30 10:00:00 - 2021-04-30 13:00:00 (the timings of this morning's git lesson)
create a time range that starts at 10:05 and ends at 12:55 and has two 10-minute breaks, also on 30 April 2021.
include a line that checks that the time overlap between the first and the second time range is what you expect
check that the test passes by running pytest.
Commit your changes and push
Once you've written this new test, commit it to your repository with a meaningful commit message that also links to this issue.
Well done, you've gotten to the end of the first exercise 🎉
If you've finished this exercise with time to spare, feel free to explore an additional exercise, that involves writing a test for no overlap test between time ranges: #6 .
The text was updated successfully, but these errors were encountered:
sanchezy
pushed a commit
to sanchezy/ipls-workshop
that referenced
this issue
Apr 30, 2021
In this exercise, you will be given a few lines of code that compute the overlap between two time ranges and a unit test that checks that this overlap is computed correctly.
Your task will be to write a further unit test that checks whether the overlap computation is performed correctly on a new set of two time ranges.
Setup
Fork
button on the top right of this page.git clone https://github.com/<your github username here>/ipls-workshop.git
.exercises
branch:git checkout exercises
ls
in the repository - you should see 2 files:times.py
andtest_times.py
.Exercise 1
Unit tests in Python
As we've discussed in class, unit tests are a way to check that small, modular parts of your code behave as intended.
The de-facto standard framework for unit tests in Python is
pytest
.pytest
automatically detects files that start withtest_
and functions therein that start withtest_
and runs those.Comparisons can be done using the
assert
statement. The typical structure of apytest
unit test is as follows:Further information about
pytest
can be found in its documentation.Understanding the code
compute_overlap
function ofoverlap.py
computes the time overlaps correctly?test_times.py
?Running a test
test_times.py
file contains a test forcompute_overlap
. Run the test by typingpytest
and then hittingEnter
on your command line in the local repository. Does the test pass?Adding another test
Now it's your turn to create a test.
test_times.py
, add an additional unit test namedtest_workshop_morning_times
(there is already a skeleton implementation there, you need to fill in the test function body). You shouldpytest
.Commit your changes and push
Once you've written this new test, commit it to your repository with a meaningful commit message that also links to this issue.
and push it to your fork.
Well done, you've gotten to the end of the first exercise 🎉
If you've finished this exercise with time to spare, feel free to explore an additional exercise, that involves writing a test for no overlap test between time ranges: #6 .
The text was updated successfully, but these errors were encountered: