use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class InterpreterTest method testMixedModeArithmetic.
@Test
public void testMixedModeArithmetic() throws Exception {
final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
attribNameToTypeMap.put("x", Long.class);
final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
nameToDescriptorMap.put("x", new IdentDescriptor(new Long(3)));
assertTrue(compiler.compile("=$x + 2.0", attribNameToTypeMap));
assertEquals(new Double(5.0), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
assertTrue(compiler.compile("=TRUE + TRUE", attribNameToTypeMap));
assertEquals(new Double(2.0), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class InterpreterTest method testSimpleExpr.
@Test
public void testSimpleExpr() throws Exception {
final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
attribNameToTypeMap.put("BOB", Double.class);
assertTrue(compiler.compile("=42 - 12 + 3 * (4 - 2) + ${BOB:12}", attribNameToTypeMap));
final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
nameToDescriptorMap.put("BOB", new IdentDescriptor(-10.0));
assertEquals(new Double(26.0), interpreter.execute(compiler.getEquation(), nameToDescriptorMap));
}
use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class InterpreterTest method testFunctionWithBadRuntimeReturnType.
@Test
public void testFunctionWithBadRuntimeReturnType() throws Exception {
final Function badReturnFunction = new BadReturnFunction();
if (// Avoid duplicate registration!
parser.getFunction(badReturnFunction.getName()) == null)
parser.registerFunctionInternal(badReturnFunction);
final Map<String, Class<?>> attribNameToTypeMap = new HashMap<String, Class<?>>();
assertTrue(compiler.compile("=BAD()", attribNameToTypeMap));
final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
try {
interpreter.execute(compiler.getEquation(), nameToDescriptorMap);
} catch (final IllegalStateException e) {
// If we get here, everything is as expected and we let the test pass!
}
}
use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class InterpreterImpl method aref.
private void aref() throws EmptyStackException {
final String attribName = (String) argumentStack.pop();
final IdentDescriptor identDescriptor = variableNameToDescriptorMap.get(attribName);
if (identDescriptor == null)
throw new IllegalStateException("unknown column reference: \"" + attribName + "\" (1).");
final Object value = identDescriptor.getValue();
if (value == null)
throw new IllegalStateException("undefined column reference: \"" + attribName + "\".");
argumentStack.push(value);
}
use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class Framework method executeTestExpectFailure.
/**
* Excecute a test that should fail at either compile time or runtime.
* @return true if the test fails at compile time or runtime, otherwise false
*/
static boolean executeTestExpectFailure(final String equation, final Map<String, Object> variablesAndValues) {
final Map<String, Class<?>> varNameToTypeMap = new HashMap<String, Class<?>>();
for (final String variableName : variablesAndValues.keySet()) varNameToTypeMap.put(variableName, variablesAndValues.get(variableName).getClass());
try {
if (!compiler.compile(equation, varNameToTypeMap)) {
System.err.println("Error while compiling \"" + equation + "\": " + compiler.getLastErrorMsg());
return true;
}
} catch (final Exception e) {
System.err.println("Error while compiling \"" + equation + "\": " + e.getMessage());
return true;
}
final Map<String, IdentDescriptor> nameToDescriptorMap = new HashMap<String, IdentDescriptor>();
try {
for (final String variableName : variablesAndValues.keySet()) nameToDescriptorMap.put(variableName, new IdentDescriptor(variablesAndValues.get(variableName)));
} catch (final Exception e) {
System.err.println("Error while processing variables for \"" + equation + "\": " + e.getMessage());
return true;
}
final Interpreter interpreter = new InterpreterImpl();
try {
final Object result = interpreter.execute(compiler.getEquation(), nameToDescriptorMap);
// We should never get here!
return false;
} catch (final Exception e) {
return true;
}
}
Aggregations