| author | Christian Urban <christian.urban@kcl.ac.uk> | 
| Fri, 24 Oct 2025 10:45:17 +0100 | |
| changeset 1016 | 3a431a78499d | 
| parent 977 | 7a02c5b9e0df | 
| permissions | -rw-r--r-- | 
| 
977
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
1  | 
// for testing evaluation  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
2  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
3  | 
import scala.util.{Try, Success, Failure}
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
4  | 
import $file.cw034_add  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
5  | 
import cw034_add._  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
6  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
7  | 
val str = os.read(os.pwd / "primes.while")  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
8  | 
val resmap = Map("end" -> 100, "n" -> 100, "f" -> 4, "tmp" -> 1)
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
9  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
10  | 
def mapeq[A, B](m1: Map[A, B], m2: Map[A, B]) : Boolean = {
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
11  | 
m1.keySet.forall(k => m1(k) == m2(k))  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
12  | 
}  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
13  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
14  | 
|
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
15  | 
Try(test_string(str)) match {
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
16  | 
case Success(v) if mapeq(resmap, v) => Console.println(s" Generated the correct result $v")  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
17  | 
  case Success(v) => Console.println(s"   Generated $v\n instead of\n $resmap\n.") ; throw new Exception("Different")
 | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
18  | 
case Failure(e) => Console.println(s" Exception raised.") ; throw(e)  | 
| 
 
7a02c5b9e0df
updated marking scripts
 
Christian Urban <christian.urban@kcl.ac.uk> 
parents:  
diff
changeset
 | 
19  | 
}  |