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));
}
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);
}
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));
}
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));
}
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));
}
Aggregations