There is an algorithm in the software program that other team handed to me on linux. Given a set of requirements, our task is to create a test script/driver to verify that algorithm using a separate data file and spit out the result on the output file. The concept is quite simple, but not sure if I know how to start. Please advice!!!!!

example: a C program contains an algorithm F = ma (Newton's Law). a data file for m and a is needed (each line contains data for m and a). To verify an algorithm, a test script should be written to call both data file and executable file and the output should be written either on the fly or a text file.

Thanks

Ignoring the file issue for the moment, how does the program get a single 'm' and 'a' value?

On the command line, like ./testprog 10 20 Or as a prompt from within the program

Enter m and a values
10 20

Salem

Ignoring the file issue for the moment, how does the program get a single 'm' and 'a' value?

I do believe yer man has already said he'll be reading m and a from a file

using a separate data file ... a data file for m and a is needed (each line contains data for m and a).

usr1971ca, what a nice name by the way, you need to read the two numbers in from your data file; fgets() reads in a line at a time, then convert the two numbers from the digits in the input line into integers with sscanf(). Now it's just a matter of calculating their product and writing it out.

Your code might look something like this:

while (fgets(buf, sizeof(buf), datafile) != NULL)
      {
         if (sscanf(buf, "%d%d", &m, &a) == 2)
         {
            printf("%d * %d = %d\n", m, a, m * a);
         }
      }

Oh, hang on. You don't need to write the program just a script to run it. That seems very odd because it could be as little as the name of the program followed by the name of the datafile both on one line in a text file that you make executable with chmod.

Or am I missing something here?

Salem and Risby,

Thanks for your prompt replies.
However, we will not scanf or fget within the prorgam. We probably initialize all 3 parameters for compilation purpose. The excerise here is to write another program to read a data file, which is used for a computation defined in that executable code. Its kinda hard to describe clearly here, but hope you get a picture.

Thanks

Its kinda hard to describe clearly here, but hope you get a picture.

Not at all ... and if you want to get anywhere in IT clear descriptions are vital.

> Its kinda hard to describe clearly here, but hope you get a picture.
The source code for the program you're trying to test, or at least the bit of it where it "gets the values m and a" would make it much clearer.

I guess I still don't know how. Any example of a C program that reads both inputs (from data file) and object code so that it can generate an output file?

Take your pick

#include <stdio.h>
#include <stdlib.h>

int main ( int argc, char *argv[] ) {
    int m, a;
    if ( argc > 2 ) {
        m = strtol(argv[1],NULL,10);
        a = strtol(argv[2],NULL,10);
    } else {
        char buff[BUFSIZ];
        printf( "Enter m and a values > " );
        fflush( stdout );
        if ( fgets( buff, sizeof buff, stdin ) != NULL ) {
            sscanf( buff, "%d %d", &m, &a );
        }
    }
    printf( "m=%d, a=%d\n", m, a );
    return 0;
}


# parameters on command line
$ ./a.exe 22 33
m=22, a=33

# parameters entered at a prompt
$ ./a.exe
Enter m and a values > 33 44
m=33, a=44

Salem,

Thanks very much. But that doesn't clear up my frustration.

The above source code should be pre-compiled. Data 22 33 should be one of the many data in a separate file. An objective here is to write a test script to read BOTH that data file and object code then spit out the result in a separate output file.

Your patience is appreciated

Which brings me back to the my original question, how does your pre-compiled program read the input?

From the command line?
From a prompt?

How it runs affects how you drive it
say

echo 22 33 | testprogram
testprogram 22 33

> write a test script
Using what language
C
C++
C!*?#
DOS Batch file
Linux bash script
Perl
....
etc

This stuff is easy in any number of ways, but I'm not about to describe all of them for the lack of you being specific about what it is you have.

In other words:
You have 3 files
1) Data File -- what reads the data file?
2) Program -- calculates data from the file. How does the data get into the program?
3) Script file -- somehow runs the program and associates the data with the program. This depends on how the other two files interface.

Waltp has interpreted my point correctly.
A test script using C to run a pre-compiled program with the input data in a separate file.

We treat a program as a black box w/o having any ability to modify the source. This is a software that a vendor delivered to us. With the set of requirements, wWe will now have to creat a scenarios (input data) to test this piece of new release software.

As a newbie, I just want to understand that simple concept, then apply toward that large scale testing.

Waltp has interpreted my point correctly.
A test script using C to run a pre-compiled program with the input data in a separate file.

We treat a program as a black box w/o having any ability to modify the source. This is a software that a vendor delivered to us. With the set of requirements, wWe will now have to creat a scenarios (input data) to test this piece of new release software.

As a newbie, I just want to understand that simple concept, then apply toward that large scale testing.

But not one question answered. We therefore can't help because we don't know what to do either. Sorry.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.