How to make a simple judge in bash to evaluate your test cases

Revision en1, by gabrc, 2020-05-20 01:08:16

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

#!/bin/bash
N=`ls *.in | wc -w`
for ((i = 1; i <= N; i++)); do
    echo ----- case $i -----
    diff -wb <($1 <$i.in) $i.out || break
done

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

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. To disable this, remove the part that says || break

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

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

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

Tags judge, local, script, #customtest

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en6 English gabrc 2020-05-20 03:44:56 5 similar change to judge
en5 English gabrc 2020-05-20 03:43:20 5 Change ls *.in -> ls *.out in order to make mkcase cancellable
en4 English gabrc 2020-05-20 01:18:32 89 (published)
en3 English gabrc 2020-05-20 01:16:44 106
en2 English gabrc 2020-05-20 01:14:10 510
en1 English gabrc 2020-05-20 01:08:16 1139 Initial revision (saved to drafts)