Q:

Write a unit test for addinventory(). call redsweater.addinventory() with parameter sweatershipment. print the shown error if the subsequent quantity is incorrect. sample output for failed unit test given initial quantity is 10 and sweatershipment is 50: beginning tests. unit test failed: addinventory() tests complete. note: unit test failed is preceded by 3 spaces.

Accepted Solution

A:
#include <iostream> using namespace std; class InventoryTag { public: InventoryTag(); int getQuantityRemaining() const; void addInventory(int numItems); private: int quantityRemaining; }; InventoryTag::InventoryTag() { quantityRemaining = 0; } int InventoryTag::getQuantityRemaining() const { return quantityRemaining; } void InventoryTag::addInventory(int numItems) { if (numItems > 10) { quantityRemaining = quantityRemaining + numItems; } } int main() { InventoryTag redSweater; int sweaterShipment = 0; int sweaterInventoryBefore = 0; sweaterInventoryBefore = redSweater.getQuantityRemaining(); sweaterShipment = 25; cout << "Beginning tests." << endl; // FIXME add unit test for addInventory /* Your solution goes here */ cout << "Tests complete." << endl; return 0; }