Search in sources :

Example 11 with EquationParserImpl

use of org.cytoscape.equations.internal.EquationParserImpl in project cytoscape-impl by cytoscape.

the class OutDegreeTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new OutDegree(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=OUTDEGREE(101)", 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!", 3L, 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 12 with EquationParserImpl

use of org.cytoscape.equations.internal.EquationParserImpl in project cytoscape-impl by cytoscape.

the class TargetIDTest method test.

@Test
public void test() {
    final EquationParserImpl parser = new EquationParserImpl(serviceRegistrar);
    final EquationCompilerImpl compiler = new EquationCompilerImpl(parser);
    parser.registerFunctionInternal(new TargetID(serviceRegistrar));
    final Map<String, Class<?>> variableNameToTypeMap = new HashMap<String, Class<?>>();
    if (!compiler.compile("=TARGETID(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)

Aggregations

EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)12 EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)11 Interpreter (org.cytoscape.equations.Interpreter)9 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)9 Before (org.junit.Before)6 HashMap (java.util.HashMap)5 Equation (org.cytoscape.equations.Equation)5 IdentDescriptor (org.cytoscape.equations.IdentDescriptor)5 DummyCyEventHelper (org.cytoscape.event.DummyCyEventHelper)5 Test (org.junit.Test)5 EquationCompiler (org.cytoscape.equations.EquationCompiler)4 CyNetworkManagerImpl (org.cytoscape.model.internal.CyNetworkManagerImpl)4 CyNetworkTableManagerImpl (org.cytoscape.model.internal.CyNetworkTableManagerImpl)4 CyTableManagerImpl (org.cytoscape.model.internal.CyTableManagerImpl)4 CyServiceRegistrar (org.cytoscape.service.util.CyServiceRegistrar)4 TableAddedEvent (org.cytoscape.model.events.TableAddedEvent)2 CyTableFactoryImpl (org.cytoscape.model.internal.CyTableFactoryImpl)2 CyTableImpl (org.cytoscape.model.internal.CyTableImpl)2 CyNetworkNaming (org.cytoscape.session.CyNetworkNaming)2 CyEventHelper (org.cytoscape.event.CyEventHelper)1