English subtitles

← Solution Step I - Intro to Computer Science

Get Embed Code
3 Languages

Showing Revision 5 created 05/24/2016 by Udacity Robot.

  1. So I'm starting with the code we had before that works correctly, except for,
  2. with this assumption that all months have 30 days. So the first step is going to
  3. be to define the stub procedure daysInMonth that gives the number of days in a
  4. month. But, for our stub procedure, we're just going to always return 30. And
  5. I'm going to modify nextDay to call daysInMonth. That's pretty simple, but I
  6. should start testing, and I'm going to write some code to do testing. We don't
  7. want to have to keep typing the same test cases in the shell. We want to write
  8. some code for testing. For the problem that's provided, there were some provided
  9. test cases. I'm going to write my own starting now. And I'm going to make sure
  10. that these test cases, we don't expect the correct results yet because I'm
  11. testing with 30-day months. So, I'm going to test two dates that are the same.
  12. It's a boundary case, it's a useful one to test. I'm going to test from one day
  13. to the next, that should give us one day. And these are test cases for days
  14. between dates. I should really be writing some test cases for next day. The
  15. reason for that is that, if they fail, well, it's going to be more easy to
  16. understand what went wrong, rather than just writing all of my test cases for
  17. days between days. So let's try some nextDay test cases. Got one where the day
  18. advances. Let's get one where the month advances. And I will use a month that
  19. has 30 days. So it will be correct in 30 months, but will still be correct once
  20. we fix this. And I'll use advancing the year. A few test cases, probably we
  21. should have more. But let's try that. We should save, and let's run this, and
  22. we'll run our test. And, something failed. Not too surprising, this happens.
  23. Let's see what failed. And the failure is type error that I'm calling
  24. daysInMonth Not passing in the right number of parameters. In fact, I passed in
  25. 0. I should have passed in both the year and the month. So this is one of the
  26. reasons for writing things in stubs, we can find these kinds of errors quickly.
  27. So let's try again, and now we're test passed, and our test case is using
  28. restrictions. I'm going to be a little more careful and print something out when
  29. the test finishes, because it's a little bit dangerous to have nothing to tell
  30. when the test finished. Maybe we didn't get any output for some other reason.