Consider the following class definition:
class StrToTokens {
StrToTokens(const char* str, const char* delimiters = "\t\r\n"); //constructor
string getN开发者_运维问答extToken();
void reset();
bool empty();
}
Can someone list some good testcases to test the above class.
A few I could think of are:
empty string, empty delimiters, repeated delimiters, consecutive delimiters, string with only delimiters.However, the interviewer expected some more(better ones). Can you help out.
Thanks.
Well, I usually add at least one testcase that just tests for a normal working case. And of course all the tests you guys mentioned where just for the constructor. The other methods have to be tested as well:
- does reset really reset (what is reset meant to do anyway)
- does empty behave as expected
- are tokens retrieved in the right way/order
I usually implement some more complex testcases to test such things, such as
Initialize
read a token
reset
read a token
Or
Initialize
read all tokens
check empty
If you are looking for edge cases I would test the following.. Some of them you've already came up with, but I don't think there are more "edgy" cases than the following:
StrToTokens(NULL);
StrToTokens("a", NULL);
StrToTokens("a", "\0");
StrToTokens("", "");
StrToTokens("abc", "abc");
精彩评论