marking1/alcohol_test2.scala
author Christian Urban <urbanc@in.tum.de>
Fri, 30 Nov 2018 08:46:02 +0000
changeset 224 42d760984496
parent 158 94b11ac19b41
permissions -rw-r--r--
updated
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
158
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     1
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     2
import io.Source
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     3
import scala.util._
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     4
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     5
val file_population_test = "population.csv"
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     6
val file_alcohol_test = "alcohol.csv"
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     7
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     8
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
     9
def get_csv_file_test(file: String) : List[String] = 
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    10
  Source.fromFile(file)("ISO-8859-1").getLines.toList
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    11
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    12
val alcs_test = get_csv_file_test(file_alcohol_test)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    13
val pops_test = get_csv_file_test(file_population_test)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    14
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    15
assert(CW6b.process_alcs(alcs_test.drop(1))(0) == ("Afghanistan", 0.0))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    16
assert(CW6b.process_alcs(alcs_test.drop(1))(1) == ("Albania", 4.9))
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    17
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    18
assert(CW6b.process_pops(pops_test.drop(1))("Micronesia") == 104015)
94b11ac19b41 updated
Christian Urban <urbanc@in.tum.de>
parents:
diff changeset
    19
assert(CW6b.process_pops(pops_test.drop(1))("Albania") == 2889104)