minimario's blog

By minimario, history, 7 years ago, In English

Hi,

Is there any program that can test a program on a large set of .in files against a large set of .out files? I heard about Ineffable, but I also heard it's really buggy.

Thanks!

  • Vote: I like it
  • +32
  • Vote: I do not like it

»
7 years ago, # |
  Vote: I like it +86 Vote: I do not like it

If you use Linux, here is the command you are looking for:

for i in *.in; do j=${i%.*}; ./cpp < $j.in > my$j.out; echo ---$j---; diff -w my$j.out $j.out; done;

What it does is loop over all files having extension .in (this is the value of i), then j becomes the filename without the extension and after that it just runs your code with j.in, saves your output in myj.out and compares it to the correct output j.out.

Here is what it should look like if among 10 cases, the 7th one fails:

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

    Thanks! very useful

  • »
    »
    7 years ago, # ^ |
    Rev. 2   Vote: I like it 0 Vote: I do not like it

    I'm trying to extend this to files of the type I.(number) and O.(number). The current line I have is this:

    for i in I.*; do j=${*.i%}; ./cpp < I.$j > my$j.out; echo ---$j---; diff -w my$j.out O.$j; done;
    

    Unfortunately it seems to be failing to get the proper j (it thinks it is the character I). I am not very experienced with this kind of thing (I don't even know what it's called). Could you please tell me how I can get it to obtain the proper j values?

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +21 Vote: I do not like it
      do j=${i##*.}
      

      What this does is remove the longest match of *. from the front of i, which results into the extension we need. I also don't know a lot about bash, just a few things I find helpful for testing.

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

    Does anyone have a good solution for people who don't use Linux?

    • »
      »
      »
      7 years ago, # ^ |
        Vote: I like it +34 Vote: I do not like it
    • »
      »
      »
      7 years ago, # ^ |
      Rev. 3   Vote: I like it 0 Vote: I do not like it

      For windows this works, if you want to test main.exe with all the pairs (x.in,x.ans) in the folder you do: $run.bat main

      @echo off
      setlocal enabledelayedexpansion
      
      set exe=%1.exe
      
      if not exist %exe% exit /B
      
      for %%I in (*.in) do (
        set testId=%%~nI
        set inputFile=%%I
        set answerFile=!testId!.ans
        set outputFile=!testId!.out
        %exe% <!inputFile!> !outputFile!
        echo Test #!testId!
        FC !answerFile! !outputFile!
      )
      

      You can start with this .bat and try to improve it