main_testing2/danube_test5.scala
changeset 347 4de31fdc0d67
parent 284 9a04eb6a2291
child 379 5616b45d656f
equal deleted inserted replaced
346:663c2a9108d1 347:4de31fdc0d67
       
     1 
       
     2 // first test 
       
     3 
       
     4 import CW7b._
       
     5 
       
     6 def urban_groupById(ratings: List[(String, String)]) = 
       
     7   ratings.groupBy(_._1).view.mapValues(_.map(_._2)).toMap 
       
     8 
       
     9 def urban_get_csv_file(name: String) : List[String] = {
       
    10   import io.Source
       
    11   import scala.util._
       
    12   val csv = Source.fromFile(name)
       
    13   csv.mkString.split("\n").toList.drop(1)
       
    14 }
       
    15 
       
    16 def urban_process_ratings(lines: List[String]) : List[(String, String)] = {
       
    17   for (cols <- lines.map(_.split(",").toList); 
       
    18        if (cols(2).toFloat >= 4)) yield (cols(0), cols(1))  
       
    19 }
       
    20 
       
    21 
       
    22 val urban_good_ratings = process_ratings(urban_get_csv_file("ratings.csv"))
       
    23 
       
    24 val urban_ratings_map = urban_groupById(urban_good_ratings)
       
    25 
       
    26 assert(suggestions(urban_ratings_map, "912").length  == 4110)
       
    27 assert(suggestions(urban_ratings_map, "858").length  == 4883)
       
    28 assert(suggestions(urban_ratings_map, "260").length  == 4970)
       
    29