use of org.cytoscape.equations.IdentDescriptor in project cytoscape-impl by cytoscape.
the class Framework method executeTest.
/**
* Execute a test that should succeed at compile time and runtime.
* @return true if the test compiled and ran and produced the expected result
*/
static boolean executeTest(final String equation, final Map<String, Object> variablesAndValues, final Object expectedResult) {
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 false;
}
} catch (final Exception e) {
System.err.println("Error while compiling \"" + equation + "\": " + e.getMessage());
return false;
}
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 false;
}
final Interpreter interpreter = new InterpreterImpl();
final Object actualResult;
try {
actualResult = interpreter.execute(compiler.getEquation(), nameToDescriptorMap);
} catch (final Exception e) {
System.err.println("caught runtime error: " + e.getMessage());
return false;
}
if (!areEqual(actualResult, expectedResult)) {
System.err.println("[" + equation + "] expected: " + expectedResult + ", found: " + actualResult);
return false;
}
return true;
}
Aggregations