ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/AtomicIntegerTest.java
(Generate patch)

Comparing jsr166/src/test/tck/AtomicIntegerTest.java (file contents):
Revision 1.17 by jsr166, Sat Nov 21 02:07:26 2009 UTC vs.
Revision 1.20 by jsr166, Wed Aug 25 00:07:03 2010 UTC

# Line 11 | Line 11 | import java.util.concurrent.atomic.*;
11   import java.io.*;
12  
13   public class AtomicIntegerTest extends JSR166TestCase {
14 <    public static void main (String[] args) {
15 <        junit.textui.TestRunner.run (suite());
14 >    public static void main(String[] args) {
15 >        junit.textui.TestRunner.run(suite());
16      }
17      public static Test suite() {
18          return new TestSuite(AtomicIntegerTest.class);
19      }
20  
21 +    final int[] VALUES = {
22 +        Integer.MIN_VALUE, -1, 0, 1, 42, Integer.MAX_VALUE,
23 +    };
24 +
25      /**
26       * constructor initializes to given value
27       */
# Line 44 | Line 48 | public class AtomicIntegerTest extends J
48          assertEquals(2,ai.get());
49          ai.set(-3);
50          assertEquals(-3,ai.get());
47
51      }
52  
53      /**
# Line 57 | Line 60 | public class AtomicIntegerTest extends J
60          assertEquals(2,ai.get());
61          ai.lazySet(-3);
62          assertEquals(-3,ai.get());
60
63      }
64 +
65      /**
66       * compareAndSet succeeds in changing value if equal to expected else fails
67       */
# Line 68 | Line 71 | public class AtomicIntegerTest extends J
71          assertTrue(ai.compareAndSet(2,-4));
72          assertEquals(-4,ai.get());
73          assertFalse(ai.compareAndSet(-5,7));
74 <        assertFalse((7 == ai.get()));
74 >        assertEquals(-4,ai.get());
75          assertTrue(ai.compareAndSet(-4,7));
76          assertEquals(7,ai.get());
77      }
# Line 209 | Line 212 | public class AtomicIntegerTest extends J
212       */
213      public void testToString() {
214          AtomicInteger ai = new AtomicInteger();
215 <        for (int i = -12; i < 6; ++i) {
216 <            ai.set(i);
217 <            assertEquals(ai.toString(), Integer.toString(i));
215 >        assertEquals("0", ai.toString());
216 >        for (int x : VALUES) {
217 >            ai.set(x);
218 >            assertEquals(ai.toString(), Integer.toString(x));
219          }
220      }
221  
# Line 220 | Line 224 | public class AtomicIntegerTest extends J
224       */
225      public void testIntValue() {
226          AtomicInteger ai = new AtomicInteger();
227 <        for (int i = -12; i < 6; ++i) {
228 <            ai.set(i);
229 <            assertEquals(i, ai.intValue());
227 >        assertEquals(0, ai.intValue());
228 >        for (int x : VALUES) {
229 >            ai.set(x);
230 >            assertEquals(x, ai.intValue());
231          }
232      }
233  
229
234      /**
235       * longValue returns current value.
236       */
237      public void testLongValue() {
238          AtomicInteger ai = new AtomicInteger();
239 <        for (int i = -12; i < 6; ++i) {
240 <            ai.set(i);
241 <            assertEquals((long)i, ai.longValue());
239 >        assertEquals(0L, ai.longValue());
240 >        for (int x : VALUES) {
241 >            ai.set(x);
242 >            assertEquals((long)x, ai.longValue());
243          }
244      }
245  
# Line 243 | Line 248 | public class AtomicIntegerTest extends J
248       */
249      public void testFloatValue() {
250          AtomicInteger ai = new AtomicInteger();
251 <        for (int i = -12; i < 6; ++i) {
252 <            ai.set(i);
253 <            assertEquals((float)i, ai.floatValue());
251 >        assertEquals(0.0f, ai.floatValue());
252 >        for (int x : VALUES) {
253 >            ai.set(x);
254 >            assertEquals((float)x, ai.floatValue());
255          }
256      }
257  
# Line 254 | Line 260 | public class AtomicIntegerTest extends J
260       */
261      public void testDoubleValue() {
262          AtomicInteger ai = new AtomicInteger();
263 <        for (int i = -12; i < 6; ++i) {
264 <            ai.set(i);
265 <            assertEquals((double)i, ai.doubleValue());
263 >        assertEquals(0.0d, ai.doubleValue());
264 >        for (int x : VALUES) {
265 >            ai.set(x);
266 >            assertEquals((double)x, ai.doubleValue());
267          }
268      }
269  
263
264
270   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines