marking1/drumb_test2.sh
changeset 260 b4812c877b05
child 261 8997430d9765
equal deleted inserted replaced
259:43995ea34fe7 260:b4812c877b05
       
     1 #!/bin/bash
       
     2 set -euo pipefail
       
     3 
       
     4 
       
     5 out=${1:-output}
       
     6 
       
     7 echo "Below is the feedback and provisional marks for your submission" >> $out
       
     8 echo "for assignment 6 Advanced Part 3.  Please note all marks are provisional until" >> $out
       
     9 echo "ratified by the assessment board -- this is not an official" >> $out
       
    10 echo "results transcript." >> $out
       
    11 echo "" >> $out
       
    12 
       
    13 # marks for CW6 part 3
       
    14 marks=$(( 0 ))
       
    15 
       
    16 
       
    17 # compilation tests
       
    18 
       
    19 function scala_compile {
       
    20     (ulimit -t 30; JAVA_OPTS="-Xmx1g" scala -nc "$1" 2> /dev/null 1> /dev/null)
       
    21 }
       
    22 
       
    23 # functional tests
       
    24 
       
    25 function scala_assert {
       
    26     (ulimit -t 30; JAVA_OPTS="-Xmx4g" scala -i -nc "$1" "$2" -e "" 2> /dev/null 1> /dev/null)
       
    27 }
       
    28 
       
    29 
       
    30 # purity test
       
    31 
       
    32 function scala_vars {
       
    33    (egrep '\bvar\b|\breturn\b|\.par|ListBuffer|mutable|new Array' "$1" 2> /dev/null 1> /dev/null)
       
    34 }
       
    35 
       
    36 
       
    37 
       
    38 # var, .par return, ListBuffer test
       
    39 #
       
    40 echo "drumb.scala does not contain vars, returns, Arrays, ListBuffers etc?" | tee -a $out
       
    41 
       
    42 if (scala_vars drumb.scala)
       
    43 then
       
    44   echo "  --> test failed" | tee -a $out
       
    45   tsts0=$(( 1 ))
       
    46 else
       
    47   echo "  --> success" | tee -a $out
       
    48   tsts0=$(( 0 )) 
       
    49 fi
       
    50 
       
    51 
       
    52 # compilation test
       
    53 if  [ $tsts0 -eq 0 ]
       
    54 then 
       
    55   echo "drumb.scala runs?" | tee -a $out
       
    56 
       
    57   if (scala_compile drumb.scala)
       
    58   then
       
    59     echo "  --> success" | tee -a $out
       
    60     tsts=$(( 0 ))
       
    61   else
       
    62     echo "  --> scala drumb.scala did not run successfully" | tee -a $out
       
    63     tsts=$(( 1 )) 
       
    64   fi
       
    65 else
       
    66   tsts=$(( 1 ))     
       
    67 fi
       
    68 
       
    69 
       
    70 ### get_delta test
       
    71 
       
    72 if [ $tsts -eq 0 ]
       
    73 then
       
    74   echo "  get_delta(None, None) == None" | tee -a $out
       
    75   echo "  get_delta(Some(100.0), None) == None" | tee -a $out
       
    76   echo "  get_delta(None, Some(50.0)) == None" | tee -a $out
       
    77   echo "  get_delta(Some(100.0), Some(50.0)) == Some(1.0)" | tee -a $out
       
    78 
       
    79   if (scala_assert "drumb.scala" "drumb_test4.scala")
       
    80   then
       
    81       echo "  --> success" | tee -a $out
       
    82       marks=$(( marks + 1 ))
       
    83   else
       
    84       echo "  --> test failed" | tee -a $out
       
    85   fi
       
    86 fi
       
    87 
       
    88 
       
    89 ### get_deltas_test
       
    90 
       
    91 if [ $tsts -eq 0 ]
       
    92 then
       
    93   echo -e "  get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012)) == " | tee -a $out
       
    94   echo -e "    List(List(Some(-0.03573992567129673), Some(0.539975124774038)), " | tee -a $out
       
    95   echo -e "         List(Some(0.10103412653643493), Some(0.24777709700099845)))" | tee -a $out
       
    96   echo -e "" | tee -a $out
       
    97   echo -e "  get_deltas(get_prices(List(\"BIDU\"), 2004 to 2008)) == " | tee -a $out
       
    98   echo -e "    List(List(None), List(None),                          " | tee -a $out
       
    99   echo -e "         List(Some(0.9277165354330709)), List(Some(2.119679764725104)))) " | tee -a $out
       
   100   
       
   101   if (scala_assert "drumb.scala" "drumb_test5.scala") 
       
   102   then
       
   103      echo -e "  --> success" | tee -a $out
       
   104      marks=$(( marks + 1 ))
       
   105   else
       
   106      echo "  --> test failed" | tee -a $out
       
   107   fi
       
   108 fi
       
   109 
       
   110 
       
   111 ### yield_tests
       
   112 
       
   113 if [ $tsts -eq 0 ]
       
   114 then
       
   115   echo -e "  val ds = get_deltas(get_prices(List(\"GOOG\", \"AAPL\"), 2010 to 2012))" | tee -a $out
       
   116   echo -e "  yearly_yield(get_deltas(ds, 100, 0) == 125" | tee -a $out
       
   117   echo -e "  yearly_yield(get_deltas(ds, 100, 1) == 117" | tee -a $out
       
   118   
       
   119   if (scala_assert "drumb.scala" "drumb_test6.scala") 
       
   120   then
       
   121       echo -e "  --> success" | tee -a $out
       
   122       marks=$(( marks + 1 ))
       
   123   else
       
   124       echo "  --> test failed" | tee -a $out
       
   125   fi
       
   126 fi
       
   127 
       
   128 
       
   129 ### investment_test
       
   130 
       
   131 if [ $tsts -eq 0 ]
       
   132 then
       
   133   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2000, 100) == 100"   | tee -a $out
       
   134   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2001, 100) == 27 "   | tee -a $out
       
   135   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2002, 100) == 42 "   | tee -a $out
       
   136   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2003, 100) == 27 "   | tee -a $out
       
   137   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2004, 100) == 38 "   | tee -a $out
       
   138   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2005, 100) == 113"   | tee -a $out
       
   139   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2006, 100) == 254"   | tee -a $out
       
   140   echo -e "  investment(List(\"GOOG\", \"AAPL\", \"BIDU\"), 2000 to 2007, 100) == 349"   | tee -a $out
       
   141   
       
   142   if (scala_assert "drumb.scala" "drumb_test7.scala") 
       
   143   then
       
   144       echo -e "  --> success" | tee -a $out
       
   145       marks=$(( marks + 1 ))
       
   146   else
       
   147       echo "  --> test failed" | tee -a $out
       
   148   fi
       
   149 fi
       
   150 
       
   151 
       
   152 
       
   153 ## final marks
       
   154 echo "Overall mark for CW 6, Part 3" | tee -a $out
       
   155 echo "$marks" | tee -a $out