LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-13-2004, 02:38 AM   #1
harbir
LQ Newbie
 
Registered: Jan 2004
Posts: 18

Rep: Reputation: 0
Program Testing


Hello Guys.
I was having a problem in getting some sort of answer for the following problem, as i really not ever delt with testing.
--------------------------------
Given a simple program designed to take inputs of integers from 1-1000 and to output the factorial value of that number, how would you test this program? You do not have access to the code. Please be as specific as possible.

---------------------------------

Actually i have been coder and not sure how to tess tet the program.

Thank you for your time and Patience.
Harbir
 
Old 08-13-2004, 04:09 AM   #2
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
Hmm I would give a couple of numbers to the program and check it would agree with my calculator... Or even, I could redo the program if I had any reason not to trust the previously given program.
 
Old 08-13-2004, 08:14 AM   #3
cppkid
Member
 
Registered: Jul 2004
Location: Pakistan
Distribution: Ubuntu
Posts: 185

Rep: Reputation: 30
Testing means to verify, if your program is stable in all the conditions, so a simple way is that,
_______________________________________________
STEP 1:

Provide your program some random numbers, maually if it is a program to generate the factorial 1 -1000, find the factorial of some numbers manually using calculator and then with compare the results with that of your program. Random numbers like, 1 , 2 , 133 , 77 , 673 , 984 and some others.
_______________________________________________

STEP 2:

Provide your program some invalid numbers, like if your program is to test numbers 1 - 1000 then provide it with
-34 , -1 , 0 1001 , 1235 ......

Your program must not crash due to invalid input and may not give some result, like if you give -35, it will give you the factorial of 35. Its an error until it is supposed to do so.
So it must return some error like standard commands returns an error as -1.
 
Old 08-13-2004, 10:00 AM   #4
SolarBear
Member
 
Registered: Oct 2003
Location: Québec, Canada
Distribution: Gentoo 2005.0(desktop), Debian 3.0 r2 (server)
Posts: 105

Rep: Reputation: 15
One way to automate it would be to generate a testing program that "knows" the answer to a data sample. You pipe in your test values, and pipe the output to the test program that will parse the outpout to validate it.
 
Old 08-14-2004, 12:29 PM   #5
pycoucou
Member
 
Registered: Apr 2004
Location: Edinburgh
Posts: 78

Rep: Reputation: 15
There is a tricky point in his question is that 1000! is a *huge* number... I remember I did this kind of program as exercise but you can't use usual number type and have to create your own...
 
Old 08-14-2004, 02:55 PM   #6
kev82
Senior Member
 
Registered: Apr 2003
Location: Lancaster, England
Distribution: Debian Etch, OS X 10.4
Posts: 1,263

Rep: Reputation: 51
i hadnt considered it until pycoucou posted but 1000! is a 2568 digit number so you would definatly need an arbitrary length integer library. if time wasnt a constraint i would probably do something like

Code:
big_num_t x=1;
for(int n=1;n<1001;n++) {
    x*=n;
    if(x != factorial(n)) break;
}
if(n!=1001) printf("failed on %d", n);
you could do lots of quick tests all of which are necessary but not sufficient for the function to be correct and if they all pass then its likely the program is correct. eg

a) does it have the correct number of digits
b) are the last couple of digits correct
c) does it have some factors it should
d) does it have a factor it shouldnt
e) do the digits sum correctly (multiple of 3 for n>=3 multiple of 9 n>=6)
...

with a bit of number theory im sure you can come up with more conditions of you wish.

if you have a quick way to work out the gamma function then it might be worth comparing it to that as well. a digit extraction algorithm would be nice but unfortunatly there doesnt seem to be one.

cant really think of anything else.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
iptables testing program metallica1973 Linux - Security 7 04-29-2005 09:50 PM
RAM Testing program swmok Linux - Software 5 04-12-2005 10:39 PM
Setup as getting debian testing files from ftp - will it stay with testing BrianHenderson Debian 2 09-02-2004 06:06 PM
Network testing program? Joey.Dale Linux - Software 3 03-06-2004 10:26 AM
Gtk-Warning but program still works... I close konsole, program closes Laptop2250 Linux - Software 2 11-14-2003 11:18 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:45 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration