summaryrefslogtreecommitdiffstats
path: root/05-advanced_algorithms_and_complexity/02-linear_programming/check
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2022-03-25 09:37:06 +0100
committerJérémy Zurcher <jeremy@asynk.ch>2022-03-25 09:37:06 +0100
commit623c5d60f54c62fd50d115859cf60ea41785d5d2 (patch)
treea1a08cbd3795cab502aa53efc5de4a3dec11f447 /05-advanced_algorithms_and_complexity/02-linear_programming/check
parent7b224832b3795baaa5334f5f8f352c7aec330ae5 (diff)
downloadcoursera-623c5d60f54c62fd50d115859cf60ea41785d5d2.zip
coursera-623c5d60f54c62fd50d115859cf60ea41785d5d2.tar.gz
Algorithms : complete 05-advanced_algorithms_and_complexity 02-linear_programming
Diffstat (limited to '05-advanced_algorithms_and_complexity/02-linear_programming/check')
-rwxr-xr-x05-advanced_algorithms_and_complexity/02-linear_programming/check47
1 files changed, 47 insertions, 0 deletions
diff --git a/05-advanced_algorithms_and_complexity/02-linear_programming/check b/05-advanced_algorithms_and_complexity/02-linear_programming/check
new file mode 100755
index 0000000..b449883
--- /dev/null
+++ b/05-advanced_algorithms_and_complexity/02-linear_programming/check
@@ -0,0 +1,47 @@
+#! /bin/bash
+
+RESET="\033[0m"
+RED="\033[0;31m"
+GREEN="\033[0;32m"
+BROWN="\033[0;33m"
+
+BIN=/tmp/bin
+OUTA=/tmp/_outa
+OUTB=/tmp/_outb
+# GPP_OPTS="-std=c++11 -O0 -ggdb"
+GPP_OPTS="-std=c++11 -O2"
+
+for path in $(find . -name \*.cpp | sort); do
+ src=${path##*/}
+ dir=${path%/*}
+ echo -e "${RED}validate $BROWN$dir$RESET/$GREEN$src$RESET"
+ pushd $dir >/dev/null || exit 1
+ sed -i 's/^#define DEBUG 1/\/\/ #define DEBUG 1/' $src
+ echo -e " ${RED}compile $GREEN$src$RESET" && g++ $GPP_OPTS $src -o $BIN || exit 1
+ if [ -d tests ]; then
+ start=`date +%s.%N`
+ echo -e " ${RED}check $GREEN$src$RESET"
+ # if [ "$src" == "good.cpp" -o "$src" == "ad_allocation-new.cpp" ]; then
+ for t in $(find ./tests -name "*[^a~]"|sort); do
+ if [ -f $t -a -f "$t.a" ]; then
+ cat $t | $BIN 2>/dev/null | sed 's/\([0-9]\+\.[0-9]\{4\}\)[0-9]\+/\1/g' > $OUTA || echo "segfault"
+ cat $t.a | sed 's/\([0-9]\+\.[0-9]\{4\}\)[0-9]\+/\1/g' > $OUTB
+ cmp $OUTA $OUTB >/dev/null
+ if [ $? -ne 0 ]; then
+ echo -e " $BROWN$t$RESET is ${RED}KO$RESET"
+ # cat $OUTA
+ # cat $OUTB
+ # else
+ # echo -e " $BROWN$t$RESET is ${GREEN}ok$RESET"
+ fi
+ fi
+ done
+ end=`date +%s.%N`
+ echo "runtime : $(echo "$end - $start" | bc -l)"
+ # fi
+ else
+ echo -e " ${RED}no tests$RESET"
+ fi
+ popd > /dev/null
+done
+