Search in sources :

Example 6 with EquationCompilerImpl

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

the class DegreeTest method test.

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

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

the class TestCyNetworkFactory method mockCyServiceRegistrar.

private static CyServiceRegistrar mockCyServiceRegistrar(CyEventHelper deh) {
    CyServiceRegistrar serviceRegistrar = mock(CyServiceRegistrar.class);
    CyNetworkNaming namingUtil = mock(CyNetworkNaming.class);
    EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    final Interpreter interpreter = new InterpreterImpl();
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(deh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    return serviceRegistrar;
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) Interpreter(org.cytoscape.equations.Interpreter) CyNetworkNaming(org.cytoscape.session.CyNetworkNaming) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyServiceRegistrar(org.cytoscape.service.util.CyServiceRegistrar)

Example 8 with EquationCompilerImpl

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

the class TestCyNetworkFactory method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    eh = new DummyCyEventHelper(false);
    Interpreter interpreter = new InterpreterImpl();
    EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eh);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    when(serviceRegistrar.getService(Interpreter.class)).thenReturn(interpreter);
    netTblMgr = new CyNetworkTableManagerImpl();
    netMgr = new CyNetworkManagerImpl(serviceRegistrar);
    tblMgr = new CyTableManagerImpl(netTblMgr, netMgr, serviceRegistrar);
    tblFactory = new CyTableFactoryImpl(eh, serviceRegistrar);
    netFactory = new CyNetworkFactoryImpl(eh, tblMgr, netTblMgr, tblFactory, serviceRegistrar);
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) CyTableFactoryImpl(org.cytoscape.model.internal.CyTableFactoryImpl) Interpreter(org.cytoscape.equations.Interpreter) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) DummyCyEventHelper(org.cytoscape.event.DummyCyEventHelper) InterpreterImpl(org.cytoscape.equations.internal.interpreter.InterpreterImpl) CyNetworkFactoryImpl(org.cytoscape.model.internal.CyNetworkFactoryImpl) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) Before(org.junit.Before)

Example 9 with EquationCompilerImpl

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

the class TableTestSupportTest method setUp.

@Before
public void setUp() {
    eventHelper = support.getDummyCyEventHelper();
    EquationCompiler compiler = new EquationCompilerImpl(new EquationParserImpl(serviceRegistrar));
    when(serviceRegistrar.getService(CyEventHelper.class)).thenReturn(eventHelper);
    when(serviceRegistrar.getService(CyNetworkNaming.class)).thenReturn(namingUtil);
    when(serviceRegistrar.getService(EquationCompiler.class)).thenReturn(compiler);
    table = factory.createTable(Integer.toString(rand.nextInt(10000)), CyIdentifiable.SUID, Long.class, false, true);
    table2 = factory.createTable(Integer.toString(rand.nextInt(10000)), CyIdentifiable.SUID, Long.class, false, true);
    attrs = table.getRow(1l);
    CyTableManagerImpl tblMgr = new CyTableManagerImpl(new CyNetworkTableManagerImpl(), new CyNetworkManagerImpl(serviceRegistrar), serviceRegistrar);
    tblMgr.addTable(table);
    ((CyTableImpl) table).handleEvent(new TableAddedEvent(tblMgr, table));
    tblMgr.addTable(table2);
    ((CyTableImpl) table2).handleEvent(new TableAddedEvent(tblMgr, table2));
}
Also used : EquationParserImpl(org.cytoscape.equations.internal.EquationParserImpl) EquationCompilerImpl(org.cytoscape.equations.internal.EquationCompilerImpl) CyNetworkManagerImpl(org.cytoscape.model.internal.CyNetworkManagerImpl) CyNetworkTableManagerImpl(org.cytoscape.model.internal.CyNetworkTableManagerImpl) TableAddedEvent(org.cytoscape.model.events.TableAddedEvent) EquationCompiler(org.cytoscape.equations.EquationCompiler) CyTableManagerImpl(org.cytoscape.model.internal.CyTableManagerImpl) CyTableImpl(org.cytoscape.model.internal.CyTableImpl) Before(org.junit.Before)

Example 10 with EquationCompilerImpl

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

the class InDegreeTest method test.

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

Aggregations

EquationCompilerImpl (org.cytoscape.equations.internal.EquationCompilerImpl)12 EquationParserImpl (org.cytoscape.equations.internal.EquationParserImpl)11 Interpreter (org.cytoscape.equations.Interpreter)9 InterpreterImpl (org.cytoscape.equations.internal.interpreter.InterpreterImpl)9 HashMap (java.util.HashMap)6 Equation (org.cytoscape.equations.Equation)5 IdentDescriptor (org.cytoscape.equations.IdentDescriptor)5 Before (org.junit.Before)5 Test (org.junit.Test)5 EquationCompiler (org.cytoscape.equations.EquationCompiler)4 DummyCyEventHelper (org.cytoscape.event.DummyCyEventHelper)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)3 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