Hello. In this lecture, we're going to start talking about Cucumber and Gherkin, and how we can use it to map user stories that we've written and requirements into test cases using the Gherkin language. In order to do this, we're going to introduce a simple system of a Microwave. Partly because it's a system that most people are familiar with, and partly because we can make a very simple microwave that we can demonstrate how Cucumber and Gherkin work. So, our microwave is going to consist of two main components. First, we have a mode controller that determines whether or not the Microwave is cooking. So, in our microwave, we have three modes. We have Setup mode, where the user can type in the time to cook and when they hit the "start button", the system goes into the Cooking mode as long as the door is closed. If the door is open, then nothing happens. So, we're in the Cooking mode and we're cooking and then the user opens the door. Then we go into something called the Suspended mode. And the Suspended mode, basically sits with the time fixed until the user hits the "cancel button" or closes the door and hits the "start button". So, those are our three modes. When we reach 0, then we go back into the Setup mode or if we're in the Cooking mode and the user hits the "cancel button" then we go back into the Setup mode. And the way this is going to work is that we have a display controller that allows the user to type in the time to cook and also displays the current time to cook to user. Other things that we can do is we can set a preset which is a predefined time to cook and power level and we can hit the "start" or "clear" button. So. these controllers run periodically, so every 50 milliseconds the state is updated. This is normally how embedded systems work. So, we pull the state of the buttons and then we change the display. And we have some key safety requirements: we only cook with the door closed, we don't want to irradiate our clients, and we never cook forever. So eventually, the microwave will stop cooking. There are some other requirements related to the presets that we'll get to. So, let's think of some user stories. What might a user want to do with their microwave? The first thing is cook, so they place some food in the microwave, they close the door, they select the cooking time, hit "start" and cook the food. Another thing they might want to do is be able to check on the food. So, they open the door, they check on the food to see if it's cooked through, maybe they flip it over and then they close the door, and they want to be able to restart the microwave and cook from that point. And, maybe they want presets because the users make popcorn every night. Maybe they like watching movies, so this is another thing they might want to do. Finally, they might want to be able to set the power level to cook food more evenly. So, each of these tasks, the microwave software that we create should be able to do. So, now I'm going to walk through what the code looks like in Java to do this. Okay. So, here we have the actual code for the Microwave. And, this is just a class in Java and the microwave consists of a ModeController, and a DisplayController, and a set of presets and it keeps track of the current power level. Furthermore, it has a couple of variables that keep track of whether the door is open and whether it's cooking. So, let's look at it further. Basically, we're going to construct a Microwave which is kind of a shell just by passing in a ModeController and a DisplayController. And, then we have a bunch of functions that represent actions being performed in the microwave. So you can press the digits, you can press "start", you can press "clear", and then you can also press a "preset", and the presets have a range so you have to stay within the range. You can set the door open, set the power level, you can get the power level, and check whether the door is open. And finally, you can do a tick. So a tick is one time tick, so one of these cycles of this periodic loop, and what it's going to do is it's going to run the DisplayController, it's going to run the ModeController, and then it's going to determine whether or not the microwave is cooking. Oh! And there's a few other things that we can do. We can ask what the tick rate is, we can get the current mode, we can get the display digits. And this is how the actual physical hardware is going to interact with the microwave. So, let's dig a little bit further into the ModeController and the DisplayController. So, the ModeController keeps track of whether the "start" has been pressed or the "clear button" has been pressed in the current computational cycle. And then most of the behavior is in this tick() method where it describes how that state machine that we showed in the slides, how we change state. So, if we are in a state where there's no time remaining to cook, then we go into the Setup mode. If the door is open, and the mode previously was Cooking, we go into the Suspended mode and so on. So, this describes the code necessary to implement that state machine. Now we can look at the DisplayController. And the DisplayController is going to describe how the digits decrement on the display. And this seems like a very simple thing to do, and it's not too complicated, but one thing that makes it interesting is that the user can input times that don't necessarily correspond to how we normally tell time. So, the user can input "9", "9" to cook for 99 seconds. Even though this is the same as 1 minute and 59 seconds. So, what we want, if the user types in "9", "9", "9" is to cook for 10 minutes and 59 seconds. So, once we roll over the "9", "9" we want it to behave like a regular clock, where the number of seconds just goes from 59 on down to 0. So, we have to define where the digits roll over. The location, so we have a four digit display. The tens of minutes, the minutes, the tens of seconds, and the seconds. And then we have an array for digit pressed so we can press 0 through 9 and so on. So again, most of the functionality, we can press the digit, we can clear the digits pressed, we can clear any key pressed, we can determine the time to cook by multiplying the values of the digits appropriately. And then finally, we can tick. And so, what we do when we tick, if we're in Setup mode and the user's pressed a button is we advance all the digits one position to the left. When we're in Suspended, we never change the display, and when we're cooking, we decrement the display. And this may cause rollover. So, there is some code in here that deals with that rollover case. So essentially that's all the functionality of our Microwave. We have a very simple class representing a preset. And that's just to record for the preset buttons, the amount of time to cook and the power level to cook.