Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if [ "$#" -ne 3 ]; then
- echo "Invalid Arguments"
- echo "Usage: script requires 3 Arguments: "
- echo " 1. Path to folder which contains following scripts with exact names:"
- echo " SimpleRead.py, SimpleWrite.py, CompleteWrite.py, CompleteRead.py"
- echo " 2. Path to folder which contains public tests(where A,B,C,D folders are located)"
- echo " 3. Path to folder where we should put output for each test"
- echo "Example: ./check.sh src/ public_tests/ result/"
- exit
- fi
- SCRIPT_FOLDER_PATH=$1
- echo "Script Folder path: $(pwd)/${SCRIPT_FOLDER_PATH}"
- TEST_FOLDER_PATH=$2
- echo "Test Folders path: $(pwd)/${TEST_FOLDER_PATH}"
- RESULT_DIR_NAME=$3
- echo "Result Directory Path: $(pwd)/${RESULT_DIR_NAME}"
- # delete Result Dir if exists
- if [ ! -d "${RESULT_DIR_NAME}" ]; then
- mkdir ${RESULT_DIR_NAME}
- fi
- echo
- echo "Starting Tests"
- echo
- compare_files(){
- SCRIPT_PATH=$1
- PTEST_DIR_NAME=$2
- RES_DIR_NAME=$3
- TNUM=$4
- FNAME=$5
- for i in $(seq 1 $TNUM);
- do
- while [ ${#i} -lt 3 ]; do
- i=0$i
- done
- CURRENT_TEST=${PTEST_DIR_NAME}${i}.dat
- CURRENT_TEST_ANS=${PTEST_DIR_NAME}${i}.ans
- DEST_FILE_NAME=${RES_DIR_NAME}/${FNAME}_${i}.txt
- # launch your python script
- eval python3 ${SCRIPT_PATH} \"$CURRENT_TEST\" $DEST_FILE_NAME
- # check if correct
- echo "Test ${i} : $(eval cmp --silent \"$CURRENT_TEST_ANS\" \"$DEST_FILE_NAME\" && echo "Success: files are same!" || echo "Failed: files are different")"
- done
- }
- test1(){
- # Check Simple Read
- echo "### Checking Simple Read"
- SCRIPT=${SCRIPT_FOLDER_PATH}/SimpleRead.py
- TESTS=${TEST_FOLDER_PATH}/A/
- RES_DIR=${RESULT_DIR_NAME}/A/
- TNUM=$1
- FILE_NAME="SimpleRead"
- if [ ! -f "${SCRIPT}" ]; then
- echo "Script not found"
- return
- fi
- if [ -d "${RES_DIR}" ]; then
- rm -rf ${RES_DIR}
- fi
- mkdir $RES_DIR
- eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
- }
- test2(){
- # Check Simple Write
- echo
- echo "### Checking Simple Write"
- SCRIPT=${SCRIPT_FOLDER_PATH}/SimpleWrite.py
- TESTS=${TEST_FOLDER_PATH}/B/
- RES_DIR=${RESULT_DIR_NAME}/B/
- TNUM=$1
- FILE_NAME="SimpleWrite"
- if [ ! -f "${SCRIPT}" ]; then
- echo "Script not found"
- return
- fi
- if [ -d "${RES_DIR}" ]; then
- rm -rf ${RES_DIR}
- fi
- mkdir $RES_DIR
- eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
- }
- test3(){
- # Check Complete Write
- echo
- echo "### Checking Complete Write"
- SCRIPT=${SCRIPT_FOLDER_PATH}/CompleteWrite.py
- TESTS=${TEST_FOLDER_PATH}/C/
- RES_DIR=${RESULT_DIR_NAME}/C/
- TNUM=$1
- FILE_NAME="CompleteWrite"
- if [ ! -f "${SCRIPT}" ]; then
- echo "Script not found"
- return
- fi
- if [ -d "${RES_DIR}" ]; then
- rm -rf ${RES_DIR}
- fi
- mkdir $RES_DIR
- eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
- }
- test4(){
- # Check Complete Read
- echo
- echo "### Checking Complete Read"
- SCRIPT=${SCRIPT_FOLDER_PATH}/CompleteRead.py
- TESTS=${TEST_FOLDER_PATH}/D/
- RES_DIR=${RESULT_DIR_NAME}/D/
- TNUM=$1
- FILE_NAME="CompleteRead"
- if [ ! -f "${SCRIPT}" ]; then
- echo "Script not found"
- return
- fi
- if [ -d "${RES_DIR}" ]; then
- rm -rf ${RES_DIR}
- fi
- mkdir $RES_DIR
- eval compare_files \"${SCRIPT}\" \"${TESTS}\" \"${RES_DIR}\" ${TNUM} ${FILE_NAME}
- }
- test1 5
- test2 5
- test3 10
- test4 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement