22 |
|
/** |
23 |
|
* constructor creates array of given size with all elements zero |
24 |
|
*/ |
25 |
< |
public void testConstructor(){ |
25 |
> |
public void testConstructor() { |
26 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
27 |
|
for (int i = 0; i < SIZE; ++i) |
28 |
|
assertEquals(0,ai.get(i)); |
55 |
|
/** |
56 |
|
* get and set for out of bound indices throw IndexOutOfBoundsException |
57 |
|
*/ |
58 |
< |
public void testIndexing(){ |
58 |
> |
public void testIndexing() { |
59 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
60 |
|
try { |
61 |
|
ai.get(SIZE); |
62 |
< |
} catch (IndexOutOfBoundsException success){ |
62 |
> |
} catch (IndexOutOfBoundsException success) { |
63 |
|
} |
64 |
|
try { |
65 |
|
ai.get(-1); |
66 |
< |
} catch (IndexOutOfBoundsException success){ |
66 |
> |
} catch (IndexOutOfBoundsException success) { |
67 |
|
} |
68 |
|
try { |
69 |
|
ai.set(SIZE, 0); |
70 |
< |
} catch (IndexOutOfBoundsException success){ |
70 |
> |
} catch (IndexOutOfBoundsException success) { |
71 |
|
} |
72 |
|
try { |
73 |
|
ai.set(-1, 0); |
74 |
< |
} catch (IndexOutOfBoundsException success){ |
74 |
> |
} catch (IndexOutOfBoundsException success) { |
75 |
|
} |
76 |
|
} |
77 |
|
|
78 |
|
/** |
79 |
|
* get returns the last value set at index |
80 |
|
*/ |
81 |
< |
public void testGetSet(){ |
81 |
> |
public void testGetSet() { |
82 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
83 |
|
for (int i = 0; i < SIZE; ++i) { |
84 |
|
ai.set(i, 1); |
93 |
|
/** |
94 |
|
* get returns the last value lazySet at index by same thread |
95 |
|
*/ |
96 |
< |
public void testGetLazySet(){ |
96 |
> |
public void testGetLazySet() { |
97 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
98 |
|
for (int i = 0; i < SIZE; ++i) { |
99 |
|
ai.lazySet(i, 1); |
108 |
|
/** |
109 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
110 |
|
*/ |
111 |
< |
public void testCompareAndSet(){ |
111 |
> |
public void testCompareAndSet() { |
112 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
113 |
|
for (int i = 0; i < SIZE; ++i) { |
114 |
|
ai.set(i, 1); |
149 |
|
* repeated weakCompareAndSet succeeds in changing value when equal |
150 |
|
* to expected |
151 |
|
*/ |
152 |
< |
public void testWeakCompareAndSet(){ |
152 |
> |
public void testWeakCompareAndSet() { |
153 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
154 |
|
for (int i = 0; i < SIZE; ++i) { |
155 |
|
ai.set(i, 1); |
164 |
|
/** |
165 |
|
* getAndSet returns previous value and sets to given value at given index |
166 |
|
*/ |
167 |
< |
public void testGetAndSet(){ |
167 |
> |
public void testGetAndSet() { |
168 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
169 |
|
for (int i = 0; i < SIZE; ++i) { |
170 |
|
ai.set(i, 1); |
177 |
|
/** |
178 |
|
* getAndAdd returns previous value and adds given value |
179 |
|
*/ |
180 |
< |
public void testGetAndAdd(){ |
180 |
> |
public void testGetAndAdd() { |
181 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
182 |
|
for (int i = 0; i < SIZE; ++i) { |
183 |
|
ai.set(i, 1); |
191 |
|
/** |
192 |
|
* getAndDecrement returns previous value and decrements |
193 |
|
*/ |
194 |
< |
public void testGetAndDecrement(){ |
194 |
> |
public void testGetAndDecrement() { |
195 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
196 |
|
for (int i = 0; i < SIZE; ++i) { |
197 |
|
ai.set(i, 1); |
204 |
|
/** |
205 |
|
* getAndIncrement returns previous value and increments |
206 |
|
*/ |
207 |
< |
public void testGetAndIncrement(){ |
207 |
> |
public void testGetAndIncrement() { |
208 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
209 |
|
for (int i = 0; i < SIZE; ++i) { |
210 |
|
ai.set(i, 1); |
235 |
|
/** |
236 |
|
* decrementAndGet decrements and returns current value |
237 |
|
*/ |
238 |
< |
public void testDecrementAndGet(){ |
238 |
> |
public void testDecrementAndGet() { |
239 |
|
AtomicLongArray ai = new AtomicLongArray(SIZE); |
240 |
|
for (int i = 0; i < SIZE; ++i) { |
241 |
|
ai.set(i, 1); |
331 |
|
for (int i = 0; i < SIZE; ++i) { |
332 |
|
assertEquals(l.get(i), r.get(i)); |
333 |
|
} |
334 |
< |
} catch (Exception e){ |
334 |
> |
} catch (Exception e) { |
335 |
|
unexpectedException(); |
336 |
|
} |
337 |
|
} |