Suppose that you’d like to implement a cookie jar in which to store cookies. In a file called
Structure your
Either before or after you implement 0, four or more functions that collectively test your implementation of Jar thoroughly, each of whose names should begin with 2 so that you can execute your tests with:Note that it’s not as easy to test instance methods as it is to test functions alone, since instance methods sometimes manipulate the same “state” (i.e., instance variables). To test one method (e.g., 2), then, you might need to call another method first (e.g., 8). But the method you call first might itself not be correct!And so programmers sometimes mock (i.e., simulate) state when testing methods, as with Python’s own mock object library, so that you can call just the one method but modify the underlying state first, without calling the other method to do so. For simplicity, though, no need to mock any state. Implement your tests as you normally would! Hints
DemoYou’re welcome, but not required, to implement a 5 function, so this is all we can demo!Source: Sesame Street Before You BeginLog into code.cs50.io, click on your terminal window, and execute 6 by itself. You should find that your terminal window’s prompt resembles the below:Next execute to make a folder called 7 in your codespace.Then execute to change directories into that folder. You should now see your terminal prompt as 8. You can now executeto make a file called to create a file called 0 where you can write tests for your program.How to TestHere’s how to test your code manually:
You can execute the below to check your code using
Green smilies mean your program has passed a test! Red frownies will indicate your program output something unexpected. Visit the URL that |