Add junit tests + fix form errors and Parser.isCorrect
This commit is contained in:
parent
359d3eace9
commit
6ebb99fb7c
15
build.xml
15
build.xml
@ -3,6 +3,7 @@
|
|||||||
<property name="project.bin.dir" value="bin"/>
|
<property name="project.bin.dir" value="bin"/>
|
||||||
<property name="project.lib.dir" value="lib"/>
|
<property name="project.lib.dir" value="lib"/>
|
||||||
<property name="project.resources.dir" value="resources"/>
|
<property name="project.resources.dir" value="resources"/>
|
||||||
|
<property name="project.test.dir" value="test"/>
|
||||||
<path id="project.classpath">
|
<path id="project.classpath">
|
||||||
<fileset dir="${project.lib.dir}">
|
<fileset dir="${project.lib.dir}">
|
||||||
<include name="*/*.jar"/>
|
<include name="*/*.jar"/>
|
||||||
@ -10,7 +11,10 @@
|
|||||||
<pathelement location="${project.bin.dir}"/>
|
<pathelement location="${project.bin.dir}"/>
|
||||||
</path>
|
</path>
|
||||||
<target name="compile" description="Compilation des classes" depends="init">
|
<target name="compile" description="Compilation des classes" depends="init">
|
||||||
<javac srcdir="${project.sources.dir}" encoding="utf8" destdir="${project.bin.dir}" debug="on" optimize="off" deprecation="on" includeantruntime="false">
|
<javac srcdir="${project.sources.dir}" encoding="utf8" destdir="${project.bin.dir}" debug="on" optimize="on" deprecation="on" includeantruntime="false">
|
||||||
|
<classpath refid="project.classpath"/>
|
||||||
|
</javac>
|
||||||
|
<javac srcdir="${project.test.dir}" encoding="utf8" destdir="${project.bin.dir}" optimize="on" includeantruntime="false">
|
||||||
<classpath refid="project.classpath"/>
|
<classpath refid="project.classpath"/>
|
||||||
</javac>
|
</javac>
|
||||||
<copy todir="${basedir}/${project.bin.dir}">
|
<copy todir="${basedir}/${project.bin.dir}">
|
||||||
@ -32,7 +36,7 @@
|
|||||||
<classpath refid="project.classpath"/>
|
<classpath refid="project.classpath"/>
|
||||||
</java>
|
</java>
|
||||||
</target>
|
</target>
|
||||||
<target name="javadoc">
|
<target description="génération de la javadoc" name="javadoc">
|
||||||
<javadoc sourcepath="src" destdir="doc" access="private" encoding="utf8" overview="overview.html" >
|
<javadoc sourcepath="src" destdir="doc" access="private" encoding="utf8" overview="overview.html" >
|
||||||
<fileset dir="src" defaultexcludes="yes">
|
<fileset dir="src" defaultexcludes="yes">
|
||||||
<include name="**"/>
|
<include name="**"/>
|
||||||
@ -50,4 +54,11 @@
|
|||||||
</manifest>
|
</manifest>
|
||||||
<jar jarfile="build/l-system.jar" basedir="${project.bin.dir}" manifest="${project.bin.dir}/META-INF/MANIFEST.MF"/>
|
<jar jarfile="build/l-system.jar" basedir="${project.bin.dir}" manifest="${project.bin.dir}/META-INF/MANIFEST.MF"/>
|
||||||
</target>
|
</target>
|
||||||
|
<target name="tests" depends="compile">
|
||||||
|
<junit printsummary="true" haltonerror="no" haltonfailure="no" showoutput="true">
|
||||||
|
<classpath refid="project.classpath"/>
|
||||||
|
<formatter type="plain"/>
|
||||||
|
<test fork="true" name="lsystem.TestLSystem" outfile="result" />
|
||||||
|
</junit>
|
||||||
|
</target>
|
||||||
</project>
|
</project>
|
BIN
lib/junit/hamcrest-core-1.3.jar
Normal file
BIN
lib/junit/hamcrest-core-1.3.jar
Normal file
Binary file not shown.
@ -69,17 +69,17 @@ public class Parser {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(old == '.'){
|
if(old == '.'){
|
||||||
for(int y = (type == Type.RULE ? 0 : 1); y < 12; y++){
|
for(int y = (type == Type.RULE ? 0 : 1); y < 10; y++){
|
||||||
if(temp == Constants.VALID_CHARS[y])
|
if(temp == Constants.VALID_CHARS[y])
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
old = temp;
|
old = temp;
|
||||||
for(char validChar : Constants.VALID_CHARS){
|
for(char validChar : Constants.VALID_CHARS){
|
||||||
if(temp == validChar)
|
|
||||||
break;
|
|
||||||
if(validChar == ' ')
|
if(validChar == ' ')
|
||||||
return false;
|
return false;
|
||||||
|
if(temp == validChar)
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return bracket == 0;
|
return bracket == 0;
|
||||||
@ -156,6 +156,7 @@ public class Parser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
assert root == null;
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,8 +65,8 @@ public class Listener extends AbstractListener implements KeyListener, MouseWhee
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case "Clear":
|
case "Clear":
|
||||||
tab.getTextArea((byte) 0).setText("Axiome : \n");
|
tab.getTextArea((byte) 0).setText("Axiome :");
|
||||||
tab.getTextArea((byte) 1).setText("Règles : \n");
|
tab.getTextArea((byte) 1).setText("Règles :");
|
||||||
tab.getTextField((byte) 0).setText("");
|
tab.getTextField((byte) 0).setText("");
|
||||||
tab.getTextField((byte) 1).setText("");
|
tab.getTextField((byte) 1).setText("");
|
||||||
Listener kl = (Listener) tab.getTextField((byte) 0).getKeyListeners()[0];
|
Listener kl = (Listener) tab.getTextField((byte) 0).getKeyListeners()[0];
|
||||||
|
@ -3,6 +3,7 @@ package lsystem.screen.main;
|
|||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Tab extends JPanel{
|
public class Tab extends JPanel{
|
||||||
|
|
||||||
@ -133,7 +134,7 @@ public class Tab extends JPanel{
|
|||||||
*/
|
*/
|
||||||
public String getAxiom() {
|
public String getAxiom() {
|
||||||
String str = axiomList.getText();
|
String str = axiomList.getText();
|
||||||
str = str.substring(10).replaceAll(";", "");
|
str = str.substring(9).replaceAll(";", "");
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +143,9 @@ public class Tab extends JPanel{
|
|||||||
*/
|
*/
|
||||||
public java.util.List<String> getRules(){
|
public java.util.List<String> getRules(){
|
||||||
String str = rulesList.getText();
|
String str = rulesList.getText();
|
||||||
str = str.substring(10).replaceAll(";", "");
|
str = str.substring(9).replaceAll(";", "");
|
||||||
String[] strsplit = str.split("\n");
|
String[] strsplit = str.split("\n");
|
||||||
return Arrays.asList(strsplit);
|
return Arrays.stream(strsplit).filter(p -> !p.equals("")).collect(Collectors.toList()); // To eliminate empty string from the list
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
50
test/lsystem/TestLSystem.java
Normal file
50
test/lsystem/TestLSystem.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package lsystem;
|
||||||
|
|
||||||
|
import lsystem.engine.Parser;
|
||||||
|
import lsystem.engine.Rewrite;
|
||||||
|
import lsystem.screen.gl3d.GLCanvas;
|
||||||
|
import lsystem.utils.Pair;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
public class TestLSystem {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parserTest() {
|
||||||
|
GLCanvas joglFrame = new GLCanvas();
|
||||||
|
Parser parser = new Parser("X", Arrays.asList("X=XY", "Y=X"), 5);
|
||||||
|
List<Pair<String, String>> lSystemRules = parser.parseRules();
|
||||||
|
joglFrame.setLSystem(parser.getAxiom(), lSystemRules, parser.getNbIterations());
|
||||||
|
System.out.println(joglFrame.getLSystem());
|
||||||
|
assertNotNull("L-System should not be null", joglFrame.getLSystem());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void rewriteTest(){
|
||||||
|
Parser parser = new Parser("X", Arrays.asList("X=XY", "Y=X"), 7);
|
||||||
|
String result = Rewrite.rewrite(parser.getAxiom(), parser.parseRules(), parser.getNbIterations());
|
||||||
|
assertEquals("Not equals", "XYXXYXYXXYXXYXYXXYXYXXYXXYXYXXYXXY", result);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void incorrectTest() {
|
||||||
|
Parser parser = new Parser("X", Arrays.asList("X=XY", "y=X"), 3);
|
||||||
|
assertTrue(parser.isCorrect());
|
||||||
|
parser = new Parser("X", Arrays.asList("X+XY" , "Y=X"), 3);
|
||||||
|
assertFalse(parser.isCorrect());
|
||||||
|
parser = new Parser("X", Arrays.asList("X=X++Y", "Y=X"), 3);
|
||||||
|
assertTrue(parser.isCorrect());
|
||||||
|
try {
|
||||||
|
assertNotNull(Parser.parse(Rewrite.rewrite("X", new Parser("X", Arrays.asList("X=XY", "Y=X"), 3).parseRules(), 3)));
|
||||||
|
} catch (NumberFormatException err) {
|
||||||
|
System.out.println("fail");
|
||||||
|
err.printStackTrace();
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user