Question: Below for each class you find a UML and description of the public interface. Implementing the public interface as described is mandatory.There's freedom on how

Below for each class you find a UML and description of the public interface. Implementing the public interface as described is mandatory.There's freedom on how to implement these classes.The private properties and private methods are under your control. For each object, it's mandatory to create a header file (.h), implementation file (.cpp) and a driver. Blank files are included. The header should have the class definition in it. The implementation file should contain the implementations of the methods laid out in the header fine. And finally the Driver should test/demonstrate all the features of the class. Two test suites are included so that work can be checked. It's important to implement the drivers to test and demonstrate Classes functionality.
KnightTest.cpp:
#define CATCH_CONFIG_MAIN
#include "../Knight.h"
#include
#include
#include
TEST_CASE("Should be able to create a Knight"){
Knight arthur = Knight("Sir Arthur", 1,100);
}
TEST_CASE("Should be able to get Knight's name"){
Knight elara = Knight("Lady Elara", 4,550);
string name = elara.getName();
REQUIRE_THAT("Lady Elara", Catch::Matchers::Equals(name));
}
TEST_CASE("Should be able to get the level"){
Knight *cedric = new Knight("Sir Cedric", 3,277);
int level = cedric->getLevel();
REQUIRE(3== level);
}
TEST_CASE("Should be able to get the Max hit points"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
int max = gwendolyn.getMaxHitPoints();
CHECK(300== max);
Knight arthur = Knight("Sir Arthur", 1,100);
max = arthur.getMaxHitPoints();
CHECK(150== max);
}
TEST_CASE("Should be able to get health as a percentage"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
double health = gwendolyn.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(66,1));
Knight arthur = Knight("Sir Arthur", 1,32);
health = arthur.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(21,1));
}
TEST_CASE("Gaining Experience should cause the Knight to level up"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
gwendolyn.gainExperience(120);
int level = gwendolyn.getLevel();
CHECK(3== level);
Knight arthur = Knight("Sir Arthur", 1,32);
arthur.gainExperience(20);
arthur.gainExperience(89);
level = arthur.getLevel();
CHECK(2== level);
}
TEST_CASE("Attack should return 5 times the knight's level"){
Knight *cedric = new Knight("Sir Cedric", 7,277);
int damage = cedric->attack();
CHECK(35== damage);
Knight elara = Knight("Lady Elara", 4,550);
damage = elara.attack();
CHECK(20== damage);
}
TEST_CASE("Should be able to heal a Knight"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
gwendolyn.heal(100);
double health = gwendolyn.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(100,1));
Knight arthur = Knight("Sir Arthur", 1,32);
arthur.heal(45);
health = arthur.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(51,1));
}
TEST_CASE("Should take damage when damaged"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
gwendolyn.damage(99);
double health = gwendolyn.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(34,1));
Knight arthur = Knight("Sir Arthur", 1,32);
arthur.damage(13);
health = arthur.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(13,1));
}
TEST_CASE("Should not be able to heal a Knight more than 100%"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
gwendolyn.heal(1000);
double health = gwendolyn.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(100,1));
}
TEST_CASE("Dead Knights should return 0% health"){
Knight arthur = Knight("Sir Arthur", 1,32);
arthur.damage(45);
int health = arthur.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(0,1));
}
TEST_CASE("Should not be able to heal a Knight that is dead"){
Knight gwendolyn = Knight("Lady Gwendolyn", 2,200);
gwendolyn.damage(1000);
gwendolyn.heal(100);
double health = gwendolyn.health();
CHECK_THAT(health, Catch::Matchers::WithinAbs(0,1));
}
TEST_CASE("Should be dead when health is 0"){
Knight *cedric = new Knight("Sir Cedric", 7,277);
cedric->damage(300);
bool isDead = cedric->isDead();
CHECK(isDead);
Knight elara = Knight("Lady Elara", 4,550);
elara.damage(500);
elara.damage(350);
isDead = elara.isDead();
CHECK(isDead);
}
TEST_CASE("Knights can not return from the dead"){
Knight *cedric = new Knight("Sir Cedric", 7,277);
cedric->damage(300);
cedric->heal(20);
bool isDead = cedric->isDead();
CHECK(isDead);
Knight elara = Knight("Lady Elara", 4,550);
elara.damage(500);
elara.damage(350);
elara.heal(1000000);
isDead = elara.isDead();
CHECK(isDead);
}
Knight.h:
#include
using namespace std;
#ifndef KNIGHT_H
#define KNIGHT_H
static const int DAMAGE_SCALAR =5;
static const int EXPERIENCE_POINTS_
 Below for each class you find a UML and description of

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!