summaryrefslogtreecommitdiffstats
path: root/05-advanced_algorithms_and_complexity/01-flows_in_networks/check
blob: b73ff996e44967fe5553d59ca7f84e47ea940b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#! /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 -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
    echo -e "   ${RED}compile $GREEN$src$RESET" && g++ $GPP_OPTS $src -o $BIN || exit 1
    if [ -d tests ]; then
        echo -e "   ${RED}check $GREEN$src$RESET"
        for t in $(find ./tests -name "*[^a~]"|sort); do
            if [ -f $t -a -f "$t.a" ]; then
                cat $t | $BIN > $OUTA
                cat $t.a > $OUTB
                cmp $OUTA $OUTB >/dev/null
                if [ $? -ne 0 ]; then
                    echo -e "     $BROWN$t$RESET is ${RED}KO$RESET"
                else
                    echo -e "     $BROWN$t$RESET is ${GREEN}ok$RESET"
                fi
            fi
        done
    else
        echo -e "   ${RED}no tests$RESET"
    fi
    popd > /dev/null
done