gabrc's blog

By gabrc, history, 17 months ago, In English

I've created a Bash script to evaluate your own test cases:

N=`ls *.out | wc -w`
for ((i = 1; i <= N; i++)); do
    echo ----- case $i -----
    diff -wb <($1 <$ $i.out || break

To use this script, create test cases in the format, 1.out,, 2.out,, 3.out, ...

You need to pass your executable as first argument

By default, it will try doing tests sequentially until it finds a test case where it fails, then it will print the difference between your output and the correct output. If you want it to test every case, remove the part that says || break

I've also created a script that can create these files for you, which may be more convenient

cases=`ls *.out 2>/dev/null` && N=`echo $cases | wc -w` || N=0
echo Enter the contents of $ and press Ctrl+D when done
cat > $
echo Enter the contents of $N.out and press Ctrl+D when done
cat > $N.out

You may replace cat with nano, vim, geany, etc if you prefer.

You may add both of these to your PATH, for instance you can create the folder ~/bin, add both files there, and then run:

echo PATH=$PATH:$HOME/bin >> ~/.bashrc

They need to be set as exectuable, i.e:

chmod +x ~/bin/judge
chmod +x ~/bin/mkcase

Then, if the judge is in ~/bin/judge and the case creator in ~/bin/mkcase, you can simply run judge ./program to test your program and run mkcase to make a new case

It can even be useful to learn and write these scripts during an on-site contest.

Both scripts use the Bash double parentheses construct that lets you write more C-like expressions, which isn't that well known.

Read more »

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