Author: ruschein
Date: 2010-12-03 16:20:54 -0800 (Fri, 03 Dec 2010)
New Revision: 23088

Modified:
   
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
   
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 more tests for CyTable/CyRow.

Modified: 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
===================================================================
--- 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
    2010-12-03 23:55:34 UTC (rev 23087)
+++ 
core3/model-api/trunk/src/test/java/org/cytoscape/model/AbstractCyTableTest.java
    2010-12-04 00:20:54 UTC (rev 23088)
@@ -452,11 +452,54 @@
        }
 
        @Test
-       public void testSetlist() {
+       public void testSetList() {
                table.createListColumn("l", String.class);
                final List<String> strings = new ArrayList<String>();
                strings.add("joe");
                attrs.set("l", strings);
                assertEquals(attrs.getList("l", String.class), strings);
        }
+
+       @Test(expected=IllegalArgumentException.class)
+       public void testGetColumnValuesWithNonExistentColumnName() {
+               table.getColumnValues("l", String.class);
+       }
+
+       @Test(expected=NullPointerException.class)
+       public void testSetWithNullColumnName() {
+               table.createColumn("l", String.class);
+               attrs.set(null, "xyz");
+       }
+
+       @Test(expected=IllegalArgumentException.class)
+       public void testSetWithInvalidValueType() {
+               table.createColumn("l", Long.class);
+               attrs.set("l", "xyz");
+       }
+
+       @Test
+       public void testToStringMethodOfCyTable() {
+               table.createColumn("l", Long.class);
+               attrs.set("l", 13L);
+               assertTrue(table.toString().length() > 0);
+       }
+
+       @Test(expected=IllegalArgumentException.class)
+       public void testUnsetWithNonExistentColumnName() {
+               attrs.set("l", null);
+       }
+
+       @Test(expected=Exception.class)
+       public void testGetWhereGetListShouldHaveBeenUsed() {
+               table.createListColumn("l", Long.class);
+               attrs.set("l", new ArrayList<Long>());
+               attrs.get("l", Long.class);
+       }
+
+       @Test(expected=Exception.class)
+       public void testGetWithAnInvalidType() {
+               table.createColumn("l", Long.class);
+               attrs.set("l", 15L);
+               attrs.get("l", CyTable.class);
+       }
 }

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-12-03 23:55:34 UTC (rev 23087)
+++ 
core3/model-impl/trunk/impl/src/main/java/org/cytoscape/model/internal/CyTableImpl.java
     2010-12-04 00:20:54 UTC (rev 23088)
@@ -503,7 +503,7 @@
                        valueTokeysMap.remove(value);
        }
 
-       private Object getRawX(final Object key, final String columnName) {
+       private Object getValueOrEquation(final Object key, final String 
columnName) {
                Map<Object, Object> keyToValueMap = attributes.get(columnName);
                if (keyToValueMap == null)
                        return null;
@@ -515,7 +515,7 @@
                if (type.isAssignableFrom(List.class))
                        throw new IllegalArgumentException("use getList() to 
retrieve lists!");
 
-               final Object vl = getRawX(key, columnName);
+               final Object vl = getValueOrEquation(key, columnName);
                if (vl == null)
                        return null;
 
@@ -527,7 +527,7 @@
        }
 
        private Object getValue(Object key, String columnName) {
-               final Object vl = getRawX(key, columnName);
+               final Object vl = getValueOrEquation(key, columnName);
                if (vl == null)
                        return null;
 
@@ -550,7 +550,7 @@
                                                           + ", expected: " + 
expectedListElementType.getName()
                                                           + "!");
 
-               final Object vl = getRawX(key, columnName);
+               final Object vl = getValueOrEquation(key, columnName);
                if (vl == null)
                        return null;
 
@@ -656,7 +656,7 @@
                }
 
                public Object getRaw(String attributeName) {
-                       return getRawX(key, attributeName);
+                       return getValueOrEquation(key, attributeName);
                }
 
                public <T> boolean isSet(String attributeName, Class<? extends 
T> c) {
@@ -745,7 +745,7 @@
         *  @return an in-order list of attribute names that will have to be 
evaluated before "columnName" can be evaluated
         */
        private List<String> topoSortAttribReferences(final Object key, final 
String columnName) {
-               final Object equationCandidate = getRawX(key, columnName);
+               final Object equationCandidate = getValueOrEquation(key, 
columnName);
                if (!(equationCandidate instanceof Equation))
                        return new ArrayList<String>();
 
@@ -788,7 +788,7 @@
                        return;
 
                alreadyProcessed.add(columnName);
-               final Object equationCandidate = getRawX(key, columnName);
+               final Object equationCandidate = getValueOrEquation(key, 
columnName);
                if (!(equationCandidate instanceof Equation))
                        return;
 
@@ -807,7 +807,8 @@
        }
 
        /**
-        *  @return "d" converted to an Integer using Excel rules, should the 
number be outside the range of an int, null will be returned
+        *  @return "d" converted to an Integer using Excel rules, should the 
number be outside the
+        *          range of an int, null will be returned
         */
        private static Integer doubleToInteger(final double d) {
                if (d > Integer.MAX_VALUE || d < Integer.MIN_VALUE)
@@ -821,7 +822,8 @@
        }
 
        /**
-        *  @return "l" converted to an Integer using Excel rules, should the 
number be outside the range of an int, null will be returned
+        *  @return "l" converted to an Integer using Excel rules, should the 
number be outside the
+        *          range of an int, null will be returned
         */
        private static Integer longToInteger(final double l) {
                if (l >= Integer.MIN_VALUE && l <= Integer.MAX_VALUE)
@@ -831,9 +833,12 @@
        }
 
        /**
-        *  @return "equationValue" interpreted according to Excel rules as an 
integer or null if that is not possible
+        *  @return "equationValue" interpreted according to Excel rules as an 
integer or null if
+        *          that is not possible
         */
-       private Integer convertEqnRetValToInteger(final String id, final String 
columnName, final Object equationValue) {
+       private Integer convertEqnRetValToInteger(final String id, final String 
columnName,
+                                                 final Object equationValue)
+       {
                if (equationValue.getClass() == Double.class) {
                        final Integer retVal = 
doubleToInteger((Double)equationValue);
                        if (retVal == null)

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-12-03 23:55:34 UTC (rev 23087)
+++ 
core3/model-impl/trunk/impl/src/test/java/org/cytoscape/model/CyTableTest.java  
    2010-12-04 00:20:54 UTC (rev 23088)
@@ -178,4 +178,15 @@
 
                assertEquals(attrs.get("b", Double.class), 30.0, 0.00001);
        }
+
+       @Test
+       public void testSetWithAnEquationWhichReferencesANonExistentAttribute() 
{
+               table.createColumn("a", Double.class);
+               final Map<String, Class> varnameToTypeMap = new HashMap<String, 
Class>();
+               varnameToTypeMap.put("b", Double.class);
+               compiler.compile("=$b+10", varnameToTypeMap);
+               assertNull(table.getLastInternalError());
+               attrs.set("a", compiler.getEquation());
+               assertNotNull(table.getLastInternalError());
+       }
 }

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