/* Programmer: Jennifer Leopold Date: November 7, 2015
File: hw9_functs.cpp
Purpose: Function definitions used for testing the Animal,
Road, and Car class functions.
*/
#include <iostream>
#include "hw9_functs.h"
using namespace std;
void testAnimal()
{
cout << "\nTesting Animal functions...\n";
Animal possum; // default constructor
Animal armadillo(3, "armadillo", // parameterized constructor
1, 88);
// overloaded operator for <<
cout << "Animal created with default constructor is:\n"
<< possum << endl;
cout << "Animal created with parameterized constructor is:\n"
<< armadillo << endl;
// accessor functions for weigth and width
cout << "Armadillo's weight = " << armadillo.getWeight()
<< " and width = " << armadillo.getWidth() << endl;
// chooseToRun function
cout << "\nIf stupidity level was " << STUPIDITY_LEVEL_TEST
<< ":\n";
cout << "The armadillo would "
<< (armadillo.chooseToRun(STUPIDITY_LEVEL_TEST)?
"" : "not ")
<< "choose to run.\n";
cout << "The possum would "
<< (possum.chooseToRun(STUPIDITY_LEVEL_TEST)?
"" : "not ")
<< "choose to run.\n\n";
return;
}
void testCar()
{
cout << "\nTesting Car functions...\n";
Car c; // default constructor
bool triedToExceedLimit;
float oldValue;
// overloaded operator for <<
cout << "Car created with default constructor is:\n"
<< c << endl;
// incrBattery function and battery accessor
triedToExceedLimit = false;
while (!triedToExceedLimit)
{
oldValue = c.getBattery();
c.incrBattery(BATTERY_INCR);
cout << "Car's battery after incrementing by "
<< BATTERY_INCR << " is " << c.getBattery() << endl;
if (c.getBattery() == oldValue)
triedToExceedLimit = true;
}
cout << endl;
// incrDamage function and damage accessor
triedToExceedLimit = false;
while (!triedToExceedLimit)
{
oldValue = c.getDamage();
c.incrDamage(DAMAGE_INCR);
cout << "Car's damage after incrementing by "
<< DAMAGE_INCR << " is " << c.getDamage() << endl;
if (c.getDamage() == oldValue)
triedToExceedLimit = true;
}
cout << endl;
// Note: enterRoad function should be tested after Road
// functions tested
return;
}
void testRoad()
{
cout << "\nTesting Road functions...\n";
Road r; // default constructor
// overloaded operator for <<
cout << "Road created with default constructor is:\n"
<< r << endl;
// width accessor
cout << "Width of road is " << r.getWidth() << "\n";
// overloaded operator for << and placeCar function
r.placeCar(4, 1, 'X');
cout << "\nRoad after placing car (marked with X)"
<< " and having width 4 in position 1:\n"
<< r << endl;
r.placeCar(3, 5, 'Z');
cout << "\nRoad after placing car (marked with Z)"
<< " and having width 3 in position 5:\n"
<< r << endl;
return;
}
void testCarWithRoad()
{
cout << "\nTesting Car with Road functions...\n";
Road r;
Car c;
cout << "Created the following Car:\n"
<< c << endl;
cout << "Created the following Road:\n"
<< r << endl;
for (int i = 0; i <= r.getWidth() - c.getWidth(); i++)
{
c.enterRoad(r, i);
cout << "Road after car entered at positon " << i
<< " is:\n" << r << endl;
}
return;
}