--- jsr166/src/test/tck/AtomicLongTest.java 2009/11/21 02:07:26 1.16 +++ jsr166/src/test/tck/AtomicLongTest.java 2011/03/15 19:47:06 1.20 @@ -1,7 +1,7 @@ /* * Written by Doug Lea with assistance from members of JCP JSR-166 * Expert Group and released to the public domain, as explained at - * http://creativecommons.org/licenses/publicdomain + * http://creativecommons.org/publicdomain/zero/1.0/ * Other contributors include Andrew Wright, Jeffrey Hayes, * Pat Fisher, Mike Judd. */ @@ -11,13 +11,19 @@ import java.util.concurrent.atomic.*; import java.io.*; public class AtomicLongTest extends JSR166TestCase { - public static void main (String[] args) { - junit.textui.TestRunner.run (suite()); + public static void main(String[] args) { + junit.textui.TestRunner.run(suite()); } public static Test suite() { return new TestSuite(AtomicLongTest.class); } + final long[] VALUES = { + Long.MIN_VALUE, + Integer.MIN_VALUE, -1, 0, 1, 42, Integer.MAX_VALUE, + Long.MAX_VALUE, + }; + /** * constructor initializes to given value */ @@ -44,7 +50,6 @@ public class AtomicLongTest extends JSR1 assertEquals(2,ai.get()); ai.set(-3); assertEquals(-3,ai.get()); - } /** @@ -57,7 +62,6 @@ public class AtomicLongTest extends JSR1 assertEquals(2,ai.get()); ai.lazySet(-3); assertEquals(-3,ai.get()); - } /** @@ -69,7 +73,7 @@ public class AtomicLongTest extends JSR1 assertTrue(ai.compareAndSet(2,-4)); assertEquals(-4,ai.get()); assertFalse(ai.compareAndSet(-5,7)); - assertFalse((7 == ai.get())); + assertEquals(-4,ai.get()); assertTrue(ai.compareAndSet(-4,7)); assertEquals(7,ai.get()); } @@ -210,20 +214,34 @@ public class AtomicLongTest extends JSR1 */ public void testToString() { AtomicLong ai = new AtomicLong(); - for (long i = -12; i < 6; ++i) { + assertEquals("0", ai.toString()); + for (long i : VALUES) { ai.set(i); assertEquals(ai.toString(), Long.toString(i)); } } /** + * intValue returns current value. + */ + public void testIntValue() { + AtomicLong ai = new AtomicLong(); + assertEquals(0, ai.intValue()); + for (long x : VALUES) { + ai.set(x); + assertEquals((int)x, ai.intValue()); + } + } + + /** * longValue returns current value. */ public void testLongValue() { AtomicLong ai = new AtomicLong(); - for (int i = -12; i < 6; ++i) { - ai.set(i); - assertEquals((long)i, ai.longValue()); + assertEquals(0L, ai.longValue()); + for (long x : VALUES) { + ai.set(x); + assertEquals((long)x, ai.longValue()); } } @@ -232,9 +250,10 @@ public class AtomicLongTest extends JSR1 */ public void testFloatValue() { AtomicLong ai = new AtomicLong(); - for (int i = -12; i < 6; ++i) { - ai.set(i); - assertEquals((float)i, ai.floatValue()); + assertEquals(0.0f, ai.floatValue()); + for (long x : VALUES) { + ai.set(x); + assertEquals((float)x, ai.floatValue()); } } @@ -243,11 +262,11 @@ public class AtomicLongTest extends JSR1 */ public void testDoubleValue() { AtomicLong ai = new AtomicLong(); - for (int i = -12; i < 6; ++i) { - ai.set(i); - assertEquals((double)i, ai.doubleValue()); + assertEquals(0.0d, ai.doubleValue()); + for (long x : VALUES) { + ai.set(x); + assertEquals((double)x, ai.doubleValue()); } } - }