From 88d092bfc626b2c08c07403da7f4c6a08fa57f70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Sinan=20K=C3=B6ksal?= <alisinan@gmail.com> Date: Wed, 19 Jan 2011 16:41:50 +0000 Subject: [PATCH] Generated test cases go into a folder, and less console output. --- src/purescala/testcases/Main.scala | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/purescala/testcases/Main.scala b/src/purescala/testcases/Main.scala index 3fa4cb614..9eb39831c 100644 --- a/src/purescala/testcases/Main.scala +++ b/src/purescala/testcases/Main.scala @@ -36,13 +36,14 @@ class Main(reporter : Reporter) extends Analyser(reporter) { var constraints: Expr = BooleanLiteral(true) val prec = matchToIfThenElse(funDef.precondition.getOrElse(BooleanLiteral(true))) var inputList: List[Seq[Expr]] = Nil - for (i <- 1 to Settings.nbTestcases) { + var noMoreModels = false + for (i <- 1 to Settings.nbTestcases if !noMoreModels) { // reporter.info("Current constraints: " + constraints) val argMap = solver.decideIterativeWithBounds(And(prec, constraints), false) argMap match { - case (Some(true), _) => None + case (Some(true), _) => noMoreModels = true case (_ , map) => - reporter.info("Solver returned the following assignment: " + map) + // reporter.info("Solver returned the following assignment: " + map) val testInput = (for (arg <- funDef.args) yield { map.get(arg.id) match { case Some(value) => value @@ -57,6 +58,9 @@ class Main(reporter : Reporter) extends Analyser(reporter) { } } + if (inputList.size < Settings.nbTestcases) + reporter.error("Could only generate " + inputList.size + " testcases while " + Settings.nbTestcases + " were requested") + inputList.reverse } @@ -94,17 +98,21 @@ class Main(reporter : Reporter) extends Analyser(reporter) { val funcInputPairs: Seq[(Identifier, Seq[Seq[Expr]])] = (for (funDef <- program.definedFunctions.toList.sortWith((fd1, fd2) => fd1 < fd2) if (!funDef.isPrivate && (Settings.functionsToAnalyse.isEmpty || Settings.functionsToAnalyse.contains(funDef.id.name)) && (!Settings.impureTestcases || !funDef.hasBody))) yield { reporter.info("Considering function definition: " + funDef.id) - funDef.precondition match { - case Some(p) => reporter.info("The precondition is: " + p) - case None => reporter.info("Function has no precondition") - } + // funDef.precondition match { + // case Some(p) => reporter.info("The precondition is: " + p) + // case None => reporter.info("Function has no precondition") + // } val testInput = generateTestInput(funDef) - reporter.info("Generated test input is: " + testInput) + // reporter.info("Generated test input is: " + testInput) (funDef.id, testInput) }) - writeToFile("Test" + program.mainObject.id.toString + ".scala", testObject(funcInputPairs)) + val outputFolderName = "generated-testcases" + val outputFileName = outputFolderName + "/" + "Test" + program.mainObject.id.toString + ".scala" + new java.io.File(outputFolderName).mkdir() + writeToFile(outputFileName, testObject(funcInputPairs)) + reporter.info("Output written into file: " + outputFileName) reporter.info("Done.") } -- GitLab