1 21 package com.db4o.db4ounit.common.foundation; 22 23 import com.db4o.foundation.*; 24 25 import db4ounit.*; 26 27 30 public class SortedCollection4TestCase implements TestCase { 31 32 static final Comparison4 INTEGER_COMPARISON = new Comparison4() { 33 public int compare(Object x, Object y) { 34 return ((Integer )x).intValue()-((Integer )y).intValue(); 35 } 36 }; 37 38 public void testAddAllAndToArray() { 39 final Object [] array = IntArrays4.toObjectArray(new int[] { 6, 4, 1, 2, 7, 3 }); 40 41 SortedCollection4 collection = newSortedCollection(); 42 Assert.areEqual(0, collection.size()); 43 collection.addAll(new ArrayIterator4(array)); 44 45 assertCollection(new int[] { 1, 2, 3, 4, 6, 7 }, collection); 46 } 47 48 public void testToArrayOnEmptyCollection() { 49 final Object [] array = new Object [0]; 50 Assert.areSame(array, newSortedCollection().toArray(array)); 51 } 52 53 public void testAddRemove() { 54 final SortedCollection4 collection = newSortedCollection(); 55 collection.add(new Integer (3)); 56 collection.add(new Integer (1)); 57 collection.add(new Integer (5)); 58 59 assertCollection(new int[] { 1, 3, 5 }, collection); 60 61 collection.remove(new Integer (3)); 62 assertCollection(new int[] { 1, 5 }, collection); 63 64 collection.remove(new Integer (1)); 65 assertCollection(new int[] { 5 }, collection); 66 } 67 68 private void assertCollection(final int[] expected, SortedCollection4 collection) { 69 Assert.areEqual(expected.length, collection.size()); 70 ArrayAssert.areEqual( 71 IntArrays4.toObjectArray(expected), 72 collection.toArray(new Object [collection.size()])); 73 } 74 75 private SortedCollection4 newSortedCollection() { 76 return new SortedCollection4(INTEGER_COMPARISON); 77 } 78 79 } 80 | Popular Tags |