1 46 package groovy.lang; 47 48 import java.util.List ; 49 50 import junit.framework.TestCase; 51 52 56 public class TupleTest extends TestCase { 57 58 Object [] data = { "a", "b", "c" }; 59 Tuple t = new Tuple(data); 60 61 public void testSize() { 62 assertEquals("Size of " + t, 3, t.size()); 63 64 assertEquals("get(0)", "a", t.get(0)); 65 assertEquals("get(1)", "b", t.get(1)); 66 } 67 68 public void testGetOutOfTuple() { 69 try { 70 t.get(-1); 71 fail("Should have thrown IndexOut"); 72 } 73 catch (IndexOutOfBoundsException e) { 74 } 76 try { 77 t.get(10); 78 fail("Should have thrown IndexOut"); 79 } 80 catch (IndexOutOfBoundsException e) { 81 } 83 84 } 85 86 public void testContains() { 87 assertTrue("contains a", t.contains("a")); 88 assertTrue("contains b", t.contains("b")); 89 } 90 91 public void testSubList() { 92 List s = t.subList(1, 2); 93 94 assertTrue("is a Tuple", s instanceof Tuple); 95 96 assertEquals("size", 1, s.size()); 97 } 98 99 public void testHashCodeAndEquals() { 100 Tuple a = new Tuple(new Object [] { "a", "b", "c" }); 101 Tuple b = new Tuple(new Object [] { "a", "b", "c" }); 102 Tuple c = new Tuple(new Object [] { "d", "b", "c" }); 103 104 assertEquals("hashcode", a.hashCode(), b.hashCode()); 105 assertTrue("hashcode", a.hashCode() != c.hashCode()); 106 107 assertEquals("a and b", a, b); 108 assertFalse("a != c", a.equals(c)); 109 } 110 111 public void testIterator() { 112 } 113 114 } 115 | Popular Tags |