4 Replies - 317 Views - Last Post: 07 November 2017 - 10:26 PM Rate Topic: -----

#1 KING iMm0rt4lxM  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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);
    bool addBrownEggs(int);
    bool addWhiteEggs(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;
    }
}

bool EggCarton::addBrownEggs(int n)
{
    
}

bool EggCarton::addWhiteEggs(int n)
{

}

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



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

using namespace std;

int main()
{
    EggCarton egg;
    
    //egg.addBrownEggs(10);
    
    //egg.getTotalEggs();

    
    
    
    return 0;
}



Is This A Good Question/Topic? 0
  • +

Replies To: Developing Test Cases

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 13484
  • View blog
  • Posts: 53,826
  • Joined: 12-June 08

Re: Developing Test Cases

Posted 07 November 2017 - 12:54 PM

What is your question?

Quote

But I think my professor means something else.

Easy solution - ask him/her.
Was This Post Helpful? 0
  • +
  • -

#3 KING iMm0rt4lxM  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • 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
Was This Post Helpful? 0
  • +
  • -

#4 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2009
  • View blog
  • Posts: 5,384
  • 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.
Was This Post Helpful? 2
  • +
  • -

#5 ndc85430  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 587
  • View blog
  • Posts: 2,468
  • 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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1