Search in sources :

Example 6 with IdentDescriptor

use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.

the class InterpreterTest method testUnaryPlusAndMinus2.

@Test
public void testUnaryPlusAndMinus2() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("attr1", Long.class);
    assertTrue(compiler.compile("=-$attr1", attribNameToTypeMap));
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("attr1", new IdentDescriptor(5L));
    assertEquals(new Double(-5.0), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 7 with IdentDescriptor

use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.

the class InterpreterTest method testComparisons.

@Test
public void testComparisons() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("x", Double.class);
    attribNameToTypeMap.put("y", Double.class);
    attribNameToTypeMap.put("limit", Double.class);
    assertTrue(compiler.compile("=${x} <= ${y}", attribNameToTypeMap));
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("x", new IdentDescriptor(1.2));
    nameToDescriptorMap.put("y", new IdentDescriptor(-3.8e-12));
    nameToDescriptorMap.put("limit", new IdentDescriptor(-65.23e12));
    assertEquals(new Boolean(false), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
    assertTrue(compiler.compile("=-15.4^3 > ${limit}", attribNameToTypeMap));
    assertEquals(new Boolean(true), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 8 with IdentDescriptor

use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.

the class InterpreterTest method testDEFINED.

@Test
public void testDEFINED() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("x", Double.class);
    assertTrue(compiler.compile("=defined(x)", attribNameToTypeMap));
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("x", new IdentDescriptor(1.2));
    assertEquals(new Boolean(true), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
    assertTrue(compiler.compile("=DEFINED(${limit})", attribNameToTypeMap));
    assertEquals(new Boolean(false), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 9 with IdentDescriptor

use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.

the class InterpreterTest method testBinaryMinus.

@Test
public void testBinaryMinus() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("attr1", Double.class);
    attribNameToTypeMap.put("attr2", Double.class);
    assertTrue(compiler.compile("=-17.8E-14", attribNameToTypeMap));
    assertTrue(compiler.compile("=1-1.5", attribNameToTypeMap));
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("attr1", new IdentDescriptor(5.5));
    nameToDescriptorMap.put("attr2", new IdentDescriptor(6.5));
    assertEquals(new Double(-0.5), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 10 with IdentDescriptor

use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.

the class InterpreterTest method testIntegerToFloatingPointConversion.

@Test
public void testIntegerToFloatingPointConversion() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("BOB", Long.class);
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("BOB", new IdentDescriptor(new Long(3)));
    assertTrue(compiler.compile("=$BOB > 5.3", attribNameToTypeMap));
    assertEquals(new Boolean(false), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
    assertTrue(compiler.compile("=$BOB <= 5.3", attribNameToTypeMap));
    assertEquals(new Boolean(true), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Aggregations

IdentDescriptor (org.cytoscape.equations.IdentDescriptor)21 HashMap (java.util.HashMap)18 Test (org.junit.Test)16 Interpreter (org.cytoscape.equations.Interpreter)7 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)7 Equation (org.cytoscape.equations.Equation)5 EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)5 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)5 TreeMap (java.util.TreeMap)1 Function (org.cytoscape.equations.Function)1