Write a shell script that automatically tests the C language program

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.