| author | Christian Urban <christian.urban@kcl.ac.uk> |
| Mon, 20 Oct 2025 22:18:21 +0200 | |
| changeset 1013 | 1a23d87d1700 |
| parent 978 | 8778d23fef92 |
| permissions | -rw-r--r-- |
|
978
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
1 |
// for testing tokenisation |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
2 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
3 |
import scala.util.{Try, Success, Failure}
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
4 |
import $file.cw05_add |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
5 |
import cw05_add._ |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
6 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
7 |
// programs to test (and number of toplevel definitions) |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
8 |
val uprogs = List(("fact.fun", 5),
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
9 |
("hanoi.fun", 2),
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
10 |
("mand.fun", 11),
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
11 |
("sqr.fun", 4))
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
12 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
13 |
for ((file, no) <- uprogs) {
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
14 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
15 |
print(s"Testing Parsing of $file ") |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
16 |
val str = os.read(os.pwd / file) |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
17 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
18 |
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
19 |
Try(test_string(str).length) match {
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
20 |
case Success(v) if v == no => println(s"--> Success. Parsed $no top-level definitions.") |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
21 |
case Success(v) => println(s"--> Success? Parsed $v top-level definitions (should be $no).")// ; throw new Exception("Different")
|
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
22 |
case Failure(e) => println(s"--> FAIL. Exception raised.") ; throw(e) |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
23 |
} |
|
8778d23fef92
updated marking scripts
Christian Urban <christian.urban@kcl.ac.uk>
parents:
diff
changeset
|
24 |
} |