9 |
|
import junit.framework.*; |
10 |
|
import java.util.concurrent.atomic.*; |
11 |
|
import java.io.*; |
12 |
+ |
import java.util.*; |
13 |
|
|
14 |
|
public class AtomicIntegerArrayTest extends JSR166TestCase { |
15 |
|
|
31 |
|
} |
32 |
|
|
33 |
|
/** |
34 |
+ |
* constructor with null array throws NPE |
35 |
+ |
*/ |
36 |
+ |
public void testConstructor2NPE() { |
37 |
+ |
try { |
38 |
+ |
int[] a = null; |
39 |
+ |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
40 |
+ |
} catch (NullPointerException success) { |
41 |
+ |
} catch (Exception ex) { |
42 |
+ |
unexpectedException(); |
43 |
+ |
} |
44 |
+ |
} |
45 |
+ |
|
46 |
+ |
/** |
47 |
+ |
* constructor with array is of same size and has all elements |
48 |
+ |
*/ |
49 |
+ |
public void testConstructor2() { |
50 |
+ |
int[] a = { 17, 3, -42, 99, -7}; |
51 |
+ |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
52 |
+ |
assertEquals(a.length, ai.length()); |
53 |
+ |
for (int i = 0; i < a.length; ++i) |
54 |
+ |
assertEquals(a[i], ai.get(i)); |
55 |
+ |
} |
56 |
+ |
|
57 |
+ |
/** |
58 |
|
* get and set for out of bound indices throw IndexOutOfBoundsException |
59 |
|
*/ |
60 |
|
public void testIndexing(){ |
93 |
|
} |
94 |
|
|
95 |
|
/** |
96 |
+ |
* get returns the last value lazySet at index by same thread |
97 |
+ |
*/ |
98 |
+ |
public void testGetLazySet() { |
99 |
+ |
AtomicIntegerArray ai = new AtomicIntegerArray(SIZE); |
100 |
+ |
for (int i = 0; i < SIZE; ++i) { |
101 |
+ |
ai.lazySet(i, 1); |
102 |
+ |
assertEquals(1,ai.get(i)); |
103 |
+ |
ai.lazySet(i, 2); |
104 |
+ |
assertEquals(2,ai.get(i)); |
105 |
+ |
ai.lazySet(i, -3); |
106 |
+ |
assertEquals(-3,ai.get(i)); |
107 |
+ |
} |
108 |
+ |
} |
109 |
+ |
|
110 |
+ |
/** |
111 |
|
* compareAndSet succeeds in changing value if equal to expected else fails |
112 |
|
*/ |
113 |
|
public void testCompareAndSet() { |
340 |
|
} |
341 |
|
} |
342 |
|
|
343 |
+ |
|
344 |
+ |
/** |
345 |
+ |
* toString returns current value. |
346 |
+ |
*/ |
347 |
+ |
public void testToString() { |
348 |
+ |
int[] a = { 17, 3, -42, 99, -7}; |
349 |
+ |
AtomicIntegerArray ai = new AtomicIntegerArray(a); |
350 |
+ |
assertEquals(Arrays.toString(a), ai.toString()); |
351 |
+ |
} |
352 |
+ |
|
353 |
|
} |