views:

69

answers:

2

Consider the following class definition:

class StrToTokens {
  StrToTokens(const char* str, const char* delimiters = "\t\r\n"); //constructor
  string getNextToken();
  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.

+2  A: 

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");
Andreas Bonini
and may be combinations of these.. phew!! testing is difficult
Neeraj
+3  A: 

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
Space_C0wb0y
you mean this.. `initialize -- read value1 -- reset -- read value2` value1 should be equal to value 2. "a good one! btw"
Neeraj
Add to the list a test for calling `getNextToken()` more times than there are tokens (not sure what the desired behavior would be for this, but whatever it is should be tested).
Michael Burr