Advertisement
Guest User

Testovaci skript FIT IOS 2017 projekt 2 (ver 3)

a guest
Apr 26th, 2017
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 5.22 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # testuje spravnou sekvenci cislovani akci a format vystupu (pouze syntax)
  4. # bez zaruky, muze obsahovat chyby
  5.  
  6. outf="proj2.out"
  7. [ $# -eq 1 ] && outf="$1" && shift
  8. [ $# -ne 0 ] && echo "Spatny pocet parametru, ocekavam zadny pak se hleda soubor proj2.out a nebo jmeno testovaneho souboru." >&2 && exit 1
  9. [ ! -f "${outf}" ] && echo "Soubor '$outf' nenalezen." >&2 && exit 1
  10.  
  11. A_MAX=$(cat "${outf}" | grep started | cut -d: -f2 | grep A | sed "s#^[^0-9]*\([0-9]*\).*#\1#g" | sort -rn | head -n1)
  12. C_MAX=$(cat "${outf}" | grep started | cut -d: -f2 | grep C | sed "s#^[^0-9]*\([0-9]*\).*#\1#g" | sort -rn | head -n1)
  13.  
  14. cat "${outf}" | sed -e "s#[\t ]##g" -e "s#:# #g" | awk '
  15. function Print_Error_Neprovedl(kdo,text) { print kdo, "jeste neprovedl akci \"", text, "\"\r\t\t\t\t\t\t\t =>", $0 >"/dev/fd/2"; }
  16. function Print_Error(text) { print text, "\r\t\t\t\t\t\t\t =>", $0 >"/dev/fd/2"; }
  17. BEGIN {
  18. A_Center=0
  19. C_Center=0
  20. A_Sum_Leave=0
  21. C_Sum_Leave=0
  22. A_Sum_Finished=0
  23. C_Sum_Finished=0
  24.  
  25. Do_Not_Enter=0
  26. Last_Adult_Enter = 0
  27. }
  28. {
  29.     id=$2
  30.     typ=substr(id,1,1)
  31.     akce=$3
  32.  
  33.     if ( akce == "started" )
  34.     {
  35.         Started[id]++
  36.         if ( Started[id] > 1 ) Print_Error("Duplicitni akce \"started\"");
  37.     } else if ( akce == "enter" )
  38.     {
  39.         Enter[id]++
  40.         if ( Started[id] == "" ) Print_Error_Neprovedl(id,"started");
  41.         else if ( Do_Not_Enter ) Print_Error( "Porusena podminka nevstupovani po \"trying to leave\"");
  42.         else if ( Enter[id] > 1 ) Print_Error("Duplicitni akce \"enter\"");
  43.         else if ( typ == "A" ) {
  44.             A_Center+=3
  45.             Last_Adult_Enter = $1
  46.         } else {
  47.             C_Center++
  48.             if ( A_Sum_Leave != '$A_MAX' ) {
  49.                 if ( C_Center > A_Center ) Print_Error("V centru jsou nehlidane deti");
  50.                 if ( Waiting[id] > Last_Adult_Enter ) Print_Error("Cekajici dite veslo driv nez vesel dalsi rodic");
  51.             }
  52.         }
  53.     }
  54.     else if ( akce == "tryingtoleave" )
  55.     {
  56.         Trying[id]++
  57.         if ( Enter[id] == "" ) Print_Error_Neprovedl( id,"enter");
  58.         else if ( Trying[id] > 1 ) Print_Error("Duplicitni akce \"trying to leave\"");
  59.         else if ( typ == "A" ) {
  60.             Do_Not_Enter++
  61.         }
  62.     }
  63.     else if ( akce == "waiting" )
  64.     {
  65.         if ( Waiting[id] > 0 ) Print_Error("Duplicitni akce \"waiting\"");
  66.         else
  67.         {
  68.             Waiting[id] = $1
  69.             if ( 3*$4 != A_Center ) Print_Error("Nesouhlasi pocet Adult v centru")
  70.             if ( $5 != C_Center )  Print_Error("Nesouhlasi pocet Child v centru")
  71.  
  72.             if ( typ == "A" ) {
  73.                 Who_Waited[id]++
  74.                 Do_Not_Enter--
  75.                 if ( A_Center > 3+C_Center ) Print_Error("Adult ceka v centru a nemusi");  
  76.             } else {
  77.                 if ( Started[id] == "" ) Print_Error_Neprovedl( id,"started");         
  78.                 if ( A_Center > C_Center ) print id,"ceka pred centrem a nemusi (", A_Center, ">" , C_Center ,")\t\t =>", $0 >"/dev/fd/2";
  79.                 if ( '$A_MAX' == A_Sum_Leave ) Print_Error("Child ceka pred centrem a adult uz neprijde");
  80.             }
  81.         }
  82.     }
  83.     else if ( akce == "leave" )
  84.     {
  85.         Leave[id]++
  86.         if ( Trying[id] == "" ) Print_Error_Neprovedl(id,"trying to leave");
  87.         else if ( Leave[id] > 1 ) Print_Error("Duplicitni akce \"leave\"");
  88.         else if ( typ == "A" ) {
  89.             A_Sum_Leave++
  90.             A_Center-=3
  91.             if ( C_Center > A_Center ) Print_Error("V centru jsou nehlidane deti");
  92.             if ( Who_Waited[id] == 0 ) Do_Not_Enter--
  93.         } else {
  94.             C_Sum_Leave++
  95.             C_Center--
  96.         }
  97.     }
  98.     else if ( akce == "finished" )
  99.     {
  100.         if ( Leave[id] == "" ) Print_Error_Neprovedl(id,"leave");
  101.         if ( A_Sum_Leave != '$A_MAX' ) Print_Error( "Nektere adult jeste neopustili centrum");
  102.         if ( C_Sum_Leave != '$C_MAX' ) Print_Error( "Nektere child jeste neopustili centrum");  
  103.         if ( typ == "A" ) A_Sum_Finished++; else C_Sum_Finished++;
  104.  
  105.     } else
  106.     {
  107.         print "wtf akce =",akce,"?\t =>", $0 >"/dev/fd/2";
  108.     }
  109. }
  110. END {
  111.     if ( '$A_MAX' != A_Sum_Finished ) { print "Rozdilny pocet startujicich a ukoncenych adult\n" >"/dev/fd/2"; }
  112.     if ( '$C_MAX' != C_Sum_Finished ) { print "Rozdilny pocet startujicich a ukoncenych child\n" >"/dev/fd/2"; }
  113. }'
  114.  
  115. tr -d " \t" < "${outf}" > $$
  116.  
  117. # test cislovani akci
  118. # tiskne radky s chybnym cislovanim
  119. cat $$ | awk -F":" ' { c++; if (c != $1) print NR, "\t => ", $1, " : chyba v cislovani akci"; } '
  120.  
  121. declare -a lines
  122.  lines[0]='^[1-9][0-9]*:C[1-9][0-9]*:started$'
  123.  lines[1]='^[1-9][0-9]*:C[1-9][0-9]*:waiting:[0-9][0-9]*:[0-9][0-9]*$'
  124.  lines[2]='^[1-9][0-9]*:C[1-9][0-9]*:enter$'
  125.  lines[3]='^[1-9][0-9]*:C[1-9][0-9]*:tryingtoleave$'
  126.  lines[4]='^[1-9][0-9]*:C[1-9][0-9]*:leave$'
  127.  lines[5]='^[1-9][0-9]*:C[1-9][0-9]*:finished$'
  128.  lines[6]='^[1-9][0-9]*:A[1-9][0-9]*:started$'
  129.  lines[7]='^[1-9][0-9]*:A[1-9][0-9]*:enter$'
  130.  lines[8]='^[1-9][0-9]*:A[1-9][0-9]*:tryingtoleave$'
  131.  lines[9]='^[1-9][0-9]*:A[1-9][0-9]*:waiting:[0-9][0-9]*:[0-9][0-9]*$'
  132. lines[10]='^[1-9][0-9]*:A[1-9][0-9]*:leave$'
  133. lines[11]='^[1-9][0-9]*:A[1-9][0-9]*:finished$'
  134.  
  135. # kontrola sytaxe vystupu
  136. # vytiskne radky, ktere neodpovidaji formatu vytupu
  137. echo "=== radky, ktere neodpovidaji formatu vystupu"
  138.  
  139. for i in `seq 0 11`
  140. do
  141.     echo "/${lines[$i]}/d" >> $$-sed
  142. done
  143.  
  144. sed -f $$-sed $$
  145.  
  146. # kontrola chybejicich vystupu
  147. # tiskne informaci, ktery text ve vystupu chybi
  148. echo "=== chybejici vystupy"
  149. echo ">> chybejici waiting nemusi nutne znamenat chybu, za urcitych okolnosti nemusi ve vystupu byt <<"
  150.  
  151. for i in `seq 0 11`
  152. do
  153.     cat $$ | grep "${lines[$i]}" >/dev/null || echo "${lines[$i]}"
  154. done
  155.  
  156.  
  157. rm $$*
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement