Advertisement
CSenshi

Information Theory - HW0 (checker)

Sep 18th, 2019
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 3.73 KB | None | 0 0
  1. if [ "$#" -ne 3 ]; then
  2.     echo "Invalid Arguments"
  3.     echo "Usage: script requires 3 Arguments: "
  4.     echo "       1. Path to folder which contains following scripts with exact names:"
  5.     echo "          SimpleRead.py, SimpleWrite.py, CompleteWrite.py, CompleteRead.py"
  6.     echo "       2. Path to folder which contains public tests(where A,B,C,D folders are located)"
  7.     echo "       3. Path to folder where we should put output for each test"
  8.     echo "Example: ./check.sh src/ public_tests/ result/"
  9.    
  10.     exit
  11. fi
  12.  
  13. SCRIPT_FOLDER_PATH=$1
  14. echo "Script Folder path:    $(pwd)/${SCRIPT_FOLDER_PATH}"
  15. TEST_FOLDER_PATH=$2
  16. echo "Test Folders path:     $(pwd)/${TEST_FOLDER_PATH}"
  17. RESULT_DIR_NAME=$3
  18. echo "Result Directory Path: $(pwd)/${RESULT_DIR_NAME}"
  19.  
  20. # delete Result Dir if exists
  21. if [ ! -d "${RESULT_DIR_NAME}" ]; then
  22.     mkdir ${RESULT_DIR_NAME}
  23. fi
  24.  
  25. echo
  26. echo "Starting Tests"
  27. echo
  28.  
  29. compare_files(){
  30.     SCRIPT_PATH=$1
  31.     PTEST_DIR_NAME=$2
  32.     RES_DIR_NAME=$3
  33.     TNUM=$4
  34.     FNAME=$5
  35.    
  36.     for i in $(seq 1 $TNUM);
  37.     do
  38.         while [ ${#i} -lt 3 ]; do
  39.             i=0$i
  40.         done
  41.        
  42.         CURRENT_TEST=${PTEST_DIR_NAME}${i}.dat
  43.         CURRENT_TEST_ANS=${PTEST_DIR_NAME}${i}.ans
  44.         DEST_FILE_NAME=${RES_DIR_NAME}/${FNAME}_${i}.txt
  45.        
  46.         # launch your python script
  47.         eval python3 ${SCRIPT_PATH} \"$CURRENT_TEST\" $DEST_FILE_NAME
  48.        
  49.         # check if correct
  50.         echo "Test ${i} : $(eval cmp --silent \"$CURRENT_TEST_ANS\" \"$DEST_FILE_NAME\" && echo "Success: files are same!" || echo "Failed: files are different")"
  51.     done
  52. }
  53.  
  54. test1(){
  55.     # Check Simple Read
  56.     echo "### Checking Simple Read"
  57.    
  58.     SCRIPT=${SCRIPT_FOLDER_PATH}/SimpleRead.py
  59.     TESTS=${TEST_FOLDER_PATH}/A/
  60.     RES_DIR=${RESULT_DIR_NAME}/A/
  61.     TNUM=$1
  62.     FILE_NAME="SimpleRead"
  63.    
  64.     if [ ! -f "${SCRIPT}" ]; then
  65.         echo "Script not found"
  66.         return
  67.     fi
  68.    
  69.     if [ -d "${RES_DIR}" ]; then
  70.         rm -rf ${RES_DIR}
  71.     fi
  72.     mkdir $RES_DIR
  73.    
  74.     eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
  75. }
  76.  
  77. test2(){
  78.     # Check Simple Write
  79.     echo
  80.     echo "### Checking Simple Write"
  81.    
  82.     SCRIPT=${SCRIPT_FOLDER_PATH}/SimpleWrite.py
  83.     TESTS=${TEST_FOLDER_PATH}/B/
  84.     RES_DIR=${RESULT_DIR_NAME}/B/
  85.     TNUM=$1
  86.     FILE_NAME="SimpleWrite"
  87.    
  88.     if [ ! -f "${SCRIPT}" ]; then
  89.         echo "Script not found"
  90.         return
  91.     fi
  92.    
  93.     if [ -d "${RES_DIR}" ]; then
  94.         rm -rf ${RES_DIR}
  95.     fi
  96.     mkdir $RES_DIR
  97.     eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
  98. }
  99.  
  100. test3(){
  101.     # Check Complete Write
  102.     echo
  103.     echo "### Checking Complete Write"
  104.     SCRIPT=${SCRIPT_FOLDER_PATH}/CompleteWrite.py
  105.     TESTS=${TEST_FOLDER_PATH}/C/
  106.     RES_DIR=${RESULT_DIR_NAME}/C/
  107.     TNUM=$1
  108.     FILE_NAME="CompleteWrite"
  109.    
  110.     if [ ! -f "${SCRIPT}" ]; then
  111.         echo "Script not found"
  112.         return
  113.     fi
  114.    
  115.     if [ -d "${RES_DIR}" ]; then
  116.         rm -rf ${RES_DIR}
  117.     fi
  118.     mkdir $RES_DIR
  119.     eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
  120. }
  121.  
  122. test4(){
  123.     # Check Complete Read
  124.     echo
  125.     echo "### Checking Complete Read"
  126.    
  127.     SCRIPT=${SCRIPT_FOLDER_PATH}/CompleteRead.py
  128.     TESTS=${TEST_FOLDER_PATH}/D/
  129.     RES_DIR=${RESULT_DIR_NAME}/D/
  130.     TNUM=$1
  131.     FILE_NAME="CompleteRead"
  132.    
  133.     if [ ! -f "${SCRIPT}" ]; then
  134.         echo "Script not found"
  135.         return
  136.     fi
  137.    
  138.     if [ -d "${RES_DIR}" ]; then
  139.         rm -rf ${RES_DIR}
  140.     fi
  141.     mkdir $RES_DIR
  142.     eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
  143. }
  144.  
  145. test1 5
  146. test2 5
  147. test3 10
  148. test4 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement