Thread: [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.
|
|
From: <st_...@us...> - 2009-01-07 20:15:52
|
Revision: 648
http://mathlib.svn.sourceforge.net/mathlib/?rev=648&view=rev
Author: st_mueller
Date: 2009-01-07 20:15:48 +0000 (Wed, 07 Jan 2009)
Log Message:
-----------
automated test case generation
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-07 20:15:29 UTC (rev 647)
+++ JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java 2009-01-07 20:15:48 UTC (rev 648)
@@ -9,9 +9,9 @@
public class testcasegenerator
{
- static String testCaseDirS = "src/jmathlibtests/scripts";
- static Stack testStack = new Stack();
-
+ String testCaseDirS = "src/jmathlibtests/scripts";
+ Stack testStack = new Stack();
+
/**
*
* @param args
@@ -21,17 +21,19 @@
String baseS = "src/jmathlib";
- processDir(baseS);
+ testcasegenerator testgen = new testcasegenerator();
- createAllTestsFile();
+ testgen.processDir(baseS);
+ testgen.createAllTestsFile();
+
}
/** Go through all directories
*
* @param baseS
*/
- public static void processDir(String baseS)
+ public void processDir(String baseS)
{
System.out.println("directory "+baseS);
File dir = new File(baseS, ".");
@@ -52,7 +54,8 @@
else
{
//System.out.println(baseS+"/"+files[i]);
-
+ if ( !files[i].endsWith(".gif") &&
+ !files[i].endsWith(".properties") )
processFile(baseS+"/"+files[i]);
}
@@ -64,16 +67,16 @@
*
* @param fileS file to process and check for testcases
*/
- public static void processFile(String fileS)
+ public void processFile(String fileS)
{
boolean testCaseFoundB = false;
int testCaseNumber = 0;
+ Stack testCasesStack = new Stack();
+
//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="";
@@ -92,10 +95,15 @@
{
// reading in a testcase finished be reaching the
// end of file or finding a new keyword %!testcase
- createTestCase(fileS, testCaseNumber, bufferS);
testCaseFoundB = false;
+ testCasesStack.push(bufferS);
}
+
+ // end of file reached
+ if(line==null)
+ break;
+
if (line.startsWith("%!@testcase"))
{
// found a new testcase
@@ -110,11 +118,6 @@
System.out.println("******* "+line);
bufferS += " "+ line.substring(2) + "\n";
}
- else if(line==null)
- {
- // reached end of file
- break;
- }
}
@@ -123,8 +126,13 @@
catch (Exception e)
{
System.out.println(" exception "+fileS);
+ e.printStackTrace();
}
+ // in case at least one test case was found -> create test-suite
+ if (!testCasesStack.empty())
+ createTestCase(fileS, testCasesStack);
+
} // end process File
@@ -134,15 +142,16 @@
* @param caseNumber
* @param testcaseS
*/
- public static void createTestCase (String fileS, int testCaseNumber, String testcaseS)
+ public void createTestCase (String fileS, Stack testCaseStack)
{
+ fileS = fileS.replaceFirst("src/", "");
fileS = fileS.replace(".java", "");
fileS = fileS.replace(".m", "");
fileS = fileS.replace(".int", "");
fileS = fileS.replace('/', '_');
fileS = fileS.replace('.', '_');
- fileS = "test_"+fileS+testCaseNumber;
+ fileS = "test_"+fileS;
// put filename on tests-stack
testStack.push(fileS);
@@ -175,14 +184,25 @@
s+=" return new TestSuite("+ fileS +".class); \n";
s+=" } \n";
- s+=" public void test_"+ fileS +"001() \n";
+
+ int n = 0;
+ while (!testCaseStack.empty())
+ {
+
+ s+="\n";
+ s+=" public void "+ fileS + n + "() \n";
s+=" { \n";
//s+=" ml.executeExpression(\"a=testFunction001(134);\"); ";
//s+=" assertTrue(136.0 == ml.getScalarValueRe(\"a\")); ";
- s+= testcaseS;
+ s+= (String)testCaseStack.pop();
s+=" }\n";
+
+ n++;
+ }
+
+
s+="}\n";
@@ -203,7 +223,7 @@
}
- public static void createAllTestsFile()
+ public void createAllTestsFile()
{
String s="";
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-11 19:12:27
|
Revision: 683
http://mathlib.svn.sourceforge.net/mathlib/?rev=683&view=rev
Author: st_mueller
Date: 2009-01-11 19:12:17 +0000 (Sun, 11 Jan 2009)
Log Message:
-----------
add more comments
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-11 14:54:38 UTC (rev 682)
+++ JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java 2009-01-11 19:12:17 UTC (rev 683)
@@ -145,13 +145,13 @@
public void createTestCase (String fileS, Stack testCaseStack)
{
- fileS = fileS.replaceFirst("src/", "");
- fileS = fileS.replace(".java", "");
- fileS = fileS.replace(".m", "");
- fileS = fileS.replace(".int", "");
- fileS = fileS.replace('/', '_');
- fileS = fileS.replace('.', '_');
- fileS = "test_"+fileS;
+ fileS = fileS.replaceFirst("src/", ""); // remove src/ at beginning
+ fileS = fileS.replace(".java", ""); // remove .java suffix
+ fileS = fileS.replace(".m", ""); // remove .m suffix
+ fileS = fileS.replace(".int", ""); // remove .int suffix
+ fileS = fileS.replace('/', '_'); // change directory-sign into underline
+ fileS = fileS.replace('.', '_'); // change directory-sign into underline
+ fileS = "test_"+fileS; // add "test_" to make JUnit aware of this class
// put filename on tests-stack
testStack.push(fileS);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|
|
From: <st_...@us...> - 2009-01-14 20:35:52
|
Revision: 686
http://mathlib.svn.sourceforge.net/mathlib/?rev=686&view=rev
Author: st_mueller
Date: 2009-01-14 20:35:47 +0000 (Wed, 14 Jan 2009)
Log Message:
-----------
code clean up
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-14 20:27:34 UTC (rev 685)
+++ JMathLib/trunk/src/jmathlib/tools/testcasegenerator/testcasegenerator.java 2009-01-14 20:35:47 UTC (rev 686)
@@ -5,7 +5,7 @@
import jmathlib.core.interpreter.ErrorLogger;
-/**An external function for getting a directory listing */
+/**An external function for getting a directory listing */
public class testcasegenerator
{
@@ -13,7 +13,7 @@
Stack testStack = new Stack();
/**
- *
+ * Main method of the test case generator
* @param args
*/
public static void main(String[] args) {
@@ -54,14 +54,18 @@
else
{
//System.out.println(baseS+"/"+files[i]);
- if ( !files[i].endsWith(".gif") &&
+ if ( !files[i].endsWith(".gif") &&
+ !files[i].endsWith(".p") &&
+ !files[i].endsWith(".html") &&
+ !files[i].endsWith(".txt") &&
+ !files[i].endsWith(".jpg") &&
!files[i].endsWith(".properties") )
processFile(baseS+"/"+files[i]);
}
- }
+ } // end for
- }
+ } // end processDir
/**
*
@@ -120,7 +124,7 @@
}
- }
+ } // end while
inReader.close();
}
catch (Exception e)
@@ -164,8 +168,7 @@
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 JMathLibTestCase { \n";
s+=" \n";
s+=" public "+ fileS +"(String name) { \n";
s+=" super(name); \n";
@@ -173,12 +176,6 @@
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+=" \n";
s+=" public static Test suite() { \n";
s+=" return new TestSuite("+ fileS +".class); \n";
@@ -221,28 +218,31 @@
}
- }
+ } // end createTestCase
+ /**
+ *
+ */
public 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+=" 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+=" } \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+=" \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";
@@ -253,10 +253,10 @@
s+=" suite.addTest(jmathlibtests.scripts."+ fileS +".suite());\n";
}
- s+=" \n";
- s+=" return suite; \n";
- s+=" } \n";
- s+=" } \n";
+ s+=" \n";
+ s+=" return suite; \n";
+ s+=" } \n";
+ s+=" } \n";
try
@@ -273,7 +273,7 @@
}
- }
+ } // createAllTestsFile
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|