Author: ruschein
Date: 2010-11-10 14:15:32 -0800 (Wed, 10 Nov 2010)
New Revision: 22805

Added:
   
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/InDegreeTest.java
   
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/OutDegreeTest.java
Modified:
   
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java
   
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java
   
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java
Log:
Added 2 more tests.

Modified: 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java
===================================================================
--- 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java
  2010-11-10 22:08:56 UTC (rev 22804)
+++ 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/FunctionRegistrar.java
  2010-11-10 22:15:32 UTC (rev 22805)
@@ -28,8 +28,8 @@
        private void registerAllFunctions() {
                final EqnParser parser = compiler.getParser();
                parser.registerFunction(new Degree(applicationManager, 
suidToNodeMapper));
-               parser.registerFunction(new InDegree(suidToNodeMapper, 
applicationManager));
-               parser.registerFunction(new OutDegree(suidToNodeMapper, 
applicationManager));
+               parser.registerFunction(new InDegree(applicationManager, 
suidToNodeMapper));
+               parser.registerFunction(new OutDegree(applicationManager, 
suidToNodeMapper));
                parser.registerFunction(new SourceID(suidToEdgeMapper));
                parser.registerFunction(new TargetID(suidToEdgeMapper));
        }

Modified: 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java
===================================================================
--- 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java
 2010-11-10 22:08:56 UTC (rev 22804)
+++ 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/InDegree.java
 2010-11-10 22:15:32 UTC (rev 22805)
@@ -44,15 +44,15 @@
 
 
 public class InDegree extends AbstractFunction {
+       private final CyApplicationManager applicationManager;
        private final SUIDToNodeMapper suidToNodeMapper;
-       private final CyApplicationManager applicationManager;
 
-       public InDegree(final SUIDToNodeMapper suidToNodeMapper,
-                       final CyApplicationManager applicationManager)
+       public InDegree(final CyApplicationManager applicationManager,
+                       final SUIDToNodeMapper suidToNodeMapper)
        {
                super(new ArgDescriptor[] { new ArgDescriptor(ArgType.INT, 
"node_ID", "An ID identifying a node.") });
+               this.applicationManager = applicationManager;
                this.suidToNodeMapper = suidToNodeMapper;
-               this.applicationManager = applicationManager;
        }
 
        /**

Modified: 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java
===================================================================
--- 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java
        2010-11-10 22:08:56 UTC (rev 22804)
+++ 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/functions/OutDegree.java
        2010-11-10 22:15:32 UTC (rev 22805)
@@ -44,15 +44,15 @@
 
 
 public class OutDegree extends AbstractFunction {
+       private final CyApplicationManager applicationManager;
        private final SUIDToNodeMapper suidToNodeMapper;
-       private final CyApplicationManager applicationManager;
 
-       public OutDegree(final SUIDToNodeMapper suidToNodeMapper,
-                        final CyApplicationManager applicationManager)
+       public OutDegree(final CyApplicationManager applicationManager,
+                        final SUIDToNodeMapper suidToNodeMapper)
        {
                super(new ArgDescriptor[] { new ArgDescriptor(ArgType.INT, 
"node_ID", "An ID identifying a node.") });
+               this.applicationManager = applicationManager;
                this.suidToNodeMapper = suidToNodeMapper;
-               this.applicationManager = applicationManager;
        }
 
        /**

Copied: 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/InDegreeTest.java
 (from rev 22803, 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/DegreeTest.java)
===================================================================
--- 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/InDegreeTest.java
                             (rev 0)
+++ 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/InDegreeTest.java
     2010-11-10 22:15:32 UTC (rev 22805)
@@ -0,0 +1,93 @@
+/*
+  File: InDegreeTest.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.internal.functions;
+
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.mockito.Mockito.*;
+
+import org.cytoscape.equations.EqnCompiler;
+import org.cytoscape.equations.Equation;
+import org.cytoscape.equations.IdentDescriptor;
+import org.cytoscape.equations.Interpreter;
+import org.cytoscape.equations.internal.EqnCompilerImpl;
+import org.cytoscape.equations.internal.EqnParserImpl;
+import org.cytoscape.equations.internal.SUIDToNodeMapper;
+import org.cytoscape.equations.internal.interpreter.InterpreterImpl;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.events.AddedNodeEvent;
+import org.cytoscape.session.CyApplicationManager;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Before;
+
+
+public class InDegreeTest {
+       private SUIDToNodeMapper suidToNodeMapper;
+       private CyApplicationManager applicationManager;
+
+       @Before
+       public void init() {
+               final CyNode node = mock(CyNode.class);
+               when(node.getSUID()).thenReturn(101L);
+
+               final List<CyEdge> edgeList = mock(List.class);
+               when(edgeList.size()).thenReturn(3);
+
+               final CyNetwork network = mock(CyNetwork.class);
+               when(network.getAdjacentEdgeList(node, 
CyEdge.Type.INCOMING)).thenReturn(edgeList);
+
+               suidToNodeMapper = new SUIDToNodeMapper();
+               suidToNodeMapper.handleEvent(new AddedNodeEvent(network, node));
+
+               applicationManager = mock(CyApplicationManager.class);
+               
when(applicationManager.getCurrentNetwork()).thenReturn(network);
+       }
+
+       @Test
+       public void test() {
+               final EqnCompiler compiler = new EqnCompilerImpl(new 
EqnParserImpl());
+               compiler.getParser().registerFunction(new 
InDegree(applicationManager, suidToNodeMapper));
+               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));
+       }
+}

Copied: 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/OutDegreeTest.java
 (from rev 22803, 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/DegreeTest.java)
===================================================================
--- 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/OutDegreeTest.java
                            (rev 0)
+++ 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/OutDegreeTest.java
    2010-11-10 22:15:32 UTC (rev 22805)
@@ -0,0 +1,93 @@
+/*
+  File: OutDegreeTest.java
+
+  Copyright (c) 2010, The Cytoscape Consortium (www.cytoscape.org)
+
+  This library is free software; you can redistribute it and/or modify it
+  under the terms of the GNU Lesser General Public License as published
+  by the Free Software Foundation; either version 2.1 of the License, or
+  any later version.
+
+  This library is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY, WITHOUT EVEN THE IMPLIED WARRANTY OF
+  MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.  The software and
+  documentation provided hereunder is on an "as is" basis, and the
+  Institute for Systems Biology and the Whitehead Institute
+  have no obligations to provide maintenance, support,
+  updates, enhancements or modifications.  In no event shall the
+  Institute for Systems Biology and the Whitehead Institute
+  be liable to any party for direct, indirect, special,
+  incidental or consequential damages, including lost profits, arising
+  out of the use of this software and its documentation, even if the
+  Institute for Systems Biology and the Whitehead Institute
+  have been advised of the possibility of such damage.  See
+  the GNU Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public License
+  along with this library; if not, write to the Free Software Foundation,
+  Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+*/
+package org.cytoscape.equations.internal.functions;
+
+
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.mockito.Mockito.*;
+
+import org.cytoscape.equations.EqnCompiler;
+import org.cytoscape.equations.Equation;
+import org.cytoscape.equations.IdentDescriptor;
+import org.cytoscape.equations.Interpreter;
+import org.cytoscape.equations.internal.EqnCompilerImpl;
+import org.cytoscape.equations.internal.EqnParserImpl;
+import org.cytoscape.equations.internal.SUIDToNodeMapper;
+import org.cytoscape.equations.internal.interpreter.InterpreterImpl;
+import org.cytoscape.model.CyEdge;
+import org.cytoscape.model.CyNetwork;
+import org.cytoscape.model.CyNode;
+import org.cytoscape.model.events.AddedNodeEvent;
+import org.cytoscape.session.CyApplicationManager;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+import org.junit.Before;
+
+
+public class OutDegreeTest {
+       private SUIDToNodeMapper suidToNodeMapper;
+       private CyApplicationManager applicationManager;
+
+       @Before
+       public void init() {
+               final CyNode node = mock(CyNode.class);
+               when(node.getSUID()).thenReturn(101L);
+
+               final List<CyEdge> edgeList = mock(List.class);
+               when(edgeList.size()).thenReturn(3);
+
+               final CyNetwork network = mock(CyNetwork.class);
+               when(network.getAdjacentEdgeList(node, 
CyEdge.Type.OUTGOING)).thenReturn(edgeList);
+
+               suidToNodeMapper = new SUIDToNodeMapper();
+               suidToNodeMapper.handleEvent(new AddedNodeEvent(network, node));
+
+               applicationManager = mock(CyApplicationManager.class);
+               
when(applicationManager.getCurrentNetwork()).thenReturn(network);
+       }
+
+       @Test
+       public void test() {
+               final EqnCompiler compiler = new EqnCompilerImpl(new 
EqnParserImpl());
+               compiler.getParser().registerFunction(new 
OutDegree(applicationManager, suidToNodeMapper));
+               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));
+       }
+}

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to