use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method combineGroupMapFunctions.
@Test
public void combineGroupMapFunctions() {
Entity entity1 = new DynamicEntity(personAgeEntityType);
entity1.set("age", 29);
Object result1 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity1, 3);
assertEquals(result1.toString(), "1");
Entity entity2 = new DynamicEntity(personAgeEntityType);
entity2.set("age", 17);
Object result2 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity2, 3);
assertEquals(result2.toString(), "0");
Entity entity3 = new DynamicEntity(personAgeEntityType);
entity3.set("age", 40);
Object result3 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity3, 3);
assertEquals(result3.toString(), "2");
Entity entity4 = new DynamicEntity(personAgeEntityType);
entity4.set("age", 70);
Object result4 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56]).map({'-18':'0','18-35':'1','35-56':'2','56+':'3'}).value();", entity4, 3);
assertEquals(result4.toString(), "3");
Entity entity5 = new DynamicEntity(personAgeEntityType);
entity5.set("age", 999);
Object result5 = jsMagmaScriptEvaluator.eval("$('age').group([18, 35, 56], [999]).map({'-18':0,'18-35':1,'35-56':2,'56+':3,'999':'9'}).value();", entity5, 3);
assertEquals(result5.toString(), "9");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testTimes.
@Test
public void testTimes() {
Entity entity0 = new DynamicEntity(personHeightEntityType);
entity0.set("height", 2);
Object result = jsMagmaScriptEvaluator.eval("$('height').times(100).value()", entity0, 3);
assertEquals(result, (double) 200);
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testValueForXref.
@Test
public void testValueForXref() {
Entity gender = new DynamicEntity(genderEntityType);
gender.set("id", "1");
gender.set("label", "male");
Entity person = new DynamicEntity(personGenderEntityType);
person.set("gender", gender);
Object result = jsMagmaScriptEvaluator.eval("$('gender.label').value()", person, 3);
assertEquals(result.toString(), "male");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testValueForNestedXrefDefaultDepth.
@Test
public void testValueForNestedXrefDefaultDepth() {
Entity gender = new DynamicEntity(genderEntityType);
gender.set("id", "1");
gender.set("label", "male");
Entity person = new DynamicEntity(personGenderEntityType);
person.set("gender", gender);
Object scriptExceptionObj = jsMagmaScriptEvaluator.eval("$('gender.xref.label').value()", person);
assertEquals(scriptExceptionObj.toString(), "org.molgenis.script.core.ScriptException: <eval>:502 TypeError: Cannot read property \"label\" from undefined");
}
use of org.molgenis.data.support.DynamicEntity in project molgenis by molgenis.
the class JsMagmaScriptEvaluatorTest method testGe.
@Test
public void testGe() {
Entity person0 = new DynamicEntity(personWeightEntityType);
person0.set("weight", null);
String script = "$('weight').ge(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, false);
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, true);
}
Aggregations