Git Product home page Git Product logo

times-tests's Introduction

In this exercise, you will be given a few lines of code that perform a certain task (that you will have to understand) and then write an automated test that checks whether that task is performed correctly.

Step 0

Make sure you have read the note chapters on Testing basics, The Fields of Saskatchewan and Test frameworks.

If you haven't already, fork this repository and clone it on your computer.

Step 1: Understanding the existing code

  • Spend some time reading the code, try to run it and see whether you understand what's going on.
  • Have you seen datetime before?
  • Play using your favourite tool (notebook, terminal, scripts) with the functions and objects used in times.py.

Step 2: Writing a unit test

  • Create a new file called test_times.py in the same directory where times.py is.
  • Make the overlap_time function accessible to that file. (Hint: You need to import the file).
  • Move the content from the if __name__ ... block from times.py to a function called test_given_input into test_times.py and fill the gaps for result and expected. (For now, you can copy the output of the program as the expected value)
def test_given_input():
    ... 
    result = ... 
    expected = ...
    assert result == expected

Step 3: Running the tests

  • run pytest on that directory and see whether the test is picked up by pytest and whether it passes. If the test doesn't pass, see if you can find what is going wrong.

Step 4: Push to GitHub

  • When you are happy with your solution (or want some feedback!):
    • Push your new code to your own fork.
    • On GitHub, open a pull request from your fork to the original repository.
    • In the description, include the text "Answers UCL-MPHY0021-21-22/RSE-Classwork#16". This will link your PR to this issue.
    • On the PR text, comment on what you found difficult or interesting, or something you learned.
  • Continue with the remaining steps (7. - 9.) on Classwork issue #16

times-tests's People

Contributors

sedaradoykova avatar alessandrofelder avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.