English subtitles

← Queue Solution - Software Testing

Get Embed Code
1 Language

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

  1. So let's go ahead and take a look at my
  2. test code for the Q class. So it doesn't actually take
  3. a whole lot to get full coverage on the Q
  4. class, and that's, this is a good point, we haven't tested
  5. the Q a huge amount here. It shows a little
  6. bit of the problems with S, especially just normal statement coverage,
  7. so let's go ahead and get started. So we start
  8. off with just a Q of size 2, we assert that
  9. it does actually get made and then we call check
  10. rep, we're going to be calling check rep after every single test
  11. that we do, just as a further test. And really, any
  12. of the test that we do that call the internals of
  13. the q class should probably be in check wrap, because
  14. we don't necessarily want our test code to have to worry
  15. about the internals of it, we want the internal testing to
  16. be taken care of by the class itself. Preferably all though
  17. you dont always get that. But after that we check
  18. the que it starts off as empty. Which it should
  19. be. And that the que is not full. Which it
  20. also should not be. And then we try the que from
  21. the empty que. And this should return none according to
  22. specification. Then we're going to que ten in to the
  23. que. And we should get a true. Result back and
  24. enqueue returns true if you successfully enqueue something, false, if it
  25. doesn't correctly enqueue for some reason or another. Then, we enqueue
  26. 20 and again, it should be true. Now, we check that
  27. it's empty again. It should not be empty and we check
  28. that it's full. Since it's a queue of size two, the
  29. full method should return true. And that's what we asset here.
  30. Now, we further try to enqueue thirty, but since the queue
  31. should already be full, this should return false. And we go
  32. ahead and assert that. Now we try to dequeue from that, and
  33. we should get 10 out since this is a q. It's a
  34. first in, first out data structure. Then we try to dequeue again,
  35. and We should get 20 out. And, again, after each of these,
  36. we call tech rep. If I go ahead and submit this, we
  37. see that I got it right. Okay. Os, that's one way you
  38. could have done it. There are a number of different possibilities here.
  39. And like I said, it doesn't really take a huge amount of
  40. code to get full coverage of the queue class. If fact, what I
  41. did here is probably a bit much. But again. It doesn't necessarily tell us
  42. a whole lot about whether the Q class is, in fact, correct in any
  43. meaningful way. So, great. I hope you got it right and had fun with
  44. it. I hope it also wasn't too challenging. But I hope it made you think.