# Developing Test Cases

Page 1 of 1

## 4 Replies - 524 Views - Last Post: 07 November 2017 - 10:26 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=407455&amp;s=474a545d48725e95fbb9cf972459782b&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 KING iMm0rt4lxM

Reputation: 1
• Posts: 44
• Joined: 08-November 15

# Developing Test Cases

Posted 07 November 2017 - 12:52 PM

I have been trying to look into this, all I find are different types of test cases.

The most I have understood is that if and switch statements are used to test code.

But I think my professor means something else. Note: The other I know of is assert.

"Develop test code that tests your implementation (edge cases should be covered).

Any help is much appreciated.

** PROBLEM **
Provide an implementation of the egg carton class described below. Develop test code that tests your implementation (edge cases should be covered). You should have three separate source code files similar to exercise 1.
```+----------------------------------------------------------------+

|                                                                                  |

|                           EggCarton                                    |

|                                                                                  |

+----------------------------------------------------------------+

|                                                                                  |

| data fields:                                                              |

| - brownEggs : int                                                    |

| - whiteEggs : int                                                     |

|                                                                                  |

+----------------------------------------------------------------+

|                                                                                   |

| member functions:                                                  |

| + EggCarton() //set initial values to 0 and 0         |

| + EggCarton(brownEggs : int, whiteEggs : int)   |

|  // set initial values to 0 and 0 if the total number |

|  // of eggs is larger 12                                            |

| + addBrownEggs(n : int) : bool                             |

| + addWhiteEggs(n : int) : bool                              |

| + getTotalEggs() : int                                              |

|                                                                                   |

+----------------------------------------------------------------+
```

Figure 1

The class structure for the EggCarton class is shown in Figure 1. Instances of this class represent egg cartons that can hold up to 12 eggs. The class provides functions to add white and brown eggs. All of the functions that modify the number of eggs in the carton return false if the operation cannot be done exactly as requested. For example, if there are 3 white eggs and 0 brown eggs, then addBrownEggs(10) returns false and the number of white eggs remains at 3 and brown eggs at 0. There is a member function called getTotalEggs, which returns the total number of white and brown eggs together. For example, if the carton has 1 brown and 2 white eggs, then getTotalEggs returns 3.

(Appropriate function comments are expected for all functions.)

```#ifndef EGGCARTON_H
#define EGGCARTON_H

#include <iostream>
using namespace std;

class EggCarton
{
private:
int brownEggs;
int whiteEggs;
public:
EggCarton();
EggCarton(int, int);
int getTotalEggs();
};

#endif

```

```#include <iostream>
#include "EggCarton.h"

using namespace std;

EggCarton::EggCarton()
{
brownEggs = 0;
whiteEggs = 0;
}

EggCarton::EggCarton(int brownEggs, int whiteEggs)
{
if (brownEggs + whiteEggs > 12)
{
brownEggs = 0;
whiteEggs = 0;
}
}

{

}

{

}

int EggCarton::getTotalEggs()
{
cout << brownEggs + whiteEggs;
}

```

```#include <iostream>
#include "EggCarton.h"
#include "EggCarton.cpp"

using namespace std;

int main()
{
EggCarton egg;

//egg.getTotalEggs();

return 0;
}

```

Is This A Good Question/Topic? 0

## Replies To: Developing Test Cases

### #2 modi123_1

• Suitor #2

Reputation: 14238
• Posts: 57,114
• Joined: 12-June 08

## Re: Developing Test Cases

Posted 07 November 2017 - 12:54 PM

Quote

But I think my professor means something else.

### #3 KING iMm0rt4lxM

Reputation: 1
• Posts: 44
• Joined: 08-November 15

## Re: Developing Test Cases

Posted 07 November 2017 - 01:02 PM

My question is what kind of test case is primarily used for C++/What kind of test case should be used for this problem? Or if I can be directed to any information regarding test cases for C++ that I can read on

### #4 r.stiltskin

• D.I.C Lover

Reputation: 2032
• Posts: 5,435
• Joined: 27-December 05

## Re: Developing Test Cases

Posted 07 November 2017 - 01:23 PM

It has nothing to do with if or switch or assert statements. You are to write a main function that tests your implementation of the class by instantiating class members and calling the member functions to verify that they "do the right thing" according to the stated specifications.

Testing "edge cases" means testing function calls that challenge the limiting parameters of your class -- in this case the capacity of the eggcarton. So for example -- what happens if the carton is empty before the function call to add eggs, what happens when the carton is already full before the function call, what happens if complying with the function call exactly fills the carton, what happens if performing the function call would "overfill" the carton, etc. You have to devise the main function (aka test driver) to test as many of these possibilities as you can think of, based on the parameters that were stated in your assignment.

### #5 ndc85430

• I think you'll find it's "Dr"

Reputation: 869
• Posts: 3,491
• Joined: 13-June 14

## Re: Developing Test Cases

Posted 07 November 2017 - 10:26 PM

One could also interpret the text to mean writing unit tests for the behaviours of the class. You'd use some third party library for writing tests, like Catch, Boost Test or Google Test. Unit testing and other forms of automated testing are what we do in professional software development.

Note also that what r.stiltskin says isn't really specific to C++; testing is a general concept.

This post has been edited by ndc85430: 07 November 2017 - 10:29 PM