29import java.io.IOException;
33import org.jau.util.ArrayHashMap;
34import org.jau.util.ArrayHashSet;
35import org.junit.Assert;
36import org.junit.FixMethodOrder;
38import org.junit.runners.MethodSorters;
40import jau.test.junit.util.JunitTracer;
42@FixMethodOrder(MethodSorters.NAME_ASCENDING)
48 public Dummy(
final int i1,
final int i2,
final int i3) {
55 public boolean equals(
final Object o) {
56 if(o instanceof
Dummy) {
58 return this.i1 == d.i1 &&
69 hash = ((hash << 5) - hash) + i2;
70 hash = ((hash << 5) - hash) + i3;
76 return "Dummy["+super.toString()+
": "+i1+
", "+i2+
", "+i3+
"]";
80 void populate(
final Map<Integer, Dummy> l,
final int start,
final int len,
81 final int i2,
final int i3,
final int expectedPlusSize) {
82 final int oldSize = l.size();
83 for(
int pos = start+len-1; pos>=start; pos--) {
84 l.put(pos,
new Dummy(pos, i2, i3));
86 Assert.assertEquals(expectedPlusSize, l.size() - oldSize);
88 boolean checkOrder(
final List<Dummy> l,
final int startIdx,
final int start,
final int len) {
89 for(
int i=0; i<len; i++) {
90 final Dummy d = l.get(startIdx+i);
91 final int i1 = start+len-1-i;
101 testArrayHashMapImpl(
true);
105 testArrayHashMapImpl(
false);
107 void testArrayHashMapImpl(
final boolean supportNullValue) {
108 final ArrayHashMap<Integer, Dummy> l =
109 new ArrayHashMap<Integer, Dummy>(supportNullValue,
110 ArrayHashSet.DEFAULT_INITIAL_CAPACITY,
111 ArrayHashSet.DEFAULT_LOAD_FACTOR);
112 Assert.assertEquals(supportNullValue, l.supportsNullValue());
113 final int p7_22_34_key, p7_22_34_idx;
114 final Dummy p7_22_34_orig;
115 final int p6_22_34_key, p6_22_34_idx;
116 final Dummy p6_22_34_orig;
118 populate(l, 10, 100, 22, 34, 100);
119 Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100));
120 populate(l, 10, 100, 22, 34, 0);
121 Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100));
122 populate(l, 6, 5, 22, 34, 4);
123 Assert.assertTrue(checkOrder(l.getData(), 100, 6, 4));
124 p7_22_34_idx = l.size() - 2;
126 p7_22_34_orig = l.get(p7_22_34_key);
127 p6_22_34_idx = l.size() - 1;
129 p6_22_34_orig = l.get(p6_22_34_key);
131 Assert.assertNotNull(p7_22_34_orig);
132 Assert.assertEquals(7, p7_22_34_orig.i1);
133 Assert.assertEquals(l.getData().get(p7_22_34_idx), p7_22_34_orig);
134 Assert.assertNotNull(p6_22_34_orig);
135 Assert.assertEquals(6, p6_22_34_orig.i1);
136 Assert.assertEquals(l.getData().get(p6_22_34_idx), p6_22_34_orig);
138 final Dummy p7_22_34_other =
new Dummy(7, 22, 34);
139 Assert.assertEquals(p7_22_34_other, p7_22_34_orig);
140 Assert.assertTrue(p7_22_34_other.hashCode() == p7_22_34_orig.hashCode());
141 Assert.assertTrue(p7_22_34_other != p7_22_34_orig);
142 final Dummy p6_22_34_other =
new Dummy(6, 22, 34);
143 Assert.assertEquals(p6_22_34_other, p6_22_34_orig);
144 Assert.assertTrue(p6_22_34_other.hashCode() == p6_22_34_orig.hashCode());
145 Assert.assertTrue(p6_22_34_other != p6_22_34_orig);
148 Dummy q = l.get(p6_22_34_key);
149 Assert.assertNotNull(q);
150 Assert.assertEquals(p6_22_34_other, q);
151 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
152 Assert.assertTrue(p6_22_34_other != q);
153 Assert.assertTrue(p6_22_34_orig == q);
155 Assert.assertTrue(l.containsValue(q));
156 Assert.assertTrue(l.containsValue(p6_22_34_other));
158 q = l.put(p6_22_34_key, p6_22_34_other);
159 Assert.assertNotNull(q);
160 Assert.assertEquals(p6_22_34_other, q);
161 Assert.assertTrue(p6_22_34_other.hashCode() == q.hashCode());
162 Assert.assertTrue(p6_22_34_other != q);
163 Assert.assertTrue(p6_22_34_orig == q);
164 Assert.assertTrue(checkOrder(l.getData(), 0, 10, 100));
165 Assert.assertTrue(checkOrder(l.getData(), 100, 6, 4));
167 final Dummy p1_2_3 =
new Dummy(1, 2, 3);
168 q = l.put(1, p1_2_3);
169 Assert.assertNull(q);
171 final Dummy pNull =
null;
172 NullPointerException npe =
null;
175 Assert.assertNull(q);
176 }
catch (
final NullPointerException _npe) { npe = _npe; }
177 if( l.supportsNullValue() ) {
178 Assert.assertNull(npe);
180 Assert.assertNotNull(npe);
184 public static void main(
final String args[])
throws IOException {
186 org.junit.runner.JUnitCore.
main(tstname);
boolean equals(final Object o)
Dummy(final int i1, final int i2, final int i3)
void test02ArrayHashSetWithoutNullValue()
static void main(final String args[])
void test01ArrayHashMapWithNullValue()