Search in sources :

Example 1 with IdentDescriptor

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

the class SourceIDTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new SourceID(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=SOURCEID(11)", variableNameToTypeMap))
        fail(compiler.getLastErrorMsg());
    final Equation equation = compiler.getEquation();
    final Interpreter interpreter = new InterpreterImpl();
    final Map<String, IdentDescriptor> variableNameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    assertEquals("Equation evaluation returned an unexpected result!", 101L, interpreter.execute(equation, variableNameToDescriptorMap));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) HashMap(java.util.HashMap) Equation(org.cytoscape.equations.Equation) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 2 with IdentDescriptor

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

the class InterpreterImpl method aref2.

private void aref2() throws EmptyStackException {
    final String attribName = (String) argumentStack.pop();
    final Object defaultValue = argumentStack.pop();
    final IdentDescriptor identDescriptor = variableNameToDescriptorMap.get(attribName);
    if (identDescriptor == null)
        throw new IllegalStateException("unknown column reference: \"" + attribName + "\" (2).");
    final Object value = identDescriptor.getValue();
    argumentStack.push(value != null ? value : defaultValue);
}
Also used : IdentDescriptor(org.cytoscape.equations.IdentDescriptor)

Example 3 with IdentDescriptor

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

the class InterpreterTest method testUnaryPlusAndMinus.

@Test
public void testUnaryPlusAndMinus() 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("=+(${attr1} + ${attr2})", 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(12.0), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
Also used : HashMap(java.util.HashMap) IdentDescriptor(org.cytoscape.equations.IdentDescriptor) Test(org.junit.Test)

Example 4 with IdentDescriptor

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

the class InterpreterTest method testColumnStartsWithNumber.

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

Example 5 with IdentDescriptor

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

the class InterpreterTest method testSimpleStringConcatExpr.

@Test
public void testSimpleStringConcatExpr() throws Exception {
    final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
    attribNameToTypeMap.put("s1", String.class);
    assertTrue(compiler.compile("=\"Fred\"&${s1}", attribNameToTypeMap));
    final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
    nameToDescriptorMap.put("s1", new IdentDescriptor("Bob"));
    assertEquals("FredBob", 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