Author: ruschein
Date: 2010-11-30 09:58:52 -0800 (Tue, 30 Nov 2010)
New Revision: 23052

Modified:
   
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
   
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableTest.java
Log:
Added some new unit tests and fixed a bug.

Modified: 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
     2010-11-30 16:45:00 UTC (rev 23051)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
     2010-11-30 17:58:52 UTC (rev 23052)
@@ -349,7 +349,8 @@
                        return;
                }
 
-               checkType(value);
+               if (!(value instanceof Equation))
+                       checkType(value);
 
                Map<Object, Object> vls = attributes.get(attrName);
 
@@ -544,9 +545,7 @@
                else if (o instanceof List) {
                        List l = (List) o;
 
-                       if (l.size() <= 0)
-                               throw new RuntimeException("empty list");
-                       else
+                       if (!l.isEmpty())
                                checkType(l.get(0));
                } else if (o instanceof Map) {
                        Map m = (Map) o;

Modified: 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableTest.java
===================================================================
--- 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableTest.java  
    2010-11-30 16:45:00 UTC (rev 23051)
+++ 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableTest.java  
    2010-11-30 17:58:52 UTC (rev 23052)
@@ -28,33 +28,77 @@
 package org.cytoscape.model;
 
 
+import java.util.HashMap;
+
+import org.cytoscape.equations.BooleanList;
+import org.cytoscape.equations.EqnCompiler;
+import org.cytoscape.equations.Equation;
 import org.cytoscape.equations.Interpreter;
+import org.cytoscape.equations.StringList;
+import org.cytoscape.equations.internal.EqnCompilerImpl;
+import org.cytoscape.equations.internal.EqnParserImpl;
 import org.cytoscape.equations.internal.interpreter.InterpreterImpl;
 import org.cytoscape.event.CyEventHelper;
 import org.cytoscape.event.DummyCyEventHelper;
 import org.cytoscape.model.internal.CyTableImpl;
 
 
-/**
- * DOCUMENT ME!
- */
 public class CyTableTest extends AbstractCyTableTest {
+       private final EqnCompiler compiler = new EqnCompilerImpl(new 
EqnParserImpl());
 
-       /**
-        * DOCUMENT ME!
-        */
        public void setUp() {
                eventHelper = new DummyCyEventHelper();
                final Interpreter interpreter = new InterpreterImpl();
                table = new CyTableImpl("homer", "SUID", Long.class, true, 
eventHelper, interpreter);
-               attrs = table.getRow(1l);
+               attrs = table.getRow(1L);
        }
 
-       /**
-        * DOCUMENT ME!
-        */
        public void tearDown() {
                table = null;
                attrs = null;
        }
+
+       public void testSetEquation() {
+               table.createColumn("someDouble", Double.class);
+               table.createColumn("someOtherDouble", Double.class);
+
+               compiler.compile("=6/3", new HashMap<String, Class>());
+               final Equation eqn = compiler.getEquation();
+               attrs.set("someDouble", eqn);
+
+               assertTrue(attrs.isSet("someDouble", Double.class));
+               assertEquals(2.0, attrs.get("someDouble", 
Double.class).doubleValue());
+       }
+
+       public void testSetEquationWithIncompatibleEquationReturnType() {
+               table.createColumn("someDouble", Double.class);
+               table.createColumn("someOtherDouble", Double.class);
+
+               compiler.compile("=\"String\"", new HashMap<String, Class>());
+               final Equation eqn = compiler.getEquation();
+               try {
+                       attrs.set("someDouble", eqn);
+                       fail();
+               } catch (IllegalArgumentException e) {
+                       /* Intentionally empty! */
+               }
+       }
+
+       public void testCreateList() {
+               table.createListColumn("booleanList", Boolean.class);
+               attrs.set("booleanList", new BooleanList());
+               final BooleanList nonEmptyList = new BooleanList(true, false);
+               attrs.set("booleanList", nonEmptyList);
+               assertEquals(attrs.getList("booleanList", Boolean.class), 
nonEmptyList);
+       }
+
+       public void testSetListWithACompatibleEquation() {
+               table.createListColumn("stringList", String.class);
+               attrs.set("stringList", new StringList());
+               compiler.compile("=SLIST(\"one\",\"two\")", new HashMap<String, 
Class>());
+               final Equation eqn = compiler.getEquation();
+               attrs.set("stringList", eqn);
+               final StringList expectedList = new StringList("one", "two");
+               assertEquals(attrs.getList("stringList", String.class), 
expectedList);
+       }
 }

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