marking1/drumb_test.sh
changeset 169 b37052895281
parent 158 94b11ac19b41
child 210 63a1376cbebd
equal deleted inserted replaced
168:03530cb87cd0 169:b37052895281
     1 #!/bin/bash
     1 #!/bin/bash
     2 set -e
     2 set -euo pipefail
       
     3 
     3 
     4 
     4 out=${1:-output}
     5 out=${1:-output}
     5 
     6 
     6 echo "" > $out
     7 echo "" > $out
     7 
     8 
     8 echo "Below is the feedback for your submission for drumb.scala" >> $out
     9 echo "Below is the feedback and provisional marks for your submission" >> $out
       
    10 echo "for assignment 6 Part 3.  Please note all marks are provisional until" >> $out
       
    11 echo "ratified by the assessment board -- this is not an official" >> $out
       
    12 echo "results transcript." >> $out
     9 echo "" >> $out
    13 echo "" >> $out
       
    14 
       
    15 # marks for CW7 part 3
       
    16 marks=$(( 0 ))
    10 
    17 
    11 # compilation tests
    18 # compilation tests
    12 
    19 
    13 function scala_compile {
    20 function scala_compile {
    14   (ulimit -t 30 -m 1024000 ; scala "$1" 2>> $out 1>> $out) 
    21     (ulimit -t 360; JAVA_OPTS="-Xmx1g" scala "$1" 2> /dev/null 1> /dev/null)
    15 }
    22 }
    16 
    23 
    17 # functional tests
    24 # functional tests
    18 
    25 
    19 function scala_assert {
    26 function scala_assert {
    20   (ulimit -t 30 -m 1024000 ; scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    27     (ulimit -t 360; JAVA_OPTS="-Xmx4g" scala -i "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
    21 }
    28 }
       
    29 
    22 
    30 
    23 # purity test
    31 # purity test
    24 
    32 
    25 function scala_vars {
    33 function scala_vars {
    26    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable' "$1" 2> /dev/null 1> /dev/null)
    34    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
    27 }
    35 }
       
    36 
    28 
    37 
    29 
    38 
    30 # var, .par return, ListBuffer test
    39 # var, .par return, ListBuffer test
    31 #
    40 #
    32 echo "drumb.scala does not contain vars, returns etc?" >> $out
    41 echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
    33 
    42 
    34 if (scala_vars drumb.scala)
    43 if (scala_vars drumb.scala)
    35 then
    44 then
    36   echo "  --> fail" >> $out
    45   echo "  --> test failed" | tee -a $out
    37   tsts0=$(( 1 ))
    46   tsts0=$(( 1 ))
    38 else
    47 else
    39   echo "  --> success" >> $out
    48   echo "  --> success" | tee -a $out
    40   tsts0=$(( 0 )) 
    49   tsts0=$(( 0 )) 
    41 fi
    50 fi
    42 
    51 
    43 
    52 
    44 # compilation test
    53 # compilation test
    45 if  [ $tsts0 -eq 0 ]
    54 if  [ $tsts0 -eq 0 ]
    46 then 
    55 then 
    47   echo "drumb.scala runs?" >> $out
    56   echo "drumb.scala runs?" | tee -a $out
    48 
    57 
    49   if (scala_compile alcohol.scala)
    58   if (scala_compile drumb.scala)
    50   then
    59   then
    51     echo "  --> success" >> $out
    60     echo "  --> success" | tee -a $out
    52     tsts=$(( 0 ))
    61     tsts=$(( 0 ))
    53   else
    62   else
    54     echo "  --> scala did not run alcohol.scala" >> $out
    63     echo "  --> scala drumb.scala did not run successfully" | tee -a $out
    55     tsts=$(( 1 )) 
    64     tsts=$(( 1 )) 
    56   fi
    65   fi
    57 else
    66 else
    58   tsts=$(( 1 ))     
    67   tsts=$(( 1 ))     
    59 fi
    68 fi
    62 
    71 
    63 ### get prices tests
    72 ### get prices tests
    64 
    73 
    65 if [ $tsts -eq 0 ]
    74 if [ $tsts -eq 0 ]
    66 then
    75 then
    67   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" >> $out
    76   echo " get_prices(List(\"BIDU\"), 2004 to 2008) ==" | tee -a $out
    68   echo "       List(List(Some(311.349976), Some(27.505054))," >> $out
    77   echo "       List(List(None), List(None), List(Some(6.35)), " | tee -a $out
    69   echo "            List(Some(300.222351), Some(42.357094))," >> $out
    78   echo "            List(Some(12.241)), List(Some(38.188)))" | tee -a $out
    70   echo "            List(Some(330.555054), Some(52.852215)))" >> $out
    79   echo " " | tee -a $out  
       
    80   echo "  get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012) ==" | tee -a $out
       
    81   echo "       List(List(Some(311.349976), Some(27.505054))," | tee -a $out
       
    82   echo "            List(Some(300.222351), Some(42.357094))," | tee -a $out
       
    83   echo "            List(Some(330.555054), Some(52.852215)))" | tee -a $out
    71 
    84 
    72   if (scala_assert "drumb.scala" "drumb_test1.scala")
    85   if (scala_assert "drumb.scala" "drumb_test1.scala")
    73   then
    86   then
    74     echo "  --> success" >> $out
    87       echo "  --> success" | tee -a $out
       
    88       marks=$(( marks + 2 ))
    75   else
    89   else
    76     echo "  --> test failed" >> $out
    90       echo "  --> test failed" | tee -a $out
    77   fi
    91   fi
    78 fi
    92 fi
    79 
    93 
    80 ### get_deltas_test
    94 ### get_deltas_test
    81 
    95 
    82 if [ $tsts -eq 0 ]
    96 if [ $tsts -eq 0 ]
    83 then
    97 then
    84   echo "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " >> $out
    98   echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
    85   echo "    List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " >> $out
    99   echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
    86   echo "         List(Some(0.10103412653643493), Some(0.2477771728154912)))" >> $out
   100   echo " " | tee -a $out  
       
   101   echo " get_deltas(prices1) == List(List(None), List(None), " | tee -a $out
       
   102   echo "                             List(Some(0.9277165354330709)), " | tee -a $out
       
   103   echo "                             List(Some(2.119679764725104)))" | tee -a $out
       
   104   echo " " | tee -a $out  
       
   105   echo " get_deltas(prices2) == List(List(Some(-0.03573992567129673), Some(0.5399749442411563)), " | tee -a $out
       
   106   echo "                             List(Some(0.10103412653643493), Some(0.2477771728154912)))" | tee -a $out
    87   
   107   
    88   if (scala_assert "drumb.scala" "drumb_test2.scala") 
   108   if (scala_assert "drumb.scala" "drumb_test2.scala") 
    89   then
   109   then
    90     echo "  --> success" >> $out
   110       echo "  --> success" | tee -a $out
       
   111       marks=$(( marks + 1 ))
    91   else
   112   else
    92     echo "  --> test failed" >> $out
   113       echo "  --> test failed" | tee -a $out
    93   fi
   114   fi
    94 fi
   115 fi
    95 
   116 
    96 
   117 
    97 ### yield_tests, investment_test
   118 ### yield_tests, investment_test
    98 
   119 
    99 if [ $tsts -eq 0 ]
   120 if [ $tsts -eq 0 ]
   100 then
   121 then
   101   echo "  yearly_yield(get_deltas(<<GOOG+AAPL 2010 - 2012>>), 100, 0) == 125" >> $out
   122   echo " val prices1 = get_prices(List(\"BIDU\"), 2004 to 2008)" | tee -a $out
   102   echo "" >> $out
   123   echo " val prices2 = get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)" | tee -a $out
   103   echo "  investment(rstate_portfolio, 1978 to 2017, 100) == 30895" >> $out
   124   echo " val prices3 = get_prices(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012)" | tee -a $out 
   104   echo "  investment(bchips_portfolio, 1978 to 2017, 100) == 349597" >> $out
   125   echo " val deltas1 = get_deltas(prices1)" | tee -a $out
       
   126   echo " val deltas2 = get_deltas(prices2)" | tee -a $out
       
   127   echo " val deltas3 = get_deltas(prices3)" | tee -a $out
       
   128   echo "" | tee -a $out
       
   129   echo " yearly_yield(deltas1, 100, 0) == 100" | tee -a $out
       
   130   echo " yearly_yield(deltas1, 100, 2) == 192" | tee -a $out
       
   131   echo " yearly_yield(deltas2, 100, 0) == 125" | tee -a $out
       
   132   echo " yearly_yield(deltas3, 100, 0) == 164" | tee -a $out
       
   133   echo " yearly_yield(deltas3, 100, 1) == 119" | tee -a $out
       
   134   echo "" | tee -a $out
       
   135   echo " val inv1 = investment(List(\"IBM\", \"BIDU\"), 2004 to 2008, 100)" | tee -a $out
       
   136   echo " val inv2 = investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2010 to 2012, 100)" | tee -a $out
       
   137   echo "" | tee -a $out
       
   138   echo " inv1 >= 295 && inv1 <= 301" | tee -a $out
       
   139   echo " inv2 >= 194 && inv2 <= 198" | tee -a $out
   105   
   140   
   106   if (scala_assert "drumb.scala" "drumb_test3.scala") 
   141   if (scala_assert "drumb.scala" "drumb_test3.scala") 
   107   then
   142   then
   108     echo "  --> success" >> $out
   143       echo "  --> success" | tee -a $out
       
   144       marks=$(( marks + 1 ))
   109   else
   145   else
   110     echo "  --> test failed" >> $out
   146       echo "  --> test failed" | tee -a $out
   111   fi
   147   fi
   112 fi
   148 fi
   113 
   149 
       
   150 
       
   151 
       
   152 ## final marks
       
   153 echo "Overall mark for CW 6, Part 3" | tee -a $out
       
   154 echo "$marks" | tee -a $out