Skip to content

Commit

Permalink
Merge pull request #47 from flipturnapps/formatting
Browse files Browse the repository at this point in the history
Change output format to Tstl-Style
  • Loading branch information
Kevin Kellar committed Aug 6, 2015
2 parents ced4bdf + ad9ead6 commit e2f581f
Show file tree
Hide file tree
Showing 8 changed files with 304 additions and 272 deletions.
1 change: 1 addition & 0 deletions src/Action.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ public interface Action
public int familyId();
public int[] repVals();
public int[] repIds();
public String tstlStyleOutput();
}
40 changes: 40 additions & 0 deletions src/ActionEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,45 @@ public String getActMainLine(int[] poolValues)
mainLine += endingCharacters;
return mainLine;
}
public String makeFormattedTstlMethod(int[] poolValues)
{
String[] jav = new String[getJavaPieces().length];
//need to copy, escape quotes, and replace below
for (int x = 0; x < jav.length; x++)
{
String temp= "";
for(int y = 0; y < getJavaPieces()[x].length(); y++)
{
if(getJavaPieces()[x].charAt(y) == '"')
temp += "\\\"";
else
temp += getJavaPieces()[x].charAt(y);
}
jav[x] = temp;
}
String ret = "public String " + TstlConstants.DECLARTATION_ACTION_METHOD_TSTL_STYLE_OUTPUT + "(){\n";
String line = "return \"";
int plus = 0;
if(hasInit())
{
line += this.getRepeatables()[0].getAsFormattedTstl(poolValues[0]) + " =";
plus = 1;
}
for (int i = 0; i < (jav.length*2)-1;i++)
{
if(i%2==0)
line += jav[(i)/2];//was (i+1)/2 - if bug reimplement
else
{
int index = ((i-1)/2) + plus;
line += this.getRepeatables()[index].getAsFormattedTstl(poolValues[index]);
}
}
line += "\";\n";
ret += line;
ret += "}\n";
return ret;
}
public String getActUsageLines(int[] poolValues)
{
String ret = "";
Expand Down Expand Up @@ -356,6 +395,7 @@ public String createActionClass(int[] poolValues, int familyId)
ret += this.makeGetFamilyIdMethod(familyId);
ret += this.makeGetRepValsMethod(poolValues);
ret += this.makeGetRepIdsMethod();
ret += this.makeFormattedTstlMethod(poolValues);
ret += "};";
return ret;
}
Expand Down
5 changes: 5 additions & 0 deletions src/NumRange.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,11 @@ public String getAsTstl()
ret += TstlConstants.IDENTIFIER_TSTLVARIABLE;
return ret;
}
@Override
public String getAsFormattedTstl(int i)
{
return getAsJava(i);
}
}


Expand Down
26 changes: 6 additions & 20 deletions src/PoolEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,43 @@ public class PoolEntry extends Repeatable
private String className;
private String varName;
private int listSize;



public PoolEntry(String className, String varName, int listSize)
{
super();
this.className = className.trim();
this.varName = varName.trim();
this.listSize = listSize;
}

public String getClassName()
{
return className;
}

@Override
public String toString() {
public String toString()
{
return "PoolEntry [className=" + className + ", varName=" + varName
+ ", listSize=" + listSize + "]";
}

public String getVarName()
{
return varName;
}

@Override
public int getListSize()
{
return listSize;
}

public String getUsedVarName()
{
return this.getVarName()+TstlConstants.SUFFIX_VAR_USED;
}

public String getInstanceVariableDeclaration(String visibilityLevel)
{

String ret = visibilityLevel + " List<" + this.getClassName() + "> "+ this.getVarName() + ";\n";
ret += visibilityLevel + " int[] " + this.getUsedVarName() + ";";
return ret;
}



public String getClearLines()
{
String ret = getVarName() + " = new ArrayList<" + getClassName() + ">();\n";
Expand All @@ -62,7 +51,6 @@ public String getClearLines()
ret += getUsedVarName() + " = new int[" + this.getListSize() + "];";
return ret;
}

public static PoolEntry getPoolEntryByVarName(PoolEntry[] entirePoolEntries, String varName)
{

Expand All @@ -73,7 +61,6 @@ public static PoolEntry getPoolEntryByVarName(PoolEntry[] entirePoolEntries, Str
}
return null;
}

@Override
public String getAsJava(int i)
{
Expand All @@ -83,20 +70,20 @@ public String getUsedAsJava(int i)
{
return this.getUsedVarName() + "["+ i + "]";
}

public String getAsFormattedTstl(int i)
{
return TstlConstants.IDENTIFIER_TSTLVARIABLE + this.getVarName().substring(TstlConstants.PREFIX_JAVA_VARIABLES.length()) +","+i+ TstlConstants.IDENTIFIER_TSTLVARIABLE;
}
@Override
public String getIsUsableExpression(int i)
{
return this.getAsJava(i) + " != null";
}

@Override
public String getCanOverwriteExpression(int i)
{
return "(" + this.getAsJava(i) + " == null || (" + this.getUsedAsJava(i) + " + " + TstlConstants.DECLARATION_SUT_ALLOW_REINIT_VALUE_FIELD + ">= 2))";
}


@Override
public boolean equalsRepeatable(Repeatable rep)
{
Expand All @@ -107,5 +94,4 @@ public boolean equalsRepeatable(Repeatable rep)
return true;
return false;
}

}
110 changes: 54 additions & 56 deletions src/RandomTester.java
Original file line number Diff line number Diff line change
@@ -1,56 +1,54 @@

public class RandomTester extends Tester
{

@Override
protected void runTests(SUTInterface sut)
{
long startTime = System.currentTimeMillis();
long testCount = 0;
long loopCount = 0;
long lastPrintTime = 0;
while(System.currentTimeMillis() - startTime < getTimeout())
{
sut.reset();
clearActTrace();
testCount = 0;
boolean print = System.currentTimeMillis() - lastPrintTime > getTestPrintDelay() && this.getTestPrintDelay() > -1;
if(print)
{
println(">>Test Number " + loopCount);
lastPrintTime = System.currentTimeMillis();
}
while(testCount<getTestsPerCycle() && System.currentTimeMillis() - startTime <getTimeout())
{
boolean enabled = false;
int testNum = -1;
while(!enabled && System.currentTimeMillis() - startTime < getTimeout())
{
testNum = (int) (Math.random() * sut.getActions().length);
enabled = sut.getActions()[testNum].enabled();
}
if(print)
println(sut.getActions()[testNum].name().trim());
String info = sut.getActions()[testNum].getAllInfo();
addToActTrace(testNum);
boolean success = executeAct(this.getIgnoreCheckValue() < 2, sut.getActions()[testNum], true);
if(!success)
{
testFailed();
return;
}

testCount++;
}
loopCount++;
}
println("-Tested for " + ((System.currentTimeMillis()-startTime+0.0)/(1000+0)) + " seconds.");
println("-Ran " + loopCount + " tests of " + getTestsPerCycle() +" actions.");
println("-Final test only got to " + testCount + " actions.");

}




}

public class RandomTester extends Tester
{
@Override
protected void runTests(SUTInterface sut)
{
long startTime = System.currentTimeMillis();
long testCount = 0;
long loopCount = 0;
long lastPrintTime = 0;
while(System.currentTimeMillis() - startTime < getTimeout())
{
sut.reset();
clearActTrace();
testCount = 0;
boolean print = System.currentTimeMillis() - lastPrintTime > getTestPrintDelay() && this.getTestPrintDelay() > -1;
if(print)
{
println(">>Test Number " + loopCount);
lastPrintTime = System.currentTimeMillis();
}
while(testCount<getTestsPerCycle() && System.currentTimeMillis() - startTime <getTimeout())
{
boolean enabled = false;
int testNum = -1;
while(!enabled && System.currentTimeMillis() - startTime < getTimeout())
{
testNum = (int) (Math.random() * sut.getActions().length);
enabled = sut.getActions()[testNum].enabled();
}
if(print)
println(sut.getActions()[testNum].tstlStyleOutput().trim());
addToActTrace(testNum);
boolean success = executeAct(this.getIgnoreCheckValue() < 2, sut.getActions()[testNum], true);
if(!success)
{
testFailed();
return;
}

testCount++;
}
loopCount++;
}
println("-Tested for " + ((System.currentTimeMillis()-startTime+0.0)/(1000+0)) + " seconds.");
println("-Ran " + loopCount + " tests of " + getTestsPerCycle() +" actions.");
println("-Final test only got to " + testCount + " actions.");

}




}
1 change: 1 addition & 0 deletions src/Repeatable.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ public void setId(int id) {
public abstract String getIsUsableExpression(int i);
public abstract String getCanOverwriteExpression(int i);
public abstract boolean equalsRepeatable(Repeatable rep);
public abstract String getAsFormattedTstl(int i);
}
Loading

0 comments on commit e2f581f

Please sign in to comment.