[Mathlib-commitlog] SF.net SVN: mathlib:[648] JMathLib/trunk/src/jmathlib/tools/ testcasegenerator/
Status: Beta
Brought to you by:
st_mueller
|
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.
|