Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

71 linhas
1.9KB

  1. #!/bin/bash
  2. if [ -z "$(which gawk)" ]; then
  3. echo "error: gawk is not installed"
  4. exit 1
  5. fi
  6. # get into the correct PWD
  7. if [ ! -f ./header.m4 ]; then
  8. cd players
  9. fi
  10. if [ ! -f ./header.m4 ]; then
  11. echo "error: call me from the players directory"
  12. exit 1
  13. fi
  14. # ordered cases
  15. cases="00-internal 02-always-stand 05-no-bust 08-mimic-the-dealer"
  16. # fancy names
  17. declare -A names=(\
  18. ["00-internal"]="Internal player" \
  19. ["02-always-stand"]="Always stand" \
  20. ["05-no-bust"]="No-bust strategy" \
  21. ["08-mimic-the-dealer"]="Mimic the dealer")
  22. # expected results
  23. declare -A expected=(\
  24. ["00-internal"]="-0.0065" \
  25. ["02-always-stand"]="-0.150" \
  26. ["05-no-bust"]="-0.075" \
  27. ["08-mimic-the-dealer"]="-0.055")
  28. # allowed deviation
  29. sigma=0.02
  30. # if there is something on the commandline, use that one, otherwise the expected keys
  31. if test ! -z "$1"; then
  32. player=$(basename $1) # remove trailing '/'
  33. else
  34. player=${cases}
  35. fi
  36. echo 'Case | Expected | Result | Error | Status ' | tee check.md
  37. echo '------------------------|---------------|--------------- |---------------|---------' | tee -a check.md
  38. for i in ${player}; do
  39. if test -d ${i} -a -x ${i}/run.sh; then
  40. cd ${i}
  41. if test $(echo "${names[${i}]}" | wc -c) -gt 16 ; then
  42. sep="\\t"
  43. else
  44. sep="\\t\\t"
  45. fi
  46. echo -ne ${names[${i}]}${sep}'| '${expected["${i}"]}\\t'| '
  47. ./run.sh 1>/dev/null 2> ../${i}.yaml
  48. return=$(grep mean ../${i}.yaml | awk '{print $2}')
  49. error=$(grep error ../${i}.yaml | awk '{print $2}')
  50. echo -ne ${return}\\t' | '${error}\\t' | '
  51. status=$(echo ${return} | awk -v e=${expected["${i}"]} -v s=${sigma} 'END {ok = ($1>(e-s)&&$1<(e+s)); print ok?"ok":"failed"; exit !ok }')
  52. result=$?
  53. cd ..
  54. echo ${status}
  55. echo -e "${names[${i}]}${sep}| ${expected["${i}"]}\\t| ${return}\\t | ${error}\\t | ${status}" >> check.md
  56. else
  57. # echo "skipped ${i}"
  58. result=77
  59. fi
  60. done