How to write a test driver?

I'm supposed to create a test driver for this program but I have no idea what exactly that entails. I've looked at the test driver tutorial that pops up on google but I don't understand what it's telling me. I'm fairly certain that this code works and would assume that drivers are for larger and more complex programs but I don't know what I need to do to make a driver. I'm supposed to loop the data so that I enter test data for the below. Would I create constant values that simply loop through the functions every time I build this or what? Any help is appreciated.


low income, < 20 minutes
low income, > 20 minutes
high income, < 20 minutes
high income, > 20 minutes.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <iostream>
#include <iomanip>

using namespace std;
const double income = 25000;


double friday(double, double);
bool incomecheck();

int main()
{
double minutes,income,hRate,total;

cout << "Total minutes of consulting time: ";
cin >> minutes;
cout << "Enter the standard hourly rate charged: ";
cin >> hRate;
cout << "Enter the income of customer: ";
cin >> income;


cout << "The total bill for this customer is $" << friday(minutes, hRate)  << ".";

return 0;
}

double friday(double minutes, double hrate)
{
    double total = 0;
    if (income <= 25000)
    {
        if (minutes <= 30)
		total = 0;
        else
        total = hrate * 0.40 * (minutes/60);
    }
    else if (income > 25000)
    {
        if (minutes <= 20)
		total = 0;
        else
		total = hrate * 0.7 * (minutes/60);
}

return total;
}


You might take a look at http://www.slideshare.net/JonJagger/larry-and-jen-do-roman-numerals-in-c to get an idea or two.
The first step is normally to take paper and pen or maybe a spreadsheet and create some test data. That means the input and the expected output. Then you run the code and check that the actual output is == expected output.

For example:
1
2
3
4
5
6
7
8
9
10
11
12
void TestLowIncomeAndShortTime()
{
   double minutes = 12;
   double income = 1899;
   double expected; // set to correct value
   double result; // get the result from the function

  if (expected == result)
     // handle success
  else
    // handle failure
}


Create functions like this for all cases and run them in main.
If you need to make any changes in your calculation it's easy to run the test with the same test data again.

EDIT:

Just found this interesting article:
http://www.codeproject.com/Articles/17649/The-Psychology-of-Testing
Last edited on
Topic archived. No new replies allowed.