001 /* 002 * Created on Jul 31, 2005 003 * 004 */ 005 package aima.test.utiltest; 006 007 import java.util.ArrayList; 008 import java.util.List; 009 010 import junit.framework.TestCase; 011 import aima.util.Table; 012 013 /** 014 * @author Ravi Mohan 015 * 016 */ 017 018 public class TableTest extends TestCase { 019 private Table<String, String, Integer> table; 020 021 @Override 022 public void setUp() { 023 List<String> rowHeaders = new ArrayList<String>(); 024 List<String> columnHeaders = new ArrayList<String>(); 025 026 rowHeaders.add("row1"); 027 rowHeaders.add("ravi"); 028 rowHeaders.add("peter"); 029 030 columnHeaders.add("col1"); 031 columnHeaders.add("iq"); 032 columnHeaders.add("age"); 033 table = new Table<String, String, Integer>(rowHeaders, columnHeaders); 034 035 } 036 037 public void testTableInitialization() { 038 assertNull(table.get("ravi", "iq")); 039 table.set("ravi", "iq", 50); 040 int i = table.get("ravi", "iq"); 041 assertEquals(50, i); 042 } 043 044 public void testNullAccess() { 045 // No value yet assigned 046 assertNull(table.get("row1", "col2")); 047 table.set("row1", "col1", 1); 048 assertEquals(1, (int) table.get("row1", "col1")); 049 // Check null returned if column does not exist 050 assertNull(table.get("row1", "col2")); 051 // Check null returned if row does not exist 052 assertNull(table.get("row2", "col1")); 053 } 054 055 }