Author |
Topic: test cases (Read 2821 times) |
|
don
Guest
|
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
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: test cases
« Reply #1 on: Apr 22nd, 2004, 1:42pm » |
Quote Modify
|
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..)
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
John_Gaughan
Uberpuzzler
Behold, the power of cheese!
Gender:
Posts: 767
|
|
Re: test cases
« Reply #2 on: Apr 22nd, 2004, 7:49pm » |
Quote Modify
|
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?
|
|
IP Logged |
x = (0x2B | ~0x2B) x == the_question
|
|
|
don
Guest
|
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
|
|
IP Logged |
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: test cases
« Reply #4 on: Apr 23rd, 2004, 12:04am » |
Quote Modify
|
on Apr 22nd, 2004, 8:48pm, 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.
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
John_Gaughan
Uberpuzzler
Behold, the power of cheese!
Gender:
Posts: 767
|
|
Re: test cases
« Reply #5 on: Apr 23rd, 2004, 10:12am » |
Quote Modify
|
wchar_t s[] = L"test string"; wchar_t *t = NULL; func ((char*)s, (char*)t); This should make the function screw up.
|
|
IP Logged |
x = (0x2B | ~0x2B) x == the_question
|
|
|
towr
wu::riddles Moderator Uberpuzzler
Some people are average, some are just mean.
Gender:
Posts: 13730
|
|
Re: test cases
« Reply #6 on: Apr 24th, 2004, 5:03am » |
Quote Modify
|
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)
|
|
IP Logged |
Wikipedia, Google, Mathworld, Integer sequence DB
|
|
|
|