accidentallygivenfuck's blog

By accidentallygivenfuck, 12 years ago, In English

Hi everybody. Does anybody know a way how to test your program in Linux. I know how to do it in Windows 7.

For example (file gr.bat) ::

copy <input_file_name_in_test_data>.in.%1 <input_file_name_default>.in
<executable_file_name>
fc <output_file_name_in_test_data>.out.%1 <output_file_name_default>.out

(you can set the syntax yourself)

to test just enter in cmd gr 1 , gr 2 , ... or gr x for test x.

Thanx in advance.

UPD: LOTS OF THANKS to razimantv and Xerxes. [SOLVED]

»
12 years ago, # |
Rev. 3   Vote: I like it +2 Vote: I do not like it

cmp command will help. http://en.wikipedia.org/wiki/Cmp_(Unix) In order to get more familiar with this, open your terminal and type cmp --help

»
12 years ago, # |
  Vote: I like it +6 Vote: I do not like it

Suppose that your executable is named exec and your input files are named input.1 ... input.10 and similarly for output files. In bash, you can write the following script in the bash terminal:

for((i=0;i<=10;i++))
do
./exec <input.$i | diff -bsq - output.$i
done

This will check whether the output your program produces for each input file is the same as the output file.

  • »
    »
    12 years ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Thanx. how to save your script ( what should be the extension ) ? and how to run it on terminal ?

    • »
      »
      »
      12 years ago, # ^ |
        Vote: I like it +5 Vote: I do not like it

      Save the script with .sh extension. You can run it with bash <name>.sh or, if you have set executable permissions for it, ./<name>.sh. All these are to be run on terminal only.