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

Check the Tests Too

You can ask for tests too: attach the program and ask for tests of a function. An AI writes them in seconds, and it works out what each test expects the way it writes code: usually right, sometimes wrong, and just as sure either way. A test that expects the wrong value is worse than no test. It prints False for a function that is right, and if you change the function until the test passes, you've put the test's mistake into your program.

Someone asked for tests of walk_price() and got the four in the editor, each with a comment saying what it checks. One of them prints False. That tells you only that the function and that test disagree, not which of them is wrong. To find out, work the case out yourself with Mia's rule: £6 for every started half hour.

Then look at what the tests leave out. A boundary has two sides: 30 minutes is one half hour, and at 31 minutes the second has started. The answer tests one side only.

Instructions

  1. 1

    Run the tests. For the one that prints False, work out by hand what the walk should cost, and fix what's wrong: the function or the test. Run the program again: it prints True four times.

  2. 2

    Add a test in the same way for a walk of 31 minutes, with the price you work out. Run the program: it prints True five times.

Back

3/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

Try it yourself

Do this exercise right here in your browser. No account needed.