testing2/danube_test.sh
changeset 284 9a04eb6a2291
parent 283 ef5f62bf5987
equal deleted inserted replaced
283:ef5f62bf5987 284:9a04eb6a2291
    35 #
    35 #
    36 echo "danube.scala does not contain vars, returns etc?" >> $out
    36 echo "danube.scala does not contain vars, returns etc?" >> $out
    37 
    37 
    38 if (scala_vars danube.scala)
    38 if (scala_vars danube.scala)
    39 then
    39 then
    40   echo "  --> fail (make triple-sure your program conforms to the required format)" >> $out
    40   echo "  --> FAIL (make triple-sure your program conforms to the required format)" >> $out
    41   tsts0=$(( 0 ))
    41   tsts0=$(( 0 ))
    42 else
    42 else
    43   echo "  --> success" >> $out
    43   echo "  --> success" >> $out
    44   tsts0=$(( 0 )) 
    44   tsts0=$(( 0 )) 
    45 fi
    45 fi
    54   if (scala_compile danube.scala)
    54   if (scala_compile danube.scala)
    55   then
    55   then
    56     echo "  --> success" >> $out
    56     echo "  --> success" >> $out
    57     tsts=$(( 0 ))
    57     tsts=$(( 0 ))
    58   else
    58   else
    59     echo "  --> scala did not run danube.scala" >> $out
    59     echo "  --> SCALA DID NOT RUN danube.scala" >> $out
    60     tsts=$(( 1 )) 
    60     tsts=$(( 1 )) 
    61   fi
    61   fi
    62 else
    62 else
    63   tsts=$(( 1 ))     
    63   tsts=$(( 1 ))     
    64 fi
    64 fi
    71   echo "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out
    71   echo "  val movies_url = \"\"\"https://nms.kcl.ac.uk/christian.urban/movies.csv\"\"\"" >> $out
    72   echo "  get_csv_url(movies_url).length == 9742" >> $out
    72   echo "  get_csv_url(movies_url).length == 9742" >> $out
    73 
    73 
    74   if (scala_assert "danube.scala" "danube_test1.scala")
    74   if (scala_assert "danube.scala" "danube_test1.scala")
    75   then
    75   then
    76     echo "  --> success" >> $out
    76     echo -e "  --> success" >> $out
    77   else
    77   else
    78     echo "  --> one of the tests failed" >> $out
    78     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
    79   fi
    79   fi
    80 fi
    80 fi
    81 
    81 
    82 ### danube processing tests
    82 ### danube processing tests
    83 
    83 
    89   echo "  good_ratings.length == 48580 " >> $out
    89   echo "  good_ratings.length == 48580 " >> $out
    90   echo "  movie_names.length == 9742 " >> $out
    90   echo "  movie_names.length == 9742 " >> $out
    91 
    91 
    92   if (scala_assert "danube.scala" "danube_test2.scala") 
    92   if (scala_assert "danube.scala" "danube_test2.scala") 
    93   then
    93   then
    94     echo "  --> success" >> $out
    94     echo -e "  --> success" >> $out
    95   else
    95   else
    96     echo "  --> one of the tests failed" >> $out
    96     echo -e "  --> ONE OF THE TESTS FAILED\n" >> $out
    97   fi
    97   fi
    98 fi
    98 fi
    99 
    99 
       
   100 ### danube groupById test
       
   101 
       
   102 if [ $tsts -eq 0 ]
       
   103 then
       
   104   echo -e  "  val ls1 = List((\"1\", \"a\"), (\"2\", \"a\"), (\"1\", \"c\"), (\"2\", \"a\"), (\"1\", \"c\"))" >> $out
       
   105   echo -e  "  val ls2 = List((\"1\", \"a\"), (\"1\", \"b\"), (\"2\", \"x\"), (\"3\", \"a\"), (\"2\", \"y\"), (\"3\", \"c\"))" >> $out
       
   106   echo -e  "  groupById(ls1, Map()) == Map(1 -> List(c, c, a), 2 -> List(a, a))" >> $out
       
   107   echo -e  "  groupById(ls2, Map()) == Map(1 -> List(b, a), 2 -> List(x, y), 3 -> List(c, a))" >> $out
       
   108   echo -e  "      where the order in the lists is unimportant" >> $out
       
   109   echo -e  "  val ls3 = (1 to 1000).map(_.toString).toList" >> $out
       
   110   echo -e  "  val ls4 = ls3 zip ls3.tail" >> $out
       
   111   echo -e  "  val ls5 = ls4 ::: ls4.reverse" >> $out
       
   112   echo -e  "  groupById(ls5, Map()) == Map(1 -> List(2,2), 2 -> List(3,3), ....)" >> $out
       
   113 
       
   114   if (scala_assert "danube.scala" "danube_test3.scala")
       
   115   then
       
   116       echo -e  -e "  --> success" >> $out
       
   117   else
       
   118       echo -e  -e "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   119   fi
       
   120 fi
       
   121 
       
   122 ### danube favourites tests
       
   123 
       
   124 if [ $tsts -eq 0 ]
       
   125 then
       
   126   echo -e  "  val good_ratings = process_ratings(ratings)" >> $out
       
   127   echo -e  "  val ratings_map = groupById(good_ratings, Map())" >> $out
       
   128   echo -e  "  favourites(ratings_map, \"912\").length  == 80 " >> $out
       
   129   echo -e  "  favourites(ratings_map, \"858\").length  == 158 " >> $out
       
   130   echo -e  "  favourites(ratings_map, \"260\").length  == 201 " >> $out  
       
   131 
       
   132   if (scala_assert "danube.scala" "danube_test4.scala") 
       
   133   then
       
   134     echo -e  "  --> success" >> $out
       
   135   else
       
   136     echo -e  "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   137   fi
       
   138 fi
       
   139 
       
   140 ### danube suggestions tests
       
   141 
       
   142 if [ $tsts -eq 0 ]
       
   143 then
       
   144   echo -e  "  val good_ratings = process_ratings(ratings)" >> $out
       
   145   echo -e  "  val ratings_map = groupById(good_ratings, Map())" >> $out
       
   146   echo -e  "  suggestions(ratings_map, \"912\").length  == 4110 " >> $out
       
   147   echo -e  "  suggestions(ratings_map, \"858\").length  == 4883 " >> $out
       
   148   echo -e  "  suggestions(ratings_map, \"260\").length  == 4970 " >> $out  
       
   149 
       
   150   if (scala_assert "danube.scala" "danube_test5.scala") 
       
   151   then
       
   152     echo -e  "  --> success" >> $out
       
   153   else
       
   154     echo -e  "  --> ONE OF THE TESTS FAILED\n" >> $out
       
   155   fi
       
   156 fi
       
   157 
       
   158 ### danube recommendation tests
       
   159 
       
   160 if [ $tsts -eq 0 ]
       
   161 then
       
   162   echo -e  "  recommendations(ratings_map, movies_map, \"1\").length  == 2 " >> $out
       
   163   echo -e  "  recommendations(ratings_map, movies_map, \"2\").length  == 2 " >> $out
       
   164   echo -e  "  recommendations(ratings_map, movies_map, \"3\").length  == 2 " >> $out
       
   165   echo -e  "  recommendations(ratings_map, movies_map, \"4\").length  == 0 " >> $out
       
   166   echo -e  "  recommendations(ratings_map, movies_map, \"5\").length  == 2 " >> $out
       
   167 
       
   168   if (scala_assert "danube.scala" "danube_test6.scala") 
       
   169   then
       
   170     echo -e  "  --> success" >> $out
       
   171   else
       
   172     echo -e  "  --> ONE OF THE TESTS FAILED\n" >>  $out
       
   173   fi
       
   174 fi
       
   175