testing5/bf_test.sh
changeset 236 e461b5325b5e
parent 235 c989f50da5de
child 243 9bb36426c781
equal deleted inserted replaced
235:c989f50da5de 236:e461b5325b5e
     1 #!/bin/bash
     1 #!/bin/bash
     2 set -e
     2 set -e
     3 
     3 
     4 out=${1:-output}
     4 out=${1:-output}
     5 
     5 
     6 echo "" > $out
     6 echo -e "" > $out
     7 
     7 
     8 echo "Below is the feedback for your submission of CW 8, Part 2." >> $out
     8 echo -e "Below is the feedback for your submission of CW 10, Part 1." >> $out
     9 echo "" >> $out
     9 echo -e "" >> $out
    10 
    10 
    11 
    11 
    12 # compilation tests
    12 # compilation tests
    13 
    13 
    14 function scala_compile {
    14 function scala_compile {
    15   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
    15    (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala "$1" 2>> $out 1>> $out)
    16 }
    16 }
    17 
    17 
    18 # functional tests
    18 # functional tests
    19 
    19 
    20 function scala_assert {
    20 function scala_assert {
    21   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    21   (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)   
    22 }
    22 }
    23 
    23 
    24 # purity test
    24 # purity test
    25 
    25 
    26 function scala_vars {
    26 function scala_vars {
    28 }
    28 }
    29 
    29 
    30 
    30 
    31 # var, return, ListBuffer test
    31 # var, return, ListBuffer test
    32 #
    32 #
    33 echo "bf.scala does not contain vars, returns etc?" >> $out
    33 echo -e "bf.scala does not contain vars, returns etc?" >> $out
    34 
    34 
    35 if (scala_vars bf.scala)
    35 if (scala_vars bf.scala)
    36 then
    36 then
    37   echo "  --> fail" >> $out
    37   echo -e "   --> fail (make triple-sure your program conforms to the required format)" >> $out  
    38   tsts0=$(( 1 ))
    38   tsts0=$(( 0 ))
    39 else
    39 else
    40   echo "  --> success" >> $out
    40   echo -e "  --> success" >> $out
    41   tsts0=$(( 0 )) 
    41   tsts0=$(( 0 )) 
    42 fi
    42 fi
    43 
    43 
    44 
    44 
    45 # compilation test
    45 # compilation test
    46 if  [ $tsts0 -eq 0 ]
    46 if  [ $tsts0 -eq 0 ]
    47 then    
    47 then    
    48   echo "bf.scala runs?" >> $out
    48   echo -e "bf.scala runs?" >> $out
    49 
    49 
    50   if (scala_compile bf.scala)
    50   if (scala_compile bf.scala)
    51   then
    51   then
    52     echo "  --> success" >> $out
    52     echo -e "  --> success" >> $out
    53     tsts1=$(( 0 ))
    53     tsts1=$(( 0 ))
    54   else
    54   else
    55     echo "  --> scala bf.scala did not run successfully" >> $out
    55     echo -e "  -->   --> SCALA DID NOT RUN BF.SCALA\nx" >> $out
    56     tsts1=$(( 1 )) 
    56     tsts1=$(( 1 )) 
    57   fi
    57   fi
    58 else
    58 else
    59   tsts1=$(( 1 ))     
    59   tsts1=$(( 1 ))     
    60 fi
    60 fi
    61 
    61 
    62 
    62 
       
    63 ### bf tests
    63 
    64 
    64 if [ $tsts1 -eq 0 ]
    65 if [ $tsts1 -eq 0 ]
    65 then
    66 then
    66   echo " sread(Map(), 2) == 0" >> $out
    67   echo -e " load_bff(\"benchmark.bf\").length == 188" >> $out
    67   echo " sread(Map(2 -> 1), 2) == 1" >> $out  
    68   echo -e " load_bff(\"foobar.bf\") == \"\"" >> $out  
    68   echo " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
       
    69   echo " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
       
    70   
    69   
    71   if (scala_assert "bf.scala" "bf1a_test.scala")
    70   if (scala_assert "bf.scala" "bf_test1.scala")
    72   then
    71   then
    73     echo "  --> success" >> $out
    72     echo -e "  --> success" >> $out
    74   else
    73   else
    75     echo "  --> test failed" >> $out
    74     echo -e "  --> \n ONE TEST FAILED\n" >> $out
       
    75   fi
       
    76 fi
       
    77 
       
    78 if [ $tsts1 -eq 0 ]
       
    79 then
       
    80   echo -e " sread(Map(), 2) == 0" >> $out
       
    81   echo -e " sread(Map(2 -> 1), 2) == 1" >> $out  
       
    82   echo -e " write(Map(), 1, 2) == Map(1 -> 2)" >> $out
       
    83   echo -e " write(Map(1 -> 0), 1, 2) == Map(1 -> 2)" >> $out
       
    84   
       
    85   if (scala_assert "bf.scala" "bf_test2.scala")
       
    86   then
       
    87     echo -e "  --> success" >> $out
       
    88   else
       
    89     echo -e "  --> \n ONE TEST FAILED\n" >> $out
    76   fi
    90   fi
    77 fi
    91 fi
    78 
    92 
    79 
    93 
    80 
    94 
    81 if [ $tsts1 -eq 0 ]
    95 if [ $tsts1 -eq 0 ]
    82 then
    96 then
    83     echo " jumpRight(\"[******]***\", 1, 0) == 8" >> $out
    97     echo -e " jumpRight(\"[******]***\", 1, 0) == 8" >> $out
    84     echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
    98     echo -e " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
    85     echo " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
    99     echo -e " jumpRight(\"[**[*]*]***\", 1, 0) == 8" >> $out
    86     echo " jumpRight(\"[**[***]***\", 1, 0) == 11" >> $out
   100     echo -e " jumpRight(\"[**[***]***\", 1, 0) == 11" >> $out
    87     echo " jumpRight(\"[*[][]*]***\", 1, 0) == 8" >> $out
   101     echo -e " jumpRight(\"[*[][]*]***\", 1, 0) == 8" >> $out
    88     echo " jumpLeft(\"[******]***\", 6, 0) == 1" >> $out
   102     echo -e " jumpLeft(\"[******]***\", 6, 0) == 1" >> $out
    89     echo " jumpLeft(\"[******]***\", 7, 0) == -1" >> $out
   103     echo -e " jumpLeft(\"[******]***\", 7, 0) == -1" >> $out
    90     echo " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" >> $out
   104     echo -e " jumpLeft(\"[*[][]*]***\", 6, 0) == 1" >> $out
    91   
   105   
    92   if (scala_assert "bf.scala" "bf1b_test.scala")
   106   if (scala_assert "bf.scala" "bf_test3.scala")
    93   then
   107   then
    94     echo "  --> success" >> $out
   108     echo -e "  --> success" >> $out
    95   else
   109   else
    96     echo "  --> test failed" >> $out
   110     echo -e "  --> \n ONE TEST FAILED\n" >> $out   
    97   fi
   111   fi
    98 fi
   112 fi
    99 
   113 
   100 
   114 
   101 
   115 
   102 if [ $tsts1 -eq 0 ]
   116 if [ $tsts1 -eq 0 ]
   103 then
   117 then
   104   echo " start(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
   118   echo -e " run(\"[-]\", Map(0 -> 100)) == Map(0 -> 0)" >> $out
   105   echo " start(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
   119   echo -e " run(\"[->+<]\", Map(0 -> 10)) == Map(0 -> 0, 1 -> 10)" >> $out
   106   echo " start(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
   120   echo -e " run(\"[>>+>>+<<<<-]\", Map(0 -> 42)) == Map(0 -> 0, 2 -> 42, 4 -> 42)" >> $out
   107   echo " start({{hello world prg 1}}, Map()) == " >> $out
   121   echo -e " run(\"\"\"+++++[->++++++++++<]>--<+++[->>++++++++++" >> $out
   108   echo "        Map(0 -> 0, 5 -> 33, 1 -> 0, 6 -> 10, 2 -> 72, 3 -> 100, 4 -> 87)" >> $out
   122   echo -e "        <<]>>++<<----------[+>.>.<+<]\"\"\") == Map(0 -> 0, 1 -> 58, 2 -> 32)" >> $out
   109 
   123 
   110   if (scala_assert "bf.scala" "bf1c_test.scala")
   124   if (scala_assert "bf.scala" "bf_test4.scala")
   111   then
   125   then
   112     echo "  --> success" >> $out
   126     echo -e "  --> success" >> $out
   113   else
   127   else
   114     echo "  --> test failed" >> $out
   128     echo -e "  --> \n ONE TEST FAILED\n" >> $out 
   115   fi
   129   fi
   116 fi
   130 fi
   117 
   131 
   118 
   132 
   119 
   133