From 0eda296787ffc44a5867aeb0a01542640e46bd10 Mon Sep 17 00:00:00 2001
From: Vytor Calixto <vytorcalixto@gmail.com>
Date: Fri, 9 Jun 2017 01:59:43 -0300
Subject: [PATCH] Muda os testes (de novo)

---
 .gitlab-ci.yml    | 73 +++++++++++++++++++++++++++++++++++++++++++++--
 Makefile          |  6 ----
 tests/runTests.sh | 58 ++++++++++++++++++-------------------
 3 files changed, 98 insertions(+), 39 deletions(-)

diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
index dffaf75..e73fae9 100644
--- a/.gitlab-ci.yml
+++ b/.gitlab-ci.yml
@@ -6,11 +6,78 @@ before_script:
     - apt-get -y install build-essential make autoconf gcc gnuplot
     - make
 
-test:
+h1:
     stage: test
-    script:
-        - make test
+    script: 
         - cd tests
+        - gcc -std=c99 -o test geraMapa.c
+        - chmod +x runTests.sh
+        - ./runTests.sh -h "./floodit_h1"
+        - gnuplot "tempos.plot"
+        - gnuplot "medias.plot"
+        - gnuplot "piores.plot"
+    artifacts:
+        paths:
+            - tests/tabuleiros.txt
+            - tests/tempos.txt
+            - tests/medias.txt
+            - tests/piores.txt
+            - tests/tempos.png
+            - tests/medias.png
+            - tests/piores.png
+    tags:
+        - ubuntu
+h2:
+    stage: test
+    script: 
+        - cd tests
+        - gcc -std=c99 -o test geraMapa.c
+        - chmod +x runTests.sh
+        - ./runTests.sh -h "./floodit_h2"
+        - gnuplot "tempos.plot"
+        - gnuplot "medias.plot"
+        - gnuplot "piores.plot"
+    artifacts:
+        paths:
+            - tests/tabuleiros.txt
+            - tests/tempos.txt
+            - tests/medias.txt
+            - tests/piores.txt
+            - tests/tempos.png
+            - tests/medias.png
+            - tests/piores.png
+    tags:
+        - ubuntu
+
+h4:
+    stage: test
+    script: 
+        - cd tests
+        - gcc -std=c99 -o test geraMapa.c
+        - chmod +x runTests.sh
+        - ./runTests.sh -h "./floodit_h4"
+        - gnuplot "tempos.plot"
+        - gnuplot "medias.plot"
+        - gnuplot "piores.plot"
+    artifacts:
+        paths:
+            - tests/tabuleiros.txt
+            - tests/tempos.txt
+            - tests/medias.txt
+            - tests/piores.txt
+            - tests/tempos.png
+            - tests/medias.png
+            - tests/piores.png
+    tags:
+        - ubuntu
+
+h6:
+    stage: test
+    script: 
+        - cd tests
+        - gcc -std=c99 -o test geraMapa.c
+        - chmod +x runTests.sh
+        - ./runTests.sh -h "./floodit_h6"
         - gnuplot "tempos.plot"
         - gnuplot "medias.plot"
         - gnuplot "piores.plot"
diff --git a/Makefile b/Makefile
index 1f81904..6871ea6 100644
--- a/Makefile
+++ b/Makefile
@@ -4,12 +4,6 @@ CFLAGS = -std=c99 -O2 -W -Wall -g
 
 all: main
 
-test: main
-	cd tests; \
-	$(CC) -std=c99 -o test geraMapa.c; \
-	chmod +x runTests.sh; \
-	./runTests.sh
-
 main: main.c libs/jogador.o libs/tabuleiro.o libs/grafo.o libs/vertice.o libs/filha.o libs/lista.o libs/no.o
 	$(CC) $(CFLAGS) -o $@ $^ -lm
 
diff --git a/tests/runTests.sh b/tests/runTests.sh
index 2944336..bc517cd 100755
--- a/tests/runTests.sh
+++ b/tests/runTests.sh
@@ -1,10 +1,29 @@
 #!/bin/bash
 
+OPTIND=1
+MAIN="../main"
+HEUR="./floodit_h6"
+
+while getopts ":m:h:" opt; do
+    case "$opt" in
+        m)  MAIN=$OPTARG
+            ;;
+        h)  HEUR=$OPTARG
+            ;;
+    esac
+done
+
+shift $((OPTIND-1))
+[ "$1" = "--" ] && shift
+
+echo $MAIN
+echo $HEUR
+
 # tempo máximo para executar, em milisegundos
 tempo_max=120000 #120s
 
 # tamanhos do tabuleiro
-tams=(3 4 8 16 32 64 100)
+tams=(32 64 100)
 
 # lista de cores
 cores=(2 3 4 6 8 10)
@@ -41,34 +60,16 @@ do
             # echo "Usando semente: ${semente}"
             ./test $i $i $cor $semente
             T_inicial=$(date +%s%N)
-            ../main < "/tmp/${semente}.in" > /tmp/resp.out
+            eval $MAIN < "/tmp/${semente}.in" > /tmp/resp.out
             T_gasto=$(($(date +%s%N) - $T_inicial))
             T_soma_cor=$(($T_gasto + $T_soma_cor))
             T_soma_total=$(($T_gasto + $T_soma_total))
-            ./floodit_h1 < "/tmp/${semente}.in" > /tmp/h1.out
-            ./floodit_h2 < "/tmp/${semente}.in" > /tmp/h2.out
-            ./floodit_h4 < "/tmp/${semente}.in" > /tmp/h4.out
-            ./floodit_h6 < "/tmp/${semente}.in" > /tmp/h6.out
-            RESP=$(cat /tmp/resp.out | head -n1)
-            H1=$(cat /tmp/h1.out | tail -n2 | head -n1)
-            H2=$(cat /tmp/h2.out | tail -n2 | head -n1)
-            H4=$(cat /tmp/h4.out | tail -n2 | head -n1)
-            H6=$(cat /tmp/h6.out | tail -n2 | head -n1)
-            if [ $RESP -gt $H1 ]; then
-                echo -ne "${RED}Heurística h1 fez tabuleiro ${i} ${i} ${cor} ${semente} em ${H1} e nós em ${RESP}${NC}\n"
-                echo "${i} ${i} ${cor} ${semente} (h1: ${H1})" >> tabuleiros.txt
-            fi
-            if [ $RESP -gt $H2 ]; then
-                echo -ne "${RED}Heurística h2 fez tabuleiro ${i} ${i} ${cor} ${semente} em ${H2} e nós em ${RESP}${NC}\n"
-                echo "${i} ${i} ${cor} ${semente} (h2: ${H2})" >> tabuleiros.txt
-            fi
-            if [ $RESP -gt $H4 ]; then
-                echo -ne "${RED}Heurística h4 fez tabuleiro ${i} ${i} ${cor} ${semente} em ${H4} e nós em ${RESP}${NC}\n"
-                echo "${i} ${i} ${cor} ${semente} (h4: ${H4})" >> tabuleiros.txt
-            fi
-            if [ $RESP -gt $H6 ]; then
-                echo -ne "${RED}Heurística h6 fez tabuleiro ${i} ${i} ${cor} ${semente} em ${H6} e nós em ${RESP}${NC}\n"
-                echo "${i} ${i} ${cor} ${semente} (h6: ${H6})" >> tabuleiros.txt
+            eval $HEUR < "/tmp/${semente}.in" > /tmp/heur.out
+            RESP=$(cat /tmp/resp.out | tail -n2 | head -n1)
+            HRESP=$(cat /tmp/heur.out | tail -n2 | head -n1)
+            if [ $RESP -gt $HRESP ]; then
+                echo -ne "${RED}Heurística ${HEUR} fez tabuleiro ${i} ${i} ${cor} ${semente} em ${HRESP} e nós em ${RESP}${NC}\n"
+                echo "${i} ${i} ${cor} ${semente} (${H1})" >> tabuleiros.txt
             fi
             # tempo em segundos
             S=$(($T_gasto/1000000000))
@@ -84,10 +85,7 @@ do
             # fi
             rm "/tmp/${semente}.in"
             rm "/tmp/resp.out"
-            rm "/tmp/h1.out"
-            rm "/tmp/h2.out"
-            rm "/tmp/h4.out"
-            rm "/tmp/h6.out"
+            rm "/tmp/heur.out"
         done
         T_medio_cor=$(($T_soma_cor/${N_TESTES}))
         S_medio_cor=$(($T_medio_cor/1000000000))
-- 
GitLab