Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

Summary

In this lesson, you learned that:

  • A test is an example that runs: print(walk_price(45) == 12) prints True when the function returns what you expected and False when they disagree. Test an ordinary case and both sides of each boundary.
  • Written before the code, tests tell the AI exactly what you want, and they check its answer as soon as you paste it in. Choose them so that only your rule fits them.
  • Tests from an AI need checking too. When a test prints False, work the case out by hand before you change the function or the test.
  • Answers often write tests with assert, which stops the program with an AssertionError at the first test that fails. The text after the comma says which test it was.

Practice it with week_total(), which adds up the prices of a week's walks, here without the discount, to keep the tests short. This time, ask for the tests. Asked only for tests of it, answers wrote them with unittest, a Python library you haven't learned, or with assert, so say how you want them written. And check them before you trust them.

Next comes When It Makes Things Up: what to do when an answer uses something that doesn't exist, and how to check what it says about Python.

Instructions

  1. 1

    Attach script.py and ask for three tests of week_total(), written as you write tests: print() of a comparison with ==. Then send it.

  2. 2

    Before you trust the tests, work out each expected total by hand, and fix any that is wrong. Then paste the tests at the end of the program and run it: under Total: 36, it prints True three times.

Back

7/7

  1. 1. An Example That Runs
  2. 2. Tests First, Then the Code
  3. 3. Check the Tests Too
  4. 4. Quiz: The Function or the Test?
  5. 5. Tests with assert
  6. 6. Quiz: Which Line Is Wrong?
  7. 7. Summary
Next

Start programming for free

By signing up, you agree to the Terms of Service and Privacy Policy.

Or sign up with: