I was wondering if I can use a Python script to test a C program automatically.
Suppose I have a very simple C program which reads data (numbers as test cases) from the console, calculates them, then outputs it to the console. Now I want to read data from a file then output whatever the program outputs into a file.
Suppose in the original C program I use while
loop andscanf
to read two numbers into two variables a
and b
for several times and do different calculations according to the values of a
and b
, like this:
if(a>4 && a<10){...} else if(a>=10){...}
Now can I use a Python script to test the program automatically? And do I need to modify my C program? How?
EDIT: If any method is permitted, then what is the best way to test the C program automatically without using frameworks?