main_testing2/danube_test4.scala
changeset 347 4de31fdc0d67
parent 284 9a04eb6a2291
child 379 5616b45d656f
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_testing2/danube_test4.scala	Mon Nov 02 02:31:44 2020 +0000
@@ -0,0 +1,29 @@
+
+// first test 
+
+import CW7b._
+
+def urban_groupById(ratings: List[(String, String)]) = 
+  ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap 
+
+def urban_get_csv_file(name: String) : List[String] = {
+  import io.Source
+  import scala.util._
+  val csv = Source.fromFile(name)
+  csv.mkString.split("\n").toList.drop(1)
+}
+
+def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
+  for (cols <- lines.map(_.split(",").toList); 
+       if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
+}
+
+
+val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
+
+val urban_ratings_map = urban_groupById(urban_good_ratings)
+
+assert(favourites(urban_ratings_map, "912").length  == 80)
+assert(favourites(urban_ratings_map, "858").length  == 158)
+assert(favourites(urban_ratings_map, "260").length  == 201)
+