summaryrefslogtreecommitdiffstats
path: root/05-advanced_algorithms_and_complexity/02-linear_programming/03-ad_allocation/check
blob: 1f7160a8792c7167a7cf2aa18ae4eea2e8d6e217 (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
39
40
#! /bin/bash

RESET="\033[0m"
RED="\033[0;31m"
GREEN="\033[0;32m"
BROWN="\033[0;33m"

GPP_OPTS="-std=c++11 -O0 -ggdb"
#GPP_OPTS="-std=c++11 -O2"

binaries=()

for src in $(find . -name \*.cpp | sort)
do
  bin=/tmp/${src##*/}.bin
  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
  binaries+=("$bin")
done

for t in "$@"
do
  tf="./tests/$t"
  echo -en "$GREEN*****$RESET try $RED$t$RESET ...\n$BROWN>$RESET\n"
  # cat "$tf"
  cat "$tf.a"
  cat "$tf.a" | sed 's/\([0-9]\+\.[0-9]\{4\}\)[0-9]\+/\1/g' > "/tmp/$t.a"
  for bin in ${binaries[@]}
  do
    echo -en "$BROWN> $bin$RESET\n"
    cat "$tf" | "$bin" 2>"${bin}-${t}-steps" | sed 's/\([0-9]\+\.[0-9]\{4\}\)[0-9]\+/\1/g' > "${bin}-${t}-out"
    cmp "/tmp/$t.a" "${bin}-${t}-out" >/dev/null
    if [ $? -ne 0 ]; then
      echo -e "     $BROWN$t$RESET is ${RED}KO$RESET"
      # cat "${bin}-${t}-out"
    else
      echo -e "     $BROWN$t$RESET is ${GREEN}ok$RESET"
    fi
  done
done