Skip to content
Snippets Groups Projects
Commit c1dd702f authored by Simon's avatar Simon
Browse files

created example test

parent 75223165
No related branches found
No related tags found
1 merge request!1Randomvarhelper
......@@ -50,3 +50,4 @@ Require-Bundle: org.eclipse.core.runtime,
org.eclipse.emf.cdo.edit,
org.apache.commons.math3
Bundle-ActivationPolicy: lazy
Import-Package: org.junit
package tools.descartes.dml.mm.applicationlevel.functions.util.tests;
import java.io.File;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
import org.junit.Assert;
import org.junit.Test;
import tools.descartes.dml.mm.applicationlevel.functions.RandomVariable;
import tools.descartes.dml.mm.applicationlevel.functions.util.RandomVariableHelper;
public class MeanCalculatorTest {
private ResourceSet resourceSet;
@Test
public void simpleTest() {
RandomVariable randomVariable = loadModel("testfiles/Simple.functions", RandomVariable.class);
Assert.assertEquals(1.0, RandomVariableHelper.getNumericalMean(randomVariable.getProbFunction()), 0.0000000001);
}
@SuppressWarnings("unchecked")
private <T extends EObject> T loadModel(String fileName, Class<T> class1) {
try {
File f = new File(fileName);
org.eclipse.emf.ecore.resource.Resource res = this.getResourceSet()
.getResource(URI.createFileURI(f.getAbsolutePath()), true);
T model = (T) res.getContents().get(0);
if (model == null)
throw new IllegalStateException("Unable to load test file!");
return model;
} catch (Exception e) {
throw new IllegalStateException(e);
}
}
public ResourceSet getResourceSet() {
if (null == resourceSet)
this.resourceSet = new ResourceSetImpl();
return resourceSet;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<functions:RandomVariable xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:functions="http://www.descartes.tools/metamodel/functions/1.0">
<probFunction xsi:type="functions:DoubleLiteral" value="1"/>
</functions:RandomVariable>
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