Now often use Vim to write some C language programs, write the program generally have to carry out some tests, of course, we can do some regular manual testing. In my mind, it would be nice if I could write a shell script that would automatically test the C language program.
In order to try this idea, found a C language program title:
[a ball from - The height of the meter falls freely, and jumps back to half the original height after each landing, and then falls, begging it to Section Ten How many meters are there after the landing? Ten How high is the second bounce?]
On the basis of this requirement, I have written a procedure to solve this problem:
#include <stdio.h> #include <stdlib.h> #define H 100int Main (int argc, char* argv[]) { float h0=h; float sum=h; float H=h0; int count=2; int Number=atoi (argv[1]); for (; count<=number;count++) { h=h/2.0; sum+=2*h; } h=h/2.0; printf ("The initial height is:%d\n", number); printf ("The length is%.3f, the height is%.2f\n", sum, h); return 0;}
This program can get the correct result, below I wrote a shell script program can be automated test
#!/bin/bashfor ((i=1;i<=10;i=i+1)) do ./a.out $idone
The CC *.cpp is executed on the end of the Mac system, which generates the A.out executable, which tests 10 sets of examples in this shell script:
file:///Users/daidapeng/Desktop/Screen shot%202015-07-10%20 pm 11.38.01.png
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Write a shell script that automatically tests the C language program