use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testValueForMrefWithComplexAlgorithm.
@Test
public void testValueForMrefWithComplexAlgorithm() {
Entity trait = new DynamicEntity(traitEntityType);
trait.set("id", "1");
trait.set("name", "Hello");
Entity person = new DynamicEntity(personTraitEntityType);
person.set("id", "1");
person.set("trait", singletonList(trait));
Object result = jsMagmaScriptEvaluator.eval("var result = [];$('trait').map(function (entity) {result.push(entity.val.name)});result", person, 3);
assertEquals(result.toString(), "[Hello]");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method combinePlusGroupMapFunctions.
@Test
public void combinePlusGroupMapFunctions() {
Attribute idAttribute = mock(Attribute.class);
when(idAttribute.getName()).thenReturn("id");
when(idAttribute.getDataType()).thenReturn(STRING);
Attribute food59Attr = when(mock(Attribute.class).getName()).thenReturn("FOOD59A1").getMock();
when(food59Attr.getDataType()).thenReturn(INT);
Attribute food60Attr = when(mock(Attribute.class).getName()).thenReturn("FOOD60A1").getMock();
when(food60Attr.getDataType()).thenReturn(INT);
EntityType foodPersonEntityType = when(mock(EntityType.class).getId()).thenReturn("person").getMock();
when(foodPersonEntityType.getIdAttribute()).thenReturn(idAttribute);
when(foodPersonEntityType.getAttribute("FOOD59A1")).thenReturn(food59Attr);
when(foodPersonEntityType.getAttribute("FOOD60A1")).thenReturn(food60Attr);
when(foodPersonEntityType.getAtomicAttributes()).thenReturn(asList(food59Attr, food60Attr));
Entity entity0 = new DynamicEntity(foodPersonEntityType);
entity0.set("FOOD59A1", 7);
entity0.set("FOOD60A1", 6);
Object result1 = jsMagmaScriptEvaluator.eval("var SUM_WEIGHT = new newValue(0);SUM_WEIGHT.plus($('FOOD59A1').map({\"1\":0,\"2\":0.2,\"3\":0.6,\"4\":1,\"5\":2.5,\"6\":4.5,\"7\":6.5}, null, null).value());SUM_WEIGHT.plus($('FOOD60A1').map({\"1\":0,\"2\":0.2,\"3\":0.6,\"4\":1,\"5\":2.5,\"6\":4.5,\"7\":6.5}, null, null).value());SUM_WEIGHT.group([0,1,2,6,7]).map({\"0-1\":\"4\",\"1-2\":\"3\",\"2-6\":\"2\",\"6-7\":\"1\", \"7+\" : \"1\"},null,null).value();", entity0, 3);
assertEquals(result1.toString(), "1");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method age.
@Test
public void age() {
Entity person = new DynamicEntity(personBirthDateMeta);
person.set("birthdate", now().atOffset(UTC).toLocalDate());
Object result = jsMagmaScriptEvaluator.eval("$('birthdate').age().value()", person, 3);
assertEquals(result, 0d);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testLe.
@Test
public void testLe() {
Entity person0 = new DynamicEntity(personWeightEntityType);
person0.set("weight", null);
String script = "$('weight').le(100).value()";
Object result = jsMagmaScriptEvaluator.eval(script, person0, 3);
assertEquals(result, false);
Entity person1 = new DynamicEntity(personWeightEntityType);
person1.set("weight", 99);
result = jsMagmaScriptEvaluator.eval(script, person1, 3);
assertEquals(result, true);
Entity person2 = new DynamicEntity(personWeightEntityType);
person2.set("weight", 100);
result = jsMagmaScriptEvaluator.eval(script, person2, 3);
assertEquals(result, true);
Entity person3 = new DynamicEntity(personWeightEntityType);
person3.set("weight", 101);
result = jsMagmaScriptEvaluator.eval(script, person3, 3);
assertEquals(result, false);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testPlusObject.
@Test
public void testPlusObject() {
Entity entity0 = new DynamicEntity(personHeightEntityType);
entity0.set("height", 180);
Object result1 = jsMagmaScriptEvaluator.eval("$('height').plus(new newValue(100)).value()", entity0, 3);
assertEquals(result1, (double) 280);
}
Aggregations