| 249 |      1 | #!/bin/bash
 | 
|  |      2 | set -euo pipefail
 | 
|  |      3 | 
 | 
|  |      4 | 
 | 
|  |      5 | out=${1:-output}
 | 
|  |      6 | 
 | 
|  |      7 | echo -e "" > $out
 | 
|  |      8 | 
 | 
| 346 |      9 | echo -e "Below is the feedback for your submission postfix.scala and postfix2.scala" >> $out
 | 
| 249 |     10 | echo -e "" >> $out
 | 
|  |     11 | 
 | 
| 471 |     12 | 
 | 
| 249 |     13 | # compilation tests
 | 
|  |     14 | 
 | 
|  |     15 | function scala_compile {
 | 
| 474 |     16 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli compile -Xprint:parser "$1" 2> c$out 1> c$out)
 | 
| 249 |     17 | }
 | 
|  |     18 | 
 | 
|  |     19 | # functional tests
 | 
|  |     20 | 
 | 
|  |     21 | function scala_assert {
 | 
| 478 |     22 |   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala-cli -i "$1" "$2" -e "urbanmain()") # 2> /dev/null 1> /dev/null)
 | 
| 249 |     23 | }
 | 
|  |     24 | 
 | 
|  |     25 | # purity test
 | 
|  |     26 | function scala_vars {
 | 
| 471 |     27 |    (sed 's/immutable/ok/g' c$out > cb$out;
 | 
|  |     28 |     egrep '\bvar\b|\breturn\b|\.par\.|\.par |ListBuffer|AtomicInteger|mutable|util.control|new Array' cb$out 2> /dev/null 1> /dev/null)
 | 
| 249 |     29 | }
 | 
|  |     30 | 
 | 
|  |     31 | 
 | 
| 346 |     32 | # compilation test
 | 
|  |     33 | 
 | 
|  |     34 | echo -e "postfix.scala runs?" >> $out
 | 
|  |     35 | 
 | 
|  |     36 | if (scala_compile postfix.scala)
 | 
|  |     37 | then
 | 
| 352 |     38 |     echo -e "  --> passed" >> $out
 | 
| 346 |     39 |     tsts=$(( 0 ))
 | 
|  |     40 |   else
 | 
| 471 |     41 |       echo -e "  --> SCALA DID NOT RUN postfix.scala\n" >> $out
 | 
|  |     42 |       echo -e "  --> try running scala-cli compile postfix.scala on your own computer\n" >> $out
 | 
| 346 |     43 |     tsts=$(( 1 )) 
 | 
|  |     44 | fi
 | 
|  |     45 | 
 | 
|  |     46 | 
 | 
| 249 |     47 | # var, return, ListBuffer test
 | 
|  |     48 | #
 | 
|  |     49 | echo -e "postfix.scala does not contain vars, returns etc?" >> $out
 | 
|  |     50 | 
 | 
| 346 |     51 | if  [ $tsts -eq 0 ]
 | 
|  |     52 | then 
 | 
|  |     53 |     if (scala_vars postfix.scala)
 | 
|  |     54 |     then
 | 
|  |     55 | 	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out 
 | 
|  |     56 | 	tsts=$(( 1 ))
 | 
|  |     57 |     else
 | 
| 352 |     58 | 	echo -e "  --> passed" >> $out
 | 
| 346 |     59 | 	tsts=$(( 0 )) 
 | 
|  |     60 |     fi
 | 
| 249 |     61 | fi
 | 
|  |     62 | 
 | 
|  |     63 | 
 | 
|  |     64 | ### postfix tests
 | 
|  |     65 | 
 | 
| 346 |     66 | if [ $tsts -eq 0 ]
 | 
| 249 |     67 | then
 | 
| 250 |     68 |   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
 | 
| 249 |     69 |   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
 | 
|  |     70 |   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
 | 
| 250 |     71 |   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
 | 
| 249 |     72 |   
 | 
| 471 |     73 |   if (scala_assert "postfix.scala" "postfix_test1.scala")
 | 
| 249 |     74 |   then
 | 
|  |     75 |     echo -e "  --> success" >> $out
 | 
|  |     76 |   else
 | 
|  |     77 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out
 | 
|  |     78 |   fi
 | 
|  |     79 | fi
 | 
|  |     80 | 
 | 
|  |     81 | 
 | 
|  |     82 | 
 | 
| 346 |     83 | if [ $tsts -eq 0 ]
 | 
| 249 |     84 | then
 | 
|  |     85 |   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
 | 
|  |     86 |   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
 | 
|  |     87 |   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
 | 
|  |     88 |   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
 | 
|  |     89 |   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
 | 
|  |     90 |   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
 | 
|  |     91 |   
 | 
| 471 |     92 |   if (scala_assert "postfix.scala" "postfix_test2.scala")
 | 
| 249 |     93 |   then
 | 
|  |     94 |     echo -e "  --> success" >> $out
 | 
|  |     95 |   else
 | 
|  |     96 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out
 | 
|  |     97 |   fi
 | 
|  |     98 | fi
 | 
|  |     99 | 
 | 
| 300 |    100 | echo -e "" >> $out
 | 
| 249 |    101 | 
 | 
|  |    102 | ### postfix2 tests
 | 
|  |    103 | 
 | 
| 346 |    104 | 
 | 
|  |    105 | # compilation test
 | 
|  |    106 | 
 | 
|  |    107 | echo -e "postfix2.scala runs?" >> $out
 | 
|  |    108 | 
 | 
|  |    109 | if (scala_compile postfix2.scala)
 | 
|  |    110 | then
 | 
| 352 |    111 |     echo -e "  --> passed" >> $out
 | 
| 346 |    112 |     tsts1=$(( 0 ))
 | 
|  |    113 | else
 | 
|  |    114 |     echo -e "  --> SCALA DID NOT RUN postfix2.scala\n" >> $out
 | 
| 471 |    115 |     echo -e "  --> try running scala-cli compile postfix2.scala on your own computer\n" >> $out
 | 
| 346 |    116 |     tsts1=$(( 1 )) 
 | 
|  |    117 | fi
 | 
|  |    118 | 
 | 
|  |    119 | 
 | 
| 249 |    120 | # var, return, ListBuffer test
 | 
|  |    121 | #
 | 
|  |    122 | echo -e "\n\npostfix2.scala does not contain vars, returns etc?" >> $out
 | 
|  |    123 | 
 | 
| 346 |    124 | if [ $tsts1 -eq 0 ]
 | 
| 249 |    125 | then
 | 
| 346 |    126 |     if (scala_vars postfix2.scala)
 | 
|  |    127 |     then
 | 
|  |    128 | 	echo -e "   --> FAIL (make triple-sure your program conforms to the required format)" >> $out 
 | 
|  |    129 | 	tsts1=$(( 1 ))
 | 
|  |    130 |     else
 | 
| 352 |    131 | 	echo -e "  --> passed" >> $out
 | 
| 346 |    132 | 	tsts1=$(( 0 )) 
 | 
|  |    133 |     fi
 | 
| 249 |    134 | fi
 | 
|  |    135 | 
 | 
|  |    136 | 
 | 
|  |    137 | if [ $tsts1 -eq 0 ]
 | 
|  |    138 | then
 | 
| 250 |    139 |   echo -e " syard(split(\"3 + 4 * ( 2 - 1 )\")) == List(\"3\", \"4\", \"2\", \"1\", \"-\", \"\*\", \"+\")" >> $out
 | 
| 249 |    140 |   echo -e " syard(split(\"( ( ( 3 ) ) + ( ( 4 + ( 5 ) ) ) )\")) == List(\"3\", \"4\", \"5\", \"+\", \"+\")" >> $out
 | 
|  |    141 |   echo -e " syard(split(\"5 + 7 / 2\")) == List(\"5\", \"7\", \"2\", \"/\", \"+\")" >> $out
 | 
| 250 |    142 |   echo -e " syard(split(\"5 * 7 / 2\")) == List(\"5\", \"7\", \"\*\", \"2\", \"/\")" >> $out
 | 
| 249 |    143 |   echo -e " syard(split(\"3 + 4 * 8 / ( 5 - 1 ) ^ 2 ^ 3\")) == " >> $out
 | 
| 250 |    144 |   echo -e "         List(\"3\", \"4\", \"8\", \"\*\", \"5\", \"1\", \"-\", \"2\", \"3\", \"^\", \"^\", \"/\", \"+\")" >> $out
 | 
| 249 |    145 |   echo -e " " >> $out 
 | 
|  |    146 |   echo -e " compute(syard(split(\"3 + 4 * ( 2 - 1 )\"))) == 7" >> $out
 | 
|  |    147 |   echo -e " compute(syard(split(\"10 + 12 * 33\"))) == 406" >> $out
 | 
|  |    148 |   echo -e " compute(syard(split(\"( 5 + 7 ) * 2\"))) == 24" >> $out
 | 
|  |    149 |   echo -e " compute(syard(split(\"5 + 7 / 2\"))) == 8" >> $out
 | 
|  |    150 |   echo -e " compute(syard(split(\"5 * 7 / 2\"))) == 17" >> $out
 | 
|  |    151 |   echo -e " compute(syard(split(\"9 + 24 / ( 7 - 3 )\"))) == 15" >> $out
 | 
|  |    152 |   echo -e " compute(syard(split(\"4 ^ 3 ^ 2\"))) == 262144" >> $out
 | 
|  |    153 |   echo -e " compute(syard(split(\"4 ^ ( 3 ^ 2 )\"))) == 262144" >> $out
 | 
|  |    154 |   echo -e " compute(syard(split(\"( 4 ^ 3 ) ^ 2\"))) == 4096" >> $out
 | 
|  |    155 |   echo -e " compute(syard(split(\"( 3 + 1 ) ^ 2 ^ 3\"))) == 65536" >> $out
 | 
|  |    156 |   
 | 
| 471 |    157 |   if (scala_assert "postfix2.scala" "postfix_test3.scala")
 | 
| 249 |    158 |   then
 | 
|  |    159 |     echo -e "  --> success" >> $out
 | 
|  |    160 |   else
 | 
|  |    161 |     echo -e "  --> \n ONE TEST FAILED\n" >> $out
 | 
|  |    162 |   fi
 | 
|  |    163 | fi
 | 
|  |    164 | 
 |