Testing the functionality of the class

Now that we have created a crop class with all of the (currently) desired functionality it is time to put it through its paces and make sure that it actually works as expected. To do this we are going to add two functions to our module:

  • Automatic grow
  • Manual grow

Automatic grow

The auto_grow() function will provide a way to test the crop over a long period of time. We will provide it will the number of days we wish to grow the crop over as a parameter and it will then randomly generate the amount of light and water for each day. Once it has these values it will call the grow() method of our crop instance. It will repeat this process for number of days we have provided.

The video below demonstrates how to add the auto_grow() function to the module:


Task 5a

Use the above video to help you add auto_grow() function to the module.


Manual Grow

The manual_grow() function will allow us to provide specific values to the crop so that we can test that it accepts the appropriate range of values and performs in an expected way when it receives a particular pairing of light and water. It will only grow the crop over a single day.

The video below demonstrates how to add the manual_grow() function to the module:


Task 5b

Use the above video to help you add manual_grow() function to the module.


Management menu

Currently it is quite a painful experience to test the program - we have to continually add calls to our main program to perform the required tests. To make testing easier in the future we are going to add a management menu to our module that will enable us to easily access the different test functions and see the result of calling these functions on a particular crop instance.

The structure chart below represents the additions that we will make:

Management Structure Chart

The video below demonstrates how to add the management menu to the module:


Task 6

Use the above video to help you add the management menu to the module.


Crop types

Rather than having a generic crop type wouldn't it be better if we could have particular types of crop, like wheat and potatoes? In the next section we will look at how to build on our existing work to add these specific types of crop.