Author: mes
Date: 2008-09-13 08:42:34 -0700 (Sat, 13 Sep 2008)
New Revision: 14906
Added:
csplugins/trunk/ucsd/mes/api/src/test/java/org/cytoscape/model/attrs/CyDataTableTest.java
Modified:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
Log:
added unit initial unit tests for CyDataTable
Modified:
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
2008-09-13 05:52:31 UTC (rev 14905)
+++
csplugins/trunk/ucsd/mes/api/src/main/java/org/cytoscape/model/attrs/impl/CyDataTableImpl.java
2008-09-13 15:42:34 UTC (rev 14906)
@@ -23,10 +23,13 @@
this.name = name;
this.pub = pub;
attributes = new HashMap<String,Map<Long,Object>>();
- if ( typeMap == null )
+ if ( typeMap == null ) {
types = new HashMap<String,Class<?>>();
- else {
+ unique = new HashMap<String,Boolean>();
+ } else {
types = new HashMap<String,Class<?>>(typeMap);
+ // TODO!
+ unique = new HashMap<String,Boolean>();
for ( String key : typeMap.keySet() )
attributes.put( key, new HashMap<Long,Object>()
);
}
Added:
csplugins/trunk/ucsd/mes/api/src/test/java/org/cytoscape/model/attrs/CyDataTableTest.java
===================================================================
---
csplugins/trunk/ucsd/mes/api/src/test/java/org/cytoscape/model/attrs/CyDataTableTest.java
2008-09-13 05:52:31 UTC (rev 14905)
+++
csplugins/trunk/ucsd/mes/api/src/test/java/org/cytoscape/model/attrs/CyDataTableTest.java
2008-09-13 15:42:34 UTC (rev 14906)
@@ -0,0 +1,145 @@
+
+package org.cytoscape.model.attrs;
+
+import org.cytoscape.model.attrs.CyDataTable;
+import org.cytoscape.model.attrs.impl.CyDataTableImpl;
+
+import junit.framework.Assert;
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import java.lang.RuntimeException;
+import java.util.*;
+
+import java.awt.Color;
+
+public class CyDataTableTest extends TestCase {
+
+ private CyDataTable mgr;
+ private CyRow attrs;
+
+ public void setUp() {
+ mgr = new CyDataTableImpl(null,"homer",true);
+ attrs = mgr.getRow(1);
+ }
+
+ public void tearDown() {
+ }
+
+ public void testAddStringAttr() {
+ mgr.createColumn("someString",String.class,false);
+ mgr.createColumn("someStringElse",String.class,false);
+
+ attrs.set("someString","apple");
+ attrs.set("someStringElse","orange");
+
+ assertTrue( attrs.contains("someString",String.class) );
+ assertTrue( attrs.contains("someStringElse",String.class) );
+ assertFalse( attrs.contains("yetAnotherString",String.class) );
+
+ assertEquals( "apple", attrs.get("someString",String.class) );
+ assertEquals( "orange",
attrs.get("someStringElse",String.class) );
+ }
+
+ public void testAddIntAttr() {
+ mgr.createColumn("someInt",Integer.class,false);
+ mgr.createColumn("someOtherInt",Integer.class,false);
+
+ attrs.set("someInt",50);
+ attrs.set("someOtherInt",100);
+
+ assertTrue( attrs.contains("someInt",Integer.class) );
+ assertTrue( attrs.contains("someOtherInt",Integer.class) );
+ assertFalse( attrs.contains("yetAnotherInteger",Integer.class)
);
+
+ assertEquals( 50, attrs.get("someInt",Integer.class).intValue()
);
+ assertEquals( 100,
attrs.get("someOtherInt",Integer.class).intValue() );
+ }
+
+ public void testAddDoubleAttr() {
+ mgr.createColumn("someDouble",Double.class,false);
+ mgr.createColumn("someOtherDouble",Double.class,false);
+
+ attrs.set("someDouble",3.14);
+ attrs.set("someOtherDouble",2.76);
+
+ assertTrue( attrs.contains("someDouble",Double.class) );
+ assertTrue( attrs.contains("someOtherDouble",Double.class) );
+ assertFalse( attrs.contains("yetAnotherDouble",Double.class) );
+
+ assertEquals( 3.14, attrs.get("someDouble",
Double.class).doubleValue() );
+ assertEquals( 2.76, attrs.get("someOtherDouble",
Double.class).doubleValue() );
+ }
+
+ public void testAddBooleanAttr() {
+ mgr.createColumn("someBoolean",Boolean.class,false);
+ mgr.createColumn("someOtherBoolean",Boolean.class,false);
+
+ attrs.set("someBoolean",true);
+ attrs.set("someOtherBoolean",false);
+
+ assertTrue( attrs.contains("someBoolean",Boolean.class) );
+ assertTrue( attrs.contains("someOtherBoolean",Boolean.class) );
+ assertFalse( attrs.contains("yetAnotherBoolean",Boolean.class)
);
+
+ assertTrue( attrs.get("someBoolean",Boolean.class) );
+ assertFalse( attrs.get("someOtherBoolean",Boolean.class) );
+ }
+
+ public void testAddListAttr() {
+ mgr.createColumn("someList",List.class,false);
+
+ List<String> l = new LinkedList<String>();
+ l.add("orange");
+ l.add("banana");
+
+ attrs.set("someList",l);
+
+ assertTrue( attrs.contains("someList",List.class) );
+
+ assertEquals( 2, attrs.get("someList",List.class).size() );
+ }
+
+ public void testAddMapAttr() {
+ mgr.createColumn("someMap",Map.class,false);
+
+ Map<String,Integer> m = new HashMap<String,Integer>();
+ m.put("orange",1);
+ m.put("banana",2);
+
+ attrs.set("someMap",m);
+
+ assertTrue( attrs.contains("someMap",Map.class) );
+
+ assertEquals( 2, attrs.get("someMap",Map.class).size() );
+ }
+
+ public void testAddBadAttr() {
+ try {
+ attrs.set("nodeColor",Color.white);
+ } catch (IllegalArgumentException e) {
+ // successfully caught the exception
+ return;
+ }
+ // shouldn't get here
+ fail();
+ }
+
+ public void testAddBadList() {
+ List<Color> l = new LinkedList<Color>();
+ l.add(Color.white);
+ l.add(Color.red);
+
+ try {
+ attrs.set("someList",l);
+ } catch (IllegalArgumentException e) {
+ // successfully caught the exception
+ return;
+ }
+ // shouldn't get here
+ fail();
+ }
+
+ // lots more needed
+}
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---