English subtitles

← Hello Assert - Software Debugging

Get Embed Code
4 Languages

Showing Revision 3 created 05/25/2016 by Udacity Robot.

  1. The error is due to the variable tag being set. How do we know that this variable is being set?
  2. Let me introduce you to one of the most powerful
  3. debugging tools ever invented which is the assert statement.
  4. The statement assert followed by a condition, evaluates the condition and aborts the execution
  5. raising an exception if condition is false--that is if the condition holds, we proceed as usual.
  6. If the condition does not hold, we throw an exception.
  7. With the statement, we can now go and check the value of tag all through the loop.
  8. So again we say, in our hypothesis tag is being set and we use assert to check that.
  9. With this statement assert not tag should tag ever be set will we immediately get an exception
  10. and again we can check this with foo enclosed in double quotes.
  11. So in order to confirm the hypothesis, we would expect an assert exception.
  12. What is the output really? Let's make this a quiz.
  13. Now that we change the program to include assert not tag, what's going to happen?
  14. Does the program raise an exception or is the case that the output is still foo as before.
  15. The assertion is not violated and tag is not set during the entire loop. Over to you.