Assignment
Assignment
1. Overview
Suppose you have recently joined as a teacher at an engineering university. You are in charge of evaluating an Algorithm assignment that
students have submitted via elms. After downloading the submission files, you are in awe! No matter how many times you have reminded them
to submit their files following a standard, some students paid no attention to that. Now you have to organize the submissions and execute them.
Luckily, you are an expert in bash scripting. You will use your expertise to automate these tasks and save your precious time.
Inside the submissions folder, there will be multiple zipped files – one zipped file for each student (see the helping materials section to unzip).
Inside the zipped file are the files submitted by the student. The name of the zipped file will be in the following format:
Students will submit codes in C (.c extension), Python (.py extension), and Java (.java extension). It is guaranteed that one student has
submitted only one code file, either in C or Python or Java. There may be other files ending in different extensions. You have to ignore those
extra files. The code file of a student can be located inside any directory/subdirectory of the zipped file of the student.
You have to create a new target directory (targets). Inside the target directory, there will be three subdirectories - C, Python, Java.
Suppose, student 011212XXX has written his/her code in C. You have to create a new subdirectory inside <target
directory>/C/011212XXX and copy the C file inside <target directory>/C/011212XXX and rename it to main.c.
Suppose, student 011212XXX has written his/her code in Java. You have to create a new subdirectory inside <target
directory>/Java/011212XXX and copy the .java file inside <target directory>/Java/011212XXX and rename it to [Link].
Suppose, student 011212XXX has written his/her code in Python. You have to create a new subdirectory inside
<target directory>/Python/011212XXX and copy the .py file inside <target directory>/Python/011212XXX and rename it to [Link].
Refer to the Match/targets directory that has been provided to better understand the task.
Inside the test case folder (tests), test cases are stored in the pattern of [Link], [Link], …, [Link] and so on. They are guaranteed to
follow such naming conventions.
For each test file, there will also be an accepted answer file inside the answer folder (answers), stored in the pattern of [Link], [Link], …,
[Link] and so on. They are also guaranteed to follow such naming conventions.
Your task is to compile and run the codes you have organized. Note that Python codes do not require compiling. Refer to the helping materials
section to compile and run the code files.
You have to store the output files of each test case inside the student’s folder inside the organized target folder. The output files will follow the
naming convention of [Link], [Link], …, [Link] and so on.
Then, you will match the output files with the corresponding answer files using the command diff. If there are any mismatches between an
output file and an answer file, it will be considered as a failure in that test case.
Finally you have to generate a CSV file (inside <target directory>, named [Link]) having columns, student_id, type, matched,
not_matched. For each student you have to record his/her student ID, his/her programming language (C/Python/Java), number of test cases
matched and number of test cases that did not match.
Tentative Algorithm: (obviously, there are rooms for improvement in this algorithm)
For each student
Find the code file type (C/Python/Java)
Compile if needed
For each test cases test<i>.txt
Run the code file
Store the output in out<i>.txt
Match out<i>.txt with corresponding ans<i>.txt file
Record how many test cases matched, how many not matched
Generate a CSV file <target directory>/[Link]
4. Example
Download the “[Link]” file from elms. After unzipping it, you will find two folders and the following
subdirectories.
➔ Workspace
◆ submissions # submission folder
◆ tests # test input folder
● [Link]
● [Link]
● …
● [Link]
◆ answers # accepted output folder
● [Link]
● [Link]
● …
● [Link]
➔ Match
◆ targets # this will not be provided during evaluation
● C # student who submitted C code
○ 011212096
◆ main.c
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ 011212097
○ …
● Python # student who submitted Python code
○ 011223045
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ …
● Java # student who submitted Java code
○ 011223075
◆ [Link]
◆ [Link]
◆ [Link]
◆ …
◆ [Link]
○ …
● [Link] # result of each student
You aim to write a shell script ([Link]) that will be executed inside the Workspace directory. The script will take 4 mandatory arguments
and 1 optional argument.
Sample commands:
After executing the [Link] file, it will generate a new folder inside the Workspace directory named targets. Your script must generate
Workspace/targets identical to the Match/targets directory.
5. Additional Information
● Each Java file is guaranteed to have Main as the main class.
● Each code is guaranteed to compile and run without error/exception.
● You must generate a CSV file following the exact format that is provided. Order of student ID does not matter. The names of the
columns must match.
● You must generate executable files, output files following the format. The evaluation will be done by a script and failure to follow the
format will result in a penalty.
● If the number of arguments is less than the required number, you must print a usage message showing how to use the script.
6. Helping Materials
Unzipping
● Use the command unzip to unzip files.
● Use -d switch to unzip to a specific folder.
● Refer to the man unzip for more.
● Test the command in the terminal before using it inside the script.
string=[Link]
echo ${string%.world}
string=[Link]
echo ${string:2:1}
echo ${string:2:2}
echo ${string:2:20}
echo ${string: -1} # mind the space before - sign
echo ${string: -4}
echo ${string:2: -1}
Run a C File
● gcc file_name.c -o executable_name
● ./executable_name
7. Marks Distribution
Match Outputs 10
Generate CSV 10
-noexecute No Execute 10
Usage Message 5
Total 100
8. Submission
10. Acknowledgement
Md. Tareq Mahmood
Assistant Professor, dept of CSE, BUET.