Google test, classes and objects.

Hello all, i've been busy with this excersize for quiete some time now, i'm using the google test framework and i'm trying to write code for the test below

1
2
3
4
5
TEST(Line, canFindTheOnlyWordInLineWithOneWord) {
    Line testline("Stop");
    Word searchword("Stop");
    EXPECT_TRUE(testline.contains(searchword));
}


I have the following classes that have been predefined and their publice members are to not be changed
1
2
3
4
5
6
7
8
9
10
11
12
13
class Line
{
public:
	// DO NOT MODIFY THE PUBLIC INTERFACE OF THIS CLASS

	// accepts a line of text (which FileReader will provide in production code)
	Line(const string& line);
	// returns true if the search word is found in the line; false otherwise
	bool contains(const Word& search_word) const;

private:
    vector<Word> _line;
};


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
class Word
{
public:
	// DO NOT MODIFY THE PUBLIC INTERFACE OF THIS CLASS

	// constructor
	Word(const string& word);
	// overloads is-equal-to (or equivalence) operator - this is very useful for testing,
	// as we can compare words directly
	bool operator==(const Word& rhs) const;
	// returns true if queryable, false otherwise
	// (according to the brief, words less than 3 characters are not queryable)
	bool isQueryable() const;

private:
	string _word;
};


What i understance from the test is that the following function should somehow compare searchWord and testline
1
2
    Line testline("Stop");
    Word searchword("Stop");
and return a true if they are equal.


My contains function currently looks like this
1
2
3
4
bool Line::contains(const Word& search_word) const {

    return false;
}


How do i go about comparing
1
2
    Line testline("Stop");
    Word searchword("Stop");
given all this, i really cant think of anyway to do it!, any help / suggestion will be greatly appreciated, i am willing to provide more information if required!


Thanks.

Note that the private interface of each class may be changed and or edited!
Last edited on
First of all, stop commenting every single line of code. Comments like //constructor are useless unless the person who you are giving the code to has no knowledge in C++, which wouldn't be useful at all. Only document when needed :)
Additionally, most lines can be written in such a way it's self documenting. For example person.getHeight().

I hope you get through the "exercise".
It is a test, I think that's why he is commenting so often, he is testing noobs or a class of students at a school/ buisness.
Last edited on
Topic archived. No new replies allowed.