[Mathlib-commitlog] SF.net SVN: mathlib:[640] JMathLib/trunk/src/jmathlib/tools/ testcasegenerator/
Status: Beta
Brought to you by:
st_mueller
|
From: <st_...@us...> - 2009-01-06 16:42:30
|
Revision: 640
http://mathlib.svn.sourceforge.net/mathlib/?rev=640&view=rev
Author: st_mueller
Date: 2009-01-06 16:42:24 +0000 (Tue, 06 Jan 2009)
Log Message:
-----------
automated tests
Modified Paths:
--------------
JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java
Modified: JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java
===================================================================
--- JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java 2009-01-06 16:42:09 UTC (rev 639)
+++ JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java 2009-01-06 16:42:24 UTC (rev 640)
@@ -1,6 +1,7 @@
package jmathlib.tools.testcasegenerator;
import java.io.*;
+import java.util.Stack;
import jmathlib.core.interpreter.ErrorLogger;
@@ -8,19 +9,28 @@
public class testcasegenerator
{
- static String testCaseDirS = "src/jmathlibtests";
+ static String testCaseDirS = "src/jmathlibtests/scripts";
+ static Stack testStack = new Stack();
+ /**
+ *
+ * @param args
+ */
public static void main(String[] args) {
System.out.println("testcasegenerator");
String baseS = "src/jmathlib";
-
processDir(baseS);
+ createAllTestsFile();
+
}
-
+ /** Go through all directories
+ *
+ * @param baseS
+ */
public static void processDir(String baseS)
{
System.out.println("directory "+baseS);
@@ -50,11 +60,21 @@
}
+ /**
+ *
+ * @param fileS file to process and check for testcases
+ */
public static void processFile(String fileS)
{
+ boolean testCaseFoundB = false;
+ int testCaseNumber = 0;
+
//System.out.println("anaylzing "+ fileS);
+ if (fileS.endsWith("bitor.java"))
+ System.out.println("*!*!*!*!*!*!*!*!*!*!*\n!*!*!*!*!*!*!**");
+
// open file and read m-file line by line
String bufferS="";
try
@@ -62,13 +82,41 @@
File f = new File(fileS);
BufferedReader inReader = new BufferedReader(new FileReader(f));
String line;
- while ((line = inReader.readLine()) != null)
- {
- if (line.startsWith("%!"))
+ while (true)
+ {
+ // read a line from the file
+ line = inReader.readLine();
+
+ if(testCaseFoundB &&
+ (line==null || line.startsWith("%!@testcase")) )
{
+ // reading in a testcase finished be reaching the
+ // end of file or finding a new keyword %!testcase
+ createTestCase(fileS, testCaseNumber, bufferS);
+ testCaseFoundB = false;
+ }
+
+ if (line.startsWith("%!@testcase"))
+ {
+ // found a new testcase
+ System.out.println("******* new testcase found");
+ testCaseNumber++;
+ testCaseFoundB = true;
+ bufferS = "";
+ }
+ else if (line.startsWith("%!"))
+ {
+ // build up testcase
System.out.println("******* "+line);
bufferS += " "+ line.substring(2) + "\n";
}
+ else if(line==null)
+ {
+ // reached end of file
+ break;
+ }
+
+
}
inReader.close();
}
@@ -78,55 +126,64 @@
}
- if (!bufferS.equals(""))
- {
- createTestCase(fileS, bufferS);
- }
-
} // end process File
-
- public static void createTestCase (String fileS, String testcaseS)
+ /**
+ *
+ * @param fileS
+ * @param caseNumber
+ * @param testcaseS
+ */
+ public static void createTestCase (String fileS, int testCaseNumber, String testcaseS)
{
+ fileS = fileS.replace(".java", "");
+ fileS = fileS.replace(".m", "");
+ fileS = fileS.replace(".int", "");
fileS = fileS.replace('/', '_');
fileS = fileS.replace('.', '_');
- fileS = "test_"+fileS;
+ fileS = "test_"+fileS+testCaseNumber;
+ // put filename on tests-stack
+ testStack.push(fileS);
+
String s = "";
s+="// "+fileS + "\n";
- s+="package jmathlibtests; \n";
+ s+="package jmathlibtests.scripts; \n";
s+="";
- s+="import jmathlib.core.interpreter.Interpreter; \n";
- s+="import jmathlib.tools.junit.framework.*; \n";
- s+="import jmathlibtests.Compare; \n";
+ s+="import jmathlib.core.interpreter.Interpreter; \n";
+ s+="import jmathlib.tools.junit.framework.*; \n";
+ s+="import jmathlibtests.Compare; \n";
s+="\n";
- s+="public class "+ fileS +" extends TestCase { \n";
- s+=" protected Interpreter ml; \n";
+ s+="public class "+ fileS +" extends TestCase { \n";
+ s+=" protected Interpreter ml; \n";
s+=" \n";
- s+=" public "+ fileS +"(String name) { \n";
- s+=" super(name); \n";
- s+=" } \n";
- s+=" public static void main (String[] args) { \n";
+ s+=" public "+ fileS +"(String name) { \n";
+ s+=" super(name); \n";
+ s+=" } \n";
+ s+=" public static void main (String[] args) { \n";
s+=" jmathlib.tools.junit.textui.TestRunner.run (suite()); \n";
+ s+=" } \n";
+ s+=" protected void setUp() { \n";
+ s+=" ml = new Interpreter(true); \n";
+ s+=" } \n";
+ s+=" protected void tearDown() { \n";
+ s+=" ml = null; \n";
s+=" } \n";
- s+=" protected void setUp() { \n";
- s+=" ml = new Interpreter(true); \n";
- s+=" } \n";
- s+=" protected void tearDown() { \n";
- s+=" ml = null; \n";
- s+=" } \n";
s+=" \n";
- s+=" public static Test suite() { \n";
+ s+=" public static Test suite() { \n";
s+=" return new TestSuite("+ fileS +".class); \n";
s+=" } \n";
- s+=" public void test_"+ fileS +"001() \n";
+ s+=" public void test_"+ fileS +"001() \n";
s+=" { \n";
//s+=" ml.executeExpression(\"a=testFunction001(134);\"); ";
//s+=" assertTrue(136.0 == ml.getScalarValueRe(\"a\")); ";
+
s+= testcaseS;
+
s+=" }\n";
+ s+="}\n";
try
@@ -144,7 +201,60 @@
}
- }
+ }
+
+ public static void createAllTestsFile()
+ {
+ String s="";
+
+ s+=" package jmathlibtests.scripts; \n";
+ s+=" \n";
+ s+=" import jmathlib.tools.junit.framework.*; \n";
+ s+=" \n";
+ s+=" public class AllTests { \n";
+ s+=" \n";
+ s+=" public static void main (String[] args) { \n";
+ s+=" jmathlib.tools.junit.textui.TestRunner.run (suite()); \n";
+ s+=" } \n";
+ s+=" public static Test suite ( ) { \n";
+ s+=" TestSuite suite= new TestSuite(\"script functions\"); \n";
+ s+=" \n";
+ s+=" /* include subdirectories here */ \n";
+ s+=" // none \n";
+ s+=" \n";
+ s+=" /* include tests in this directory here */ \n";
+
+ s+=" suite.addTest(jmathlibtests.toolbox.net.testUrlread.suite());\n";
+
+ while (!testStack.isEmpty())
+ {
+ String fileS = (String)testStack.pop();
+
+ s+=" suite.addTest(jmathlibtests.scripts."+ fileS +".suite());\n";
+ }
+
+ s+=" \n";
+ s+=" return suite; \n";
+ s+=" } \n";
+ s+=" } \n";
+
+
+ try
+ {
+ File f = new File(testCaseDirS+"/AllTests.java");
+ BufferedWriter outWriter = new BufferedWriter( new FileWriter(f));
+
+ outWriter.write(s);
+ outWriter.close();
+ }
+ catch(Exception e)
+ {
+ System.out.println("AllTests exception - " + e.getMessage());
+ }
+
+
+ }
+
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|