PID auto tune unit test

This commit is contained in:
rusefi 2018-11-22 20:09:53 -05:00
parent dd2f17a332
commit 30b7cc6080
7 changed files with 40 additions and 6 deletions

View File

@ -1,6 +1,6 @@
// auto-generated from.\controllers/algo/rusefi_enums.h
// by enum2string.jar tool
// on Thu Nov 22 18:48:26 EST 2018
// on Thu Nov 22 20:05:41 EST 2018
// see also gen_config_and_enums.bat
@ -950,6 +950,8 @@ const char *getPidAutoTune_Peak(PidAutoTune_Peak value){
switch(value) {
case MAXIMUM:
return "MAXIMUM";
case MINIMUM:
return "MINIMUM";
case NOT_A_PEAK:
return "NOT_A_PEAK";
}

Binary file not shown.

View File

@ -0,0 +1,9 @@
<component name="libraryTable">
<library name="junit">
<CLASSES>
<root url="jar://$PROJECT_DIR$/../../java_console/lib/junit.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View File

@ -6,7 +6,7 @@
<target name="compile">
<mkdir dir="build/classes"/>
<javac destdir="build/classes" classpath="lib/junit.jar:lib/annotations.jar">
<javac destdir="build/classes" classpath="../../java_console/lib/junit.jar:lib/annotations.jar">
<src path="src"/>
</javac>
</target>

View File

@ -7,6 +7,6 @@
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="junit" level="project" />
</component>
</module>
</module>

View File

@ -72,7 +72,7 @@ public class EnumToString {
reader = new BufferedReader(new FileReader(inFileName));
String line;
while ((line = reader.readLine()) != null) {
line = line.replaceAll("\\s+", "");
line = removeSpaces(line);
if (line.startsWith("typedefenum{")) {
System.out.println("Entering enum");
@ -87,7 +87,7 @@ public class EnumToString {
} else {
line = line.replaceAll("//.+", "");
if (isInsideEnum) {
if (line.matches("[a-zA-Z_$][a-zA-Z\\d_$]*[=a-zA-Z\\d_*]*,?")) {
if (isKeyValueLine(line)) {
line = line.replace(",", "");
int index = line.indexOf('=');
if (index != -1)
@ -100,6 +100,14 @@ public class EnumToString {
}
}
static String removeSpaces(String line) {
return line.replaceAll("\\s+", "");
}
static boolean isKeyValueLine(String line) {
return removeSpaces(line).matches("[a-zA-Z_$][a-zA-Z\\d_$]*[=-a-zA-Z\\d_*]*,?");
}
private static String makeCode(String enumName) {
StringBuilder sb = new StringBuilder();
sb.append(getMethodSignature(enumName) + "{\r\n");

View File

@ -0,0 +1,15 @@
package com.rusefi;
import org.junit.Test;
import static com.rusefi.EnumToString.isKeyValueLine;
import static org.junit.Assert.assertTrue;
public class EnumToStringTest {
@Test
public void testParseLine() {
assertTrue(isKeyValueLine("MIN"));
assertTrue(isKeyValueLine("MIN = 2,"));
assertTrue(isKeyValueLine("MIN = -3,"));
}
}