Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a unit test for addInventory(). Call redSweater.addInventory() with parame

ID: 3668696 • Letter: W

Question

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:

Note: UNIT TEST FAILED is preceded by 3 spaces.

#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

#%#%#@%@# ANSWER HERE @#%#@%@
cout << "Tests complete." << endl;

return 0;
}

Explanation / Answer

#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;

testAddInventory(redSweater,sweaterShipment);

cout << "Tests complete." << endl;

return 0;
}

void testAddInventory(InventoryTag redSweater,int sweaterShipment)

{

redsweater.addInventory(sweaterShipment);

int quantity=redsweater.getQuantityRemaining();

if(quantity != 25)

cout<<" UnNIT TEST FAILED:addInventory()";

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote