001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.collections.primitives;
018
019import junit.framework.Test;
020import junit.framework.TestCase;
021import junit.framework.TestSuite;
022
023/**
024 * @version $Revision: 480451 $ $Date: 2006-11-29 02:45:08 -0500 (Wed, 29 Nov 2006) $
025 * @author Rodney Waldhoff
026 */
027public class TestFloatCollections extends TestCase {
028
029    //------------------------------------------------------------ Conventional
030
031    public TestFloatCollections(String testName) {
032        super(testName);
033    }
034
035    public static Test suite() {
036        return new TestSuite(TestFloatCollections.class);
037    }
038
039    //---------------------------------------------------------------- Tests
040
041    public void testSingletonFloatListIterator() {
042        FloatListIterator iter = FloatCollections.singletonFloatListIterator((float)17);
043        assertTrue(!iter.hasPrevious());        
044        assertTrue(iter.hasNext());        
045        assertEquals(17,iter.next(),(float)0);        
046        assertTrue(iter.hasPrevious());        
047        assertTrue(!iter.hasNext());        
048        assertEquals(17,iter.previous(),(float)0);        
049        try {
050            iter.set((float)18);
051            fail("Expected UnsupportedOperationException");
052        } catch(UnsupportedOperationException e) {
053            // expected
054        }
055    }
056
057    public void testSingletonFloatIterator() {
058        FloatIterator iter = FloatCollections.singletonFloatIterator((float)17);
059        assertTrue(iter.hasNext());        
060        assertEquals(17,iter.next(),(float)0);        
061        assertTrue(!iter.hasNext());        
062        try {
063            iter.remove();
064            fail("Expected UnsupportedOperationException");
065        } catch(UnsupportedOperationException e) {
066            // expected
067        }
068    }
069
070    public void testSingletonFloatList() {
071        FloatList list = FloatCollections.singletonFloatList((float)17);
072        assertEquals(1,list.size());
073        assertEquals(17,list.get(0),(float)0);        
074        try {
075            list.add((float)18);
076            fail("Expected UnsupportedOperationException");
077        } catch(UnsupportedOperationException e) {
078            // expected
079        }
080    }
081
082    public void testUnmodifiableFloatListNull() {
083        try {
084            FloatCollections.unmodifiableFloatList(null);
085            fail("Expected NullPointerException");
086        } catch(NullPointerException e) {
087            // expected
088        }
089    }
090
091    public void testEmptyFloatList() {
092        assertSame(FloatCollections.EMPTY_FLOAT_LIST,FloatCollections.getEmptyFloatList());
093        assertTrue(FloatCollections.EMPTY_FLOAT_LIST.isEmpty());
094        try {
095            FloatCollections.EMPTY_FLOAT_LIST.add((float)1);
096            fail("Expected UnsupportedOperationExcpetion");
097        } catch(UnsupportedOperationException e) {
098            // expected
099        }
100    }
101
102    public void testUnmodifiableFloatIteratorNull() {
103        try {
104            FloatCollections.unmodifiableFloatIterator(null);
105            fail("Expected NullPointerException");
106        } catch(NullPointerException e) {
107            // expected
108        }
109    }
110
111    public void testEmptyFloatIterator() {
112        assertSame(FloatCollections.EMPTY_FLOAT_ITERATOR,FloatCollections.getEmptyFloatIterator());
113        assertTrue(! FloatCollections.EMPTY_FLOAT_ITERATOR.hasNext());
114        try {
115            FloatCollections.EMPTY_FLOAT_ITERATOR.remove();
116            fail("Expected UnsupportedOperationExcpetion");
117        } catch(UnsupportedOperationException e) {
118            // expected
119        }
120    }
121
122    public void testUnmodifiableFloatListIteratorNull() {
123        try {
124            FloatCollections.unmodifiableFloatListIterator(null);
125            fail("Expected NullPointerException");
126        } catch(NullPointerException e) {
127            // expected
128        }
129    }
130
131    public void testEmptyFloatListIterator() {
132        assertSame(FloatCollections.EMPTY_FLOAT_LIST_ITERATOR,FloatCollections.getEmptyFloatListIterator());
133        assertTrue(! FloatCollections.EMPTY_FLOAT_LIST_ITERATOR.hasNext());
134        assertTrue(! FloatCollections.EMPTY_FLOAT_LIST_ITERATOR.hasPrevious());
135        try {
136            FloatCollections.EMPTY_FLOAT_LIST_ITERATOR.add((float)1);
137            fail("Expected UnsupportedOperationExcpetion");
138        } catch(UnsupportedOperationException e) {
139            // expected
140        }
141    }
142}
143