1 8 package org.ozoneDB.collections; 9 10 import java.util.Iterator ; 11 import java.util.SortedSet ; 12 13 18 public abstract class OzoneSortedSetTest extends OzoneCollectionTest { 19 20 public OzoneSortedSetTest(String name) { 21 super(name); 22 } 23 24 public void compareResults(Object refResult, Object cmpResult) { 25 if (refResult instanceof SortedSet ) { 26 SortedSet refSet = (SortedSet ) refResult; 27 SortedSet cmpSet = (SortedSet ) cmpResult; 28 assertTrue("returned SortedSets should match size; ref: " + refSet.size() +", cmp: " + cmpSet.size(), 29 refSet.size() == cmpSet.size()); 30 Iterator iRef = refSet.iterator(); 31 Iterator iCmp = cmpSet.iterator(); 32 while (iRef.hasNext()) { 33 assertTrue("returned SortedSets should have 'equal' contents", 34 iRef.next().equals(iCmp.next())); 35 } 36 } else { 37 super.compareResults(refResult, cmpResult); 38 } 39 } 40 41 public void testFirst() { 42 compare("clear"); 43 compare("first"); 44 for (int i = 0; i < VALUES.length; i ++) { 45 compare("add", new Object [] {VALUES[i]}, PARAM_OBJECT); 46 compare("first"); 47 } 48 for (int i = 0; i < VALUES.length; i++) { 49 compare("remove", new Object [] {VALUES[i]}, PARAM_OBJECT); 50 compare("first"); 51 } 52 } 53 54 public void testHeadSet() { 55 compare("clear"); 56 compare("headSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 57 for (int i = 0; i < VALUES.length; i ++) { 58 compare("add", new Object [] {VALUES[i]}, PARAM_OBJECT); 59 compare("headSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 60 compare("headSet", new Object [] {"-1"}, PARAM_OBJECT); 61 compare("headSet", new Object [] {"99999999"}, PARAM_OBJECT); 62 } 63 for (int i = 0; i < VALUES.length; i++) { 64 compare("contains", new Object [] {VALUES[i]}, PARAM_OBJECT); 65 compare("headSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 66 compare("headSet", new Object [] {"-1"}, PARAM_OBJECT); 67 compare("headSet", new Object [] {"99999999"}, PARAM_OBJECT); 68 } 69 } 70 71 public void testLast() { 72 compare("clear"); 73 compare("last"); 74 for (int i = 0; i < VALUES.length; i ++) { 75 compare("add", new Object [] {VALUES[i]}, PARAM_OBJECT); 76 compare("last"); 77 } 78 for (int i = 0; i < VALUES.length; i++) { 79 compare("remove", new Object [] {VALUES[i]}, PARAM_OBJECT); 80 compare("last"); 81 } 82 } 83 84 public void testSubSet() { 85 compare("clear"); 86 compare("subSet", new Object [] {"-1", VALUES[VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 87 for (int i = 0; i < VALUES.length; i ++) { 88 compare("add", new Object [] {VALUES[i]}, PARAM_OBJECT); 89 compare("subSet", new Object [] {VALUES[VALUES.length / 2], VALUES[2 + VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 90 compare("subSet", new Object [] {VALUES[2 + VALUES.length / 2], VALUES[VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 91 compare("subSet", new Object [] {"-1", VALUES[VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 92 compare("subSet", new Object [] {"-1", "99999999"}, new Class [] {Object .class, Object .class}); 93 } 94 for (int i = 0; i < VALUES.length; i++) { 95 compare("contains", new Object [] {VALUES[i]}, PARAM_OBJECT); 96 compare("subSet", new Object [] {VALUES[VALUES.length / 2], VALUES[2 + VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 97 compare("subSet", new Object [] {VALUES[2 + VALUES.length / 2], VALUES[VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 98 compare("subSet", new Object [] {"-1", VALUES[VALUES.length / 2]}, new Class [] {Object .class, Object .class}); 99 compare("subSet", new Object [] {"-1", "99999999"}, new Class [] {Object .class, Object .class}); 100 } 101 } 102 103 public void testTailSet() { 104 compare("clear"); 105 compare("headSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 106 for (int i = 0; i < VALUES.length; i ++) { 107 compare("add", new Object [] {VALUES[i]}, PARAM_OBJECT); 108 compare("tailSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 109 compare("tailSet", new Object [] {"-1"}, PARAM_OBJECT); 110 compare("tailSet", new Object [] {"99999999"}, PARAM_OBJECT); 111 } 112 for (int i = 0; i < VALUES.length; i++) { 113 compare("contains", new Object [] {VALUES[i]}, PARAM_OBJECT); 114 compare("tailSet", new Object [] {VALUES[VALUES.length / 2]}, PARAM_OBJECT); 115 compare("tailSet", new Object [] {"-1"}, PARAM_OBJECT); 116 compare("tailSet", new Object [] {"99999999"}, PARAM_OBJECT); 117 } 118 } 119 120 } | Popular Tags |