-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
74 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
checker/src/main/scala/org/polystat/py2eo/checker/WriteConstructions.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package org.polystat.py2eo.checker | ||
|
||
import scala.language.postfixOps | ||
import scala.reflect.io.{File, Path, Streamable} | ||
|
||
object WriteConstructions { | ||
|
||
val filename = "constructions.html" | ||
|
||
/** Write testing results to constructions.html in the provided directory */ | ||
def apply(outputPath: Path, tests: List[AwaitedTestResult]): Unit = File(outputPath / filename) writeAll html(tests) | ||
|
||
/** Returns html file contents */ | ||
private def html(tests: List[AwaitedTestResult]): String = { | ||
lazy val stream = getClass getResourceAsStream "head.html" | ||
lazy val head = Streamable slurp stream | ||
lazy val body = s"<body>\n${table(tests)}</body>\n" | ||
|
||
s"<html lang=\"en-US\">\n$head$body</html>\n" | ||
} | ||
|
||
/** Returns full table */ | ||
private def table(tests: List[AwaitedTestResult]): String = { | ||
s"<table id=programs>\n$header${body(tests)}</table>\n" | ||
} | ||
|
||
/** Returns table header */ | ||
private def header: String = { | ||
s"<tr>\n<th class=\"sorter\">Construction</th>\n<th class=\"sorter data\">Result</th></tr>\n" | ||
} | ||
|
||
/** Returns table body */ | ||
private def body(tests: List[AwaitedTestResult]): String = { | ||
val constructions = (tests map (test => test.category)).toSet | ||
val constructionsMap = (for (c <- constructions) yield (c, tests filter (test => test.category == c))).toMap | ||
|
||
val body = for ((construction, list) <- constructionsMap) yield { | ||
val data = list.exists(test => { | ||
val sublist = test.results.getOrElse(Map.empty).values.toList | ||
sublist.contains(CompilingResult.failed) || sublist.contains(CompilingResult.nodiff) | ||
}) | ||
|
||
val cell = if (data) | ||
s"<td class=\"unexpected data\">failed</td>\n" | ||
else | ||
s"<td class=\"expected data\">passed</td>\n" | ||
|
||
s"<tr>\n<th class=\"left\">$construction</th>\n$cell</tr>\n" | ||
} | ||
|
||
body mkString | ||
} | ||
} |