wu :: forums
« wu :: forums - test cases »

Welcome, Guest. Please Login or Register.
Apr 29th, 2024, 3:45am

RIDDLES SITE WRITE MATH! Home Home Help Help Search Search Members Members Login Login Register Register
   wu :: forums
   riddles
   cs
(Moderators: SMQ, Eigenray, william wu, ThudnBlunder, Grimbal, Icarus, towr)
   test cases
« Previous topic | Next topic »
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print
   Author  Topic: test cases  (Read 2804 times)
don
Guest

Email

test cases  
« on: Apr 22nd, 2004, 1:28pm »
Quote Quote Modify Modify Remove Remove

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  Roll Eyes
 
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: male
Posts: 13730
Re: test cases  
« Reply #1 on: Apr 22nd, 2004, 1:42pm »
Quote Quote Modify 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 Wink)
 
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!

5187759 5187759   john23874   SnowmanJTG
WWW Email

Gender: male
Posts: 767
Re: test cases  
« Reply #2 on: Apr 22nd, 2004, 7:49pm »
Quote Quote Modify 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

Email

Re: test cases  
« Reply #3 on: Apr 22nd, 2004, 8:48pm »
Quote Quote Modify Modify Remove Remove

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: male
Posts: 13730
Re: test cases  
« Reply #4 on: Apr 23rd, 2004, 12:04am »
Quote Quote Modify 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!

5187759 5187759   john23874   SnowmanJTG
WWW Email

Gender: male
Posts: 767
Re: test cases  
« Reply #5 on: Apr 23rd, 2004, 10:12am »
Quote Quote Modify 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: male
Posts: 13730
Re: test cases  
« Reply #6 on: Apr 24th, 2004, 5:03am »
Quote Quote Modify 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
Pages: 1  Reply Reply Notify of replies Notify of replies Send Topic Send Topic Print Print

« Previous topic | Next topic »

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