Author: ruschein
Date: 2010-11-10 14:05:26 -0800 (Wed, 10 Nov 2010)
New Revision: 22803

Added:
   core3/equations-functions-impl/trunk/src/test/
   core3/equations-functions-impl/trunk/src/test/java/
   core3/equations-functions-impl/trunk/src/test/java/org/
   core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/
   core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/
   
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/
   
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/
   
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/DegreeTest.java
Modified:
   
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java
Log:
Added the first test.

Modified: 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java
===================================================================
--- 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java
   2010-11-10 22:05:14 UTC (rev 22802)
+++ 
core3/equations-functions-impl/trunk/src/main/java/org/cytoscape/equations/internal/SUIDToNodeMapper.java
   2010-11-10 22:05:26 UTC (rev 22803)
@@ -15,13 +15,13 @@
        private final Map<Long, CyNode> suidToNodeMap = new HashMap<Long, 
CyNode>();
 
        public void handleEvent(final AddedNodeEvent event) {
-               final CyNode edge = event.getNode();
-               suidToNodeMap.put(edge.getSUID(), edge);
+               final CyNode node = event.getNode();
+               suidToNodeMap.put(node.getSUID(), node);
        }
 
        public void handleEvent(final AboutToRemoveNodeEvent event) {
-               final CyNode edge = event.getNode();
-               suidToNodeMap.remove(edge.getSUID());
+               final CyNode node = event.getNode();
+               suidToNodeMap.remove(node.getSUID());
        }
 
        public CyNode getNode(final Long id) {

Added: 
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/DegreeTest.java
                               (rev 0)
+++ 
core3/equations-functions-impl/trunk/src/test/java/org/cytoscape/equations/internal/functions/DegreeTest.java
       2010-11-10 22:05:26 UTC (rev 22803)
@@ -0,0 +1,93 @@
+/*
+  File: DegreeTest.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 DegreeTest {
+       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.ANY)).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 
Degree(applicationManager, suidToNodeMapper));
+               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));
+       }
+}

-- 
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