Tip:
Highlight text to annotate it
X
Let's start this solution video off by looking through all of the incorrect
implementations of the queue, and then we'll see how we actually caught all of the bugs.
The first queue has an error where you enqueue and it only stores integers
up to 2^16 and that's roughly 32,000.
When you enqueue things it's just silently wraps it back around to zero if you go over that.
The second queue silently fails to create queues with more than 15 elements.
So in the initializer, if the max size is greater than 15, then it just sets it to 15
and doesn't tell you about it at all.
The third queue is a little tricky--it implements the empty method by trying to dequeue an element
and checking if the dequeue is none.
If it is, then it returns true. If it isn't, then it returns false.
And because the empty method changes the state of the queue when it shouldn't,
this is going to cause buggy behavior.
The fourth queue has a bug in the dequeue method.
When you try to dequeue from an empty queue it returns false
where it should, according to the specification, return' none.
The final queue just holds one less element than you tell it to hold.
So it's just decrement size max when you pass it in by one and then stores that many elements
instead of how many you told it to.
Now let's try to catch all of these bugs.
The first queue can be caught by just trying to enqueue a value greater than 2^16
and then dequeuing it and check that the value is correct.
The second queue, you try to enqueue more than 15 elements--
remember that was the one that only stored 15 without telling you.
As soon as you go past 15, this assertion should fail. The third queue is a little bit trickier.
We create a queue with two elements and we try to enqueue 10 which should succeed fine,
and we check that, then we assert that the queue is not empty which it shouldn't be,
but remember that this empty function checks that it's empty by trying to dequeue,
which removes 10 from the queue.
Now when we try to dequeue a second time, now the queue is empty.
It's not going to return 10, it's going to return none. This assertion is going to fail.
The fourth queue returns false instead of none when you try to dequeue from an empty queue.
To test this, we instantiate a 2-element queue, and we try to immediately dequeue
from that empty queue, and we should get none, which is what we're checking.
but instead we get false, so this assertion will fail.
Now the final queue just holds one last item than intended, so we created 2-element queue,
and we try to enqueue two elements, and this will fail for the second since this queue will only hold
one element not two, so this second attempt will fail.
Okay, I hope you enjoyed catching all those bugs.
This is something that comes up fairly frequently when you have to do blackbox testing
when you don't actually know the code that you're running against, you don't have access to it.
We'll talk a bit more about that in Unit 2 and I hope to see you there. Thanks!