#!/bin/csh -f

set i=1
set max_test_nr=29
set total=0
set max_total=0
set grade_file=grade.txt
set score=(4 4 4 4 4 2 3 6 4 2 3 3 6 4 4 4 1 1 4 2 1 1 4 2 3 5 5 5 5)

if (-e ${grade_file}) then
    rm -f ${grade_file}
endif
echo "" > ${grade_file}
echo "**************" >> ${grade_file}
echo " Score for P4" >> ${grade_file}
echo "**************" >> ${grade_file}
echo "" >> ${grade_file}
echo "" >> ${grade_file}

while (${i} <= ${max_test_nr} )
  
    ./test.csh $i
    if ($status != 0) then
       echo "Test ${i}: 0 / $score[$i]" >> ${grade_file}
    else
       echo "Test ${i}: $score[$i] / $score[$i]" >> ${grade_file}
       set total=`expr ${total} + $score[$i]`
    endif
    set max_total=`expr ${max_total} + $score[$i]`
    set i=`expr ${i} + 1`
end

set max_total=`echo "scale=20; a=${max_total}; scale=0; b=a/1; if (a<b+0.5) b else b+1" | bc -l;`
set total=`echo "scale=20; a=${total}; scale=0; b=a/1; if (a<b+0.5) b else b+1" | bc -l;`

echo "" >> ${grade_file}
echo "" >> ${grade_file}
echo "------------------" >> ${grade_file}
echo "Total  : ${total} / ${max_total} " >> ${grade_file}
echo "------------------" >> ${grade_file}
