wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> cs >> test cases
(Message started by: don on Apr 22nd, 2004, 1:28pm)

Title: test cases
Post by don on Apr 22nd, 2004, 1:28pm
Hi guys,

Theres been a lot of stuff about coding... i was just wondering about the possible test cases (black box) that can be written given a function definition....

char * fun( char** str1, char *str2)

i did get some weird tests from the MS guys like how about using chinese characters  ::)

could u highlight some of the tests that can be conducted on the above function....

-Don

Title: Re: test cases
Post by towr on Apr 22nd, 2004, 1:42pm
Well, the obvious test case is two empty strings.
Then there some string and an empty string
two equal string
a string and it's reverse,
two permutations of the same string
strings with all characters the same
give some integers as argument (they will be interpreted as pointers pointing to a characters string somewhere in the memory, a nice way to generate errors ;))

hmm, should that first argument be char** or char*? (the name suggest the latter, which is how I took it..)

Title: Re: test cases
Post by John_Gaughan on Apr 22nd, 2004, 7:49pm
Like towr said, the name suggests "char*". Anyway, test cases would be valid data, null pointers, and invalid (wild) pointers. Make sure to test a variety of invalid pointers of various values. You could create your own variable, take its address, and add 10 or so to stay in your own stack or heap (if you have a private heap).

Test a variety of character types. Try casting wchar_t to char. Null-termination is slightly different with wide characters, in fact, if you encode ASCII as 16 bit Unicode you will be in for a surprise because the high bytes are all null. Maybe the function will test for the Unicode marker and cast appropriately?

The real question, Mr. Microsoft interviewer, is why are you not using std::string object references?

Title: Re: test cases
Post by don on Apr 22nd, 2004, 8:48pm
Hi

i thought char** str is perfectly fine?

the test cases for it were
str null
*str null

am i missing something?

btw john ..can u elaborate on this... i didnt get it right....
"Test a variety of character types. Try casting wchar_t to char. Null-termination is slightly different with wide characters, in fact, if you encode ASCII as 16 bit Unicode you will be in for a surprise because the high bytes are all null. Maybe the function will test for the Unicode marker and cast appropriately?
"

keep the faith

Title: Re: test cases
Post by towr on Apr 23rd, 2004, 12:04am

on 04/22/04 at 20:48:35, don wrote:
i thought char** str is perfectly fine?
Well yes, it's grammatical. But "str" implies "it's a string" implies "char *" (it like declaring "int a_float;", legal but confusing).
char ** is an array of strings .. supposedly .. It could also just be a pointer to a pointer to a char

That's one of the problems, we don't actually know what the arguments are. They could be 0 terminated arrays (like a C string, or like the argument string passed to main) But they might be something completely different.

Title: Re: test cases
Post by John_Gaughan on Apr 23rd, 2004, 10:12am
wchar_t s[] = L"test string";
wchar_t *t = NULL;

func ((char*)s, (char*)t);

This should make the function screw up.

Title: Re: test cases
Post by towr on Apr 24th, 2004, 5:03am
depend on what the function does, it might just return "hello world" regardless of input.

One other thing that might be worth testing is wether it allways gives the same output given the same input (because it might 'remember' things from the past and give different results depending on previous calls)



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board