-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor Check & Initial set for Json (#12)
- Loading branch information
1 parent
5c879de
commit b5e4b50
Showing
5 changed files
with
87 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package fhetest.Checker | ||
|
||
trait CheckResult { | ||
val results: List[BackendResultPair] | ||
override def toString: String = { | ||
val className = this.getClass.getSimpleName.replace("$", "") | ||
val resultStrings = results.map { | ||
case BackendResultPair(backendName, executeResult) => | ||
s"\n- $backendName:\n ${executeResult.toString}" | ||
} | ||
s"[$className] ${resultStrings.mkString("")}" | ||
} | ||
} | ||
case class Same(results: List[BackendResultPair]) extends CheckResult | ||
case class Diff(results: List[BackendResultPair]) extends CheckResult | ||
case class ParserError(results: List[BackendResultPair]) extends CheckResult |
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,29 @@ | ||
package fhetest.Checker | ||
|
||
import fhetest.Utils.* | ||
|
||
trait ExecuteResult | ||
case class Normal(res: String) extends ExecuteResult { | ||
override def toString: String = res | ||
} | ||
case object InterpError extends ExecuteResult | ||
case object PrintError extends ExecuteResult | ||
case class LibraryError(msg: String) extends ExecuteResult { | ||
override def toString: String = s"LibraryError: $msg" | ||
} | ||
case object ParseError extends ExecuteResult | ||
// case object TimeoutError extends ExecuteResult //TODO: development | ||
// case object Throw extends ExecuteResult | ||
|
||
case class BackendResultPair(backend: String, result: ExecuteResult) | ||
|
||
def isDiff( | ||
expected: BackendResultPair, | ||
obtained: BackendResultPair, | ||
): Boolean = | ||
(obtained.result, expected.result) match { | ||
case (Normal(obtained), Normal(expected)) => | ||
try { compare(obtained, expected); false } | ||
catch { case _ => true } | ||
case _ => true | ||
} |
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,22 @@ | ||
package fhetest.Checker | ||
|
||
import java.io.{File, PrintWriter} | ||
import java.nio.file.{Files, Path, Paths, StandardCopyOption} | ||
import spray.json._ | ||
|
||
// file writer | ||
def getPrintWriter(filename: String): PrintWriter = | ||
new PrintWriter(new File(filename)) | ||
|
||
// dump given data to a file | ||
def dumpFile(data: Any, filename: String): Unit = { | ||
val nf = getPrintWriter(filename) | ||
nf.print(data) | ||
nf.close() | ||
} | ||
|
||
// dump given data as JSON | ||
def dumpJson[T](data: T, filename: String)(implicit | ||
writer: JsonWriter[T], | ||
): Unit = | ||
dumpFile(data.toJson.prettyPrint, filename) |
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