Skip to content

Commit

Permalink
Simplify grade_utils
Browse files Browse the repository at this point in the history
  • Loading branch information
erelsgl committed Mar 10, 2021
1 parent 9baed71 commit 0bd2f63
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 23 deletions.
8 changes: 6 additions & 2 deletions TestCounter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@ using namespace doctest;

const int MIN_TESTS = 20;

int return_code = -1;

struct ReporterCounter: public ConsoleReporter {
ReporterCounter(const ContextOptions& input_options)
: ConsoleReporter(input_options) {}

void test_run_end(const TestRunStats& run_stats) override {
if (run_stats.numAsserts >= MIN_TESTS) {
std::cout << 100 << std::endl;
return_code = 0;
} else {
std::cout << "Please write at least " << MIN_TESTS << " tests! " << std::endl << 0 << std::endl;
std::cout << "Please write at least " << MIN_TESTS << " tests! " << std::endl;
return_code = 1;
}
}
};
Expand All @@ -23,4 +26,5 @@ int main(int argc, char** argv) {
Context context;
context.addFilter("reporters", "counter");
context.run();
return return_code;
}
10 changes: 6 additions & 4 deletions grade
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
#!/bin/bash

source grade_utils
TIMEOUT=10
run_in_folder_if_exists "solution"
TIMEOUT=3
run_in_folder_if_exists "$1"

printf "\n\n### Cleaning old files ###\n"
make -f Makefile clean

total=0
i=0

let "i=i+1"
printf "\n\n### Check $i: our demo program should compile with your class\n"
grade_command make -f Makefile demo
printf "### Score $i: $grade\n"
Expand All @@ -28,11 +30,11 @@ total=$((total + grade))

let "i=i+1"
printf "\n\n### Check $i: you should write some new tests\n"
grade_program test
grade_command ./test
printf "### Score $i: $grade\n"
total=$((total + grade))

total=$((total / 4))
total=$((total / i))
printf "\n\nGrade: $total\n\n"

make -f Makefile --silent clean
35 changes: 18 additions & 17 deletions grade_utils
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
set -o pipefail # see https://unix.stackexchange.com/a/267031/16569
exec 2>&1 # redirect stderr to stdout: https://unix.stackexchange.com/q/505581/16569

TIMEOUT=1 # 1 second - default timeout
TIMEOUT=10 # 10 seconds - default timeout

typeset -F SECONDS
SECONDS=0
Expand All @@ -24,22 +24,6 @@ run_in_folder_if_exists() {
}



# from here: https://stackoverflow.com/a/1115909/827927
swap() {
local TMPFILE=tmp.$$
if [ -f $1 ] && [ -f $2 ]
then
mv $1 $TMPFILE && mv $2 $1 && mv $TMPFILE $2
elif [ -f $1 ]
then
mv $1 $2
elif [ -f $2 ]
then
mv $2 $1
fi
}

# A function that echoes and executes a command.
call() {
echo "! ${@/eval/}"
Expand Down Expand Up @@ -78,3 +62,20 @@ grade_program() {
fi
echo "--- $SECONDS seconds"
}



# from here: https://stackoverflow.com/a/1115909/827927
swap() {
local TMPFILE=tmp.$$
if [ -f $1 ] && [ -f $2 ]
then
mv $1 $TMPFILE && mv $2 $1 && mv $TMPFILE $2
elif [ -f $1 ]
then
mv $1 $2
elif [ -f $2 ]
then
mv $2 $1
fi
}

0 comments on commit 0bd2f63

Please sign in to comment.