Skip to content
Snippets Groups Projects
Commit 36abdfd0 authored by Bernhard Johannes Berger's avatar Bernhard Johannes Berger
Browse files

Proper testing using Juniper, Java17 and Xtext.

parent d24c72fc
No related branches found
No related tags found
No related merge requests found
Pipeline #244304 passed
......@@ -104,6 +104,20 @@ public class ArffPropertiesReader implements PropertiesReader {
properties.put(pSpec, (int)instance.toDoubleArray()[index]);
return properties;
};
} else if(RepresentationType.STRING.equals(rType)) {
toProperties = (instance, template, builder) -> {
if(instance.isMissing(index)) {
return decoratee.apply(instance, template, builder);
}
// add current specification to builder and let the chain complete it
builder.add(pSpec);
final Properties properties = decoratee.apply(instance, template, builder);
// set value and return
properties.put(pSpec, instance.stringValue(index));
return properties;
};
} else {
throw new RuntimeException("Not yet supported: " + rType);
}
......
package de.evoal.core.arff;
import de.evoal.core.api.properties.Properties;
import de.evoal.core.api.properties.PropertiesSpecification;
import de.evoal.core.api.properties.PropertySpecification;
import de.evoal.core.api.properties.io.PropertiesReader;
import de.evoal.core.api.utils.EvoalIOException;
import de.evoal.core.arff.io.ArffPropertiesReader;
import de.evoal.core.arff.utils.LanguageUtils;
import de.evoal.core.arff.utils.ResourceUtils;
import de.evoal.languages.model.ddl.DataDescription;
import de.evoal.languages.model.ddl.DataDescriptionModel;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
......@@ -21,14 +25,52 @@ public class ArffPropertiesReaderTest {
final Path temporary = Files.createTempDirectory("evoal");
final File temporaryFolder = temporary.toFile();
ResourceUtils.unpack(getClass().getClassLoader(), temporaryFolder, "simple/input.arff", "simple/specification.ddl");
// final DataDescriptionModel model = LanguageUtils.load(new File(temporaryFolder, "simple/specification.ddl"), DataDescriptionModel.class);
// final PropertiesSpecification specification = toSpecification(model);
final File toLoad = new File(temporaryFolder, "simple/specification.ddl");
final DataDescriptionModel model = LanguageUtils.load(toLoad, DataDescriptionModel.class);
final PropertiesSpecification specification = toSpecification(model);
// final PropertiesReader testee = new ArffPropertiesReader()
// .init(new File(temporaryFolder, "input.arff"), specification);
final PropertiesReader testee = new ArffPropertiesReader()
.init(new File(temporaryFolder, "simple/input.arff"), specification);
// Assertions.assertTrue(testee.hasNext());
{
Assertions.assertTrue(testee.hasNext());
final Properties p = testee.next();
Assertions.assertEquals(5.1, p.get(new PropertySpecification("sepallength", null)));
Assertions.assertEquals(3.5, p.get(new PropertySpecification("sepalwidth", null)));
Assertions.assertEquals(1.4, p.get(new PropertySpecification("petallength", null)));
Assertions.assertEquals(0.2, p.get(new PropertySpecification("petalwidth", null)));
Assertions.assertEquals("Iris-setosa", p.get(new PropertySpecification("class", null)));
}
{
Assertions.assertTrue(testee.hasNext());
final Properties p = testee.next();
Assertions.assertEquals(4.9, p.get(new PropertySpecification("sepallength", null)));
Assertions.assertEquals(3.0, p.get(new PropertySpecification("sepalwidth", null)));
Assertions.assertEquals(1.4, p.get(new PropertySpecification("petallength", null)));
Assertions.assertEquals(0.2, p.get(new PropertySpecification("petalwidth", null)));
Assertions.assertEquals("Iris-setosa", p.get(new PropertySpecification("class", null)));
}
{
Assertions.assertTrue(testee.hasNext());
final Properties p = testee.next();
Assertions.assertEquals(4.7, p.get(new PropertySpecification("sepallength", null)));
Assertions.assertEquals(3.2, p.get(new PropertySpecification("sepalwidth", null)));
Assertions.assertEquals(1.3, p.get(new PropertySpecification("petallength", null)));
Assertions.assertEquals(0.2, p.get(new PropertySpecification("petalwidth", null)));
Assertions.assertEquals("Iris-setosa", p.get(new PropertySpecification("class", null)));
}
{
Assertions.assertTrue(testee.hasNext());
final Properties p = testee.next();
Assertions.assertEquals(4.6, p.get(new PropertySpecification("sepallength", null)));
Assertions.assertEquals(3.1, p.get(new PropertySpecification("sepalwidth", null)));
Assertions.assertEquals(1.5, p.get(new PropertySpecification("petallength", null)));
Assertions.assertEquals(0.2, p.get(new PropertySpecification("petalwidth", null)));
Assertions.assertEquals("Iris-setosa", p.get(new PropertySpecification("class", null)));
}
Assertions.assertFalse(testee.hasNext());
}
private PropertiesSpecification toSpecification(final DataDescriptionModel model) {
......
......@@ -27,11 +27,12 @@ public class LanguageUtils {
public static <T extends EObject> T load(final @NonNull File path, final Class<T> cl) {
loadPackages();
final URI modelURI = URI.createPlatformResourceURI(path.toString(), true);
final URI modelURI = URI.createFileURI(path.toString());
return load(modelURI, cl);
}
private static void loadPackages() {
DdlPackage.eINSTANCE.getName();
DataDescriptionLanguageStandaloneSetup.doSetup();
}
......
......@@ -17,10 +17,4 @@
5.1,3.5,1.4,0.2,Iris-setosa
4.9,3.0,1.4,0.2,Iris-setosa
4.7,3.2,1.3,0.2,Iris-setosa
4.6,3.1,1.5,0.2,Iris-setosa
5.0,3.6,1.4,0.2,Iris-setosa
5.4,3.9,1.7,0.4,Iris-setosa
4.6,3.4,1.4,0.3,Iris-setosa
5.0,3.4,1.5,0.2,Iris-setosa
4.4,2.9,1.4,0.2,Iris-setosa
4.9,3.1,1.5,0.1,Iris-setosa
\ No newline at end of file
4.6,3.1,1.5,0.2,Iris-setosa
\ No newline at end of file
data:
cardinal real 'sepallength';
cardinal real 'sepalwidth';
cardinal real 'petallength';
cardinal real 'petalwidth';
nominal string 'class';
\ No newline at end of file
......@@ -335,8 +335,8 @@
<arg>io.jenetics.base/io.jenetics.internal.util=de.evoal.core.main</arg>
<arg>--add-exports</arg>
<arg>io.jenetics.base/io.jenetics.internal.collection=de.evoal.core.main</arg>
<arg>--add-exports</arg>
<arg>org.eclipse.xtext.util/org.eclipse.xtext.util=de.evoal.core.main</arg>
<!--<arg>- -add-exports</arg>
<arg>org.eclipse.xtext.util/org.eclipse.xtext.util=de.evoal.core.main</arg>-->
</compilerArgs>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
</configuration>
......
......@@ -92,14 +92,7 @@
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext</artifactId>
<version>2.29.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.util</artifactId>
<version>2.29.0</version>
<version>2.29.1</version>
<scope>provided</scope>
</dependency>
......
......@@ -127,7 +127,7 @@
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext</artifactId>
<version>2.29.0</version>
<version>2.29.1</version>
<scope>provided</scope>
</dependency>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment