Question
Hey I'm currently learn how to use bazel and gtest (test driven development, c++), and I would like to create some declarations and definitions based
Hey I'm currently learn how to use bazel and gtest (test driven development, c++), and I would like to create some declarations and definitions based on the given tests.
Here are the tests:
TEST(mutants, mystique) {
// mystique weights 54kg.
Mystique mystique();
EXPECT_EQ(mystique.weight(), 54);
EXPECT_STREQ(mystique.shape(), "sphere");
// Morph to "flat" shape
mystique.morph("flat");
EXPECT_STREQ(mystique.shape(), "flat");
// Go back to default
mystique.morph();
EXPECT_STREQ(mystique.shape(), "sphere");
// Ignore all other morph attempts
mystique.morph("crazy");
EXPECT_STREQ(mystique.shape(), "sphere");
// Split into two (checks for inequality of Mystique instances, must implement operator overloading, such as !=)
Mystique newMystique = mystique.split();
EXPECT_NE(newMystique , mystique);
EXPECT_EQ(mystique.weight(), 68);
EXPECT_EQ(newMystique .weight(), 68);
EXPECT_STREQ(newMystique .shape(), mystique.shape());
____________________________________________________________________________________________________________
Basically I need to look at each test and write down the code that will pass the above tests, and this is the code I wrote as far as now:
class Mystique{
public:
Mystique(double mystiqueWeight);
double weight();
const char* shape();
private:
double _mystiqueWeight;
const char* _mystiqueShape = "sphere";
};
Mystique::Mystique(double mystiqueWeight) {
_mystiqueWeight = mystiqueWeight;
}
double Mystique::weight() {
return _mystiqueWeight;
}
const char* Mystique::shape() {
return _mystiqueShape;
}
____________________________________________________________________________________________________________
Please include your brief explanation. Thank you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started