Guest User

bash script to test algos

a guest
Sep 26th, 2021
23
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.75 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3.  
  4. # example of usage: algotest C cpp;
  5. # all tests are Ai1, Ai2, ...
  6. # all test results are Aa1, Aa2, ...
  7. # program is A.cpp or A.py
  8.  
  9. name=$1
  10. ext=$2
  11.  
  12. RED='\033[0;31m'  # Red Color
  13. GREEN='\033[0;32m'  # Green Color
  14. NC='\033[0m'  # No Color
  15.  
  16. if [[ "$ext" == "cpp" ]]; then
  17.     g++ $name.$ext -o $name
  18.     prog=$name
  19. else
  20.     prog="${name}.py"
  21. fi
  22.  
  23. testfiles="${name}i*"
  24.  
  25. echo $testfiles
  26. echo
  27.  
  28. for input in `ls $testfiles`; do
  29.     n=`echo $input | grep -o -E '[0-9]+'`
  30.     ans=${name}a${n}
  31.     text1=`cat $input | "./$prog" | awk 1`
  32.     text2=`awk 1 $ans`
  33.     if [[ $text1 == $text2 ]]; then
  34.     printf "${GREEN}${input}${NC}\n";
  35.     else
  36.     printf "${RED}${input}${NC}\n"
  37.     echo $text1
  38.     echo $text2
  39.     fi
  40.     echo
  41. done
Advertisement
Add Comment
Please, Sign In to add comment