use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testEvalDefaultDepth$.
@Test
public void testEvalDefaultDepth$() {
Entity person = new DynamicEntity(personWeightEntityType);
person.set("weight", 82);
Object weight = jsMagmaScriptEvaluator.eval("$('weight').value()", person);
assertEquals(weight, 82);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method test$.
@Test
public void test$() {
Entity person = new DynamicEntity(personWeightEntityType);
person.set("weight", 82);
Object weight = jsMagmaScriptEvaluator.eval("$('weight').value()", person, 3);
assertEquals(weight, 82);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method div.
@Test
public void div() {
Entity entity0 = new DynamicEntity(personHeightEntityType);
entity0.set("height", 200);
Object result = jsMagmaScriptEvaluator.eval("$('height').div(100).value()", entity0, 3);
assertEquals(result, 2d);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testPlusValue.
@Test
public void testPlusValue() {
Entity entity0 = new DynamicEntity(personHeightEntityType);
entity0.set("height", 180);
Object result = jsMagmaScriptEvaluator.eval("$('height').plus(100).value()", entity0, 3);
assertEquals(result, (double) 280);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testGlucose.
@Test
public void testGlucose() {
Attribute idAttribute = mock(Attribute.class);
when(idAttribute.getName()).thenReturn("id");
when(idAttribute.getDataType()).thenReturn(STRING);
Attribute gluc1Attr = when(mock(Attribute.class).getName()).thenReturn("GLUC_1").getMock();
when(gluc1Attr.getDataType()).thenReturn(DECIMAL);
EntityType personGlucoseMeta = when(mock(EntityType.class).getId()).thenReturn("glucose").getMock();
when(personGlucoseMeta.getIdAttribute()).thenReturn(idAttribute);
when(personGlucoseMeta.getAttribute("GLUC_1")).thenReturn(gluc1Attr);
when(personGlucoseMeta.getAtomicAttributes()).thenReturn(singletonList(gluc1Attr));
Entity glucose = new DynamicEntity(personGlucoseMeta);
glucose.set("GLUC_1", 4.1);
Object bmi = jsMagmaScriptEvaluator.eval("$('GLUC_1').div(100).value()", glucose, 3);
DecimalFormat df = new DecimalFormat("#.####", new DecimalFormatSymbols(Locale.ENGLISH));
assertEquals(df.format(bmi), df.format(4.1 / 100));
}
Aggregations