/*---- signature: main: void -> int purpose: testing program for the class PlayerChar compile using: g++ PlayerChar-test.cpp PlayerChar.cpp -o PlayerChar-test run using: ./PlayerChar-test by: Sharon Tuttle last modified: 2022-09-25 - slightly-cleaned-up version for posting 2022-09-22 - original version ----*/ #include <cstdlib> #include <iostream> #include <string> #include <cmath> #include "PlayerChar.h" using namespace std; int main() { cout << boolalpha; cout << "\n*** Testing class PlayerChar ***" << endl; // how do you test a class? // ...you test all its methods! // call each constructor at least once; // and you can use its accessors to both verify that // the constructors worked, and to verify that they // are working...! PlayerChar sven; PlayerChar angie("Angie", 10, 2.7, "tank", 15); // note: you can break these up into // easier-to-debug separate statements...! cout << "\ntesting constructors and accessors:" << endl; cout << ( (sven.get_name() == "") && (sven.get_strength() == 5) && (sven.get_exp() == 0) && (sven.get_role() == "") && (sven.get_hp() == 20) ) << endl; cout << ( (angie.get_name() == "Angie") && (angie.get_strength() == 10) && (angie.get_exp() == 2.7) && (angie.get_role() == "tank") && (angie.get_hp() == 15) ) << endl; // testing my mutators next! cout << "\ntesting mutators:" << endl; sven.set_name("Sven"); cout << (sven.get_name() == "Sven") << endl; sven.set_role("dps"); cout << (sven.get_role() == "dps") << endl; cout << "\ntesting my \"other\" methods" << endl; cout << "\ntesting display_player:" << endl; PlayerChar a_player; cout << "\nShould see a player with no name, " << endl << " strength 5, exp 0, no role, and" << endl << " hp 20: " << endl; a_player.display_player(); cout << "\nShould see a player with name Angie, " << endl << " strength 10, exp 2.7, role tank, and" << endl << " hp 15: " << endl; angie.display_player(); cout << "\ntesting player_to_string:" << endl; cout << (a_player.player_to_string() == "PlayerChar(, 5, 0.000000, , 20)") << endl; cout << (angie.player_to_string() == "PlayerChar(Angie, 10, 2.700000, tank, 15)") << endl; cout << endl; return EXIT_SUCCESS; }