1 17 package org.apache.commons.collections.primitives; 18 19 import junit.framework.Test; 20 import junit.framework.TestCase; 21 import junit.framework.TestSuite; 22 23 27 public class TestDoubleCollections extends TestCase { 28 29 31 public TestDoubleCollections(String testName) { 32 super(testName); 33 } 34 35 public static Test suite() { 36 return new TestSuite(TestDoubleCollections.class); 37 } 38 39 41 public void testSingletonDoubleListIterator() { 42 DoubleListIterator iter = DoubleCollections.singletonDoubleListIterator((double)17); 43 assertTrue(!iter.hasPrevious()); 44 assertTrue(iter.hasNext()); 45 assertEquals(17,iter.next(),(double)0); 46 assertTrue(iter.hasPrevious()); 47 assertTrue(!iter.hasNext()); 48 assertEquals(17,iter.previous(),(double)0); 49 try { 50 iter.set((double)18); 51 fail("Expected UnsupportedOperationException"); 52 } catch(UnsupportedOperationException e) { 53 } 55 } 56 57 public void testSingletonDoubleIterator() { 58 DoubleIterator iter = DoubleCollections.singletonDoubleIterator((double)17); 59 assertTrue(iter.hasNext()); 60 assertEquals(17,iter.next(),(double)0); 61 assertTrue(!iter.hasNext()); 62 try { 63 iter.remove(); 64 fail("Expected UnsupportedOperationException"); 65 } catch(UnsupportedOperationException e) { 66 } 68 } 69 70 public void testSingletonDoubleList() { 71 DoubleList list = DoubleCollections.singletonDoubleList((double)17); 72 assertEquals(1,list.size()); 73 assertEquals(17,list.get(0),(double)0); 74 try { 75 list.add((double)18); 76 fail("Expected UnsupportedOperationException"); 77 } catch(UnsupportedOperationException e) { 78 } 80 } 81 82 public void testUnmodifiableDoubleListNull() { 83 try { 84 DoubleCollections.unmodifiableDoubleList(null); 85 fail("Expected NullPointerException"); 86 } catch(NullPointerException e) { 87 } 89 } 90 91 public void testEmptyDoubleList() { 92 assertSame(DoubleCollections.EMPTY_DOUBLE_LIST,DoubleCollections.getEmptyDoubleList()); 93 assertTrue(DoubleCollections.EMPTY_DOUBLE_LIST.isEmpty()); 94 try { 95 DoubleCollections.EMPTY_DOUBLE_LIST.add((double)1); 96 fail("Expected UnsupportedOperationExcpetion"); 97 } catch(UnsupportedOperationException e) { 98 } 100 } 101 102 public void testUnmodifiableDoubleIteratorNull() { 103 try { 104 DoubleCollections.unmodifiableDoubleIterator(null); 105 fail("Expected NullPointerException"); 106 } catch(NullPointerException e) { 107 } 109 } 110 111 public void testEmptyDoubleIterator() { 112 assertSame(DoubleCollections.EMPTY_DOUBLE_ITERATOR,DoubleCollections.getEmptyDoubleIterator()); 113 assertTrue(! DoubleCollections.EMPTY_DOUBLE_ITERATOR.hasNext()); 114 try { 115 DoubleCollections.EMPTY_DOUBLE_ITERATOR.remove(); 116 fail("Expected UnsupportedOperationExcpetion"); 117 } catch(UnsupportedOperationException e) { 118 } 120 } 121 122 public void testUnmodifiableDoubleListIteratorNull() { 123 try { 124 DoubleCollections.unmodifiableDoubleListIterator(null); 125 fail("Expected NullPointerException"); 126 } catch(NullPointerException e) { 127 } 129 } 130 131 public void testEmptyDoubleListIterator() { 132 assertSame(DoubleCollections.EMPTY_DOUBLE_LIST_ITERATOR,DoubleCollections.getEmptyDoubleListIterator()); 133 assertTrue(! DoubleCollections.EMPTY_DOUBLE_LIST_ITERATOR.hasNext()); 134 assertTrue(! DoubleCollections.EMPTY_DOUBLE_LIST_ITERATOR.hasPrevious()); 135 try { 136 DoubleCollections.EMPTY_DOUBLE_LIST_ITERATOR.add((double)1); 137 fail("Expected UnsupportedOperationExcpetion"); 138 } catch(UnsupportedOperationException e) { 139 } 141 } 142 } 143 144 | Popular Tags |