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

Comparing jsr166/src/test/tck/LongAccumulatorTest.java (file contents):
Revision 1.2 by dl, Thu Mar 21 00:26:43 2013 UTC vs.
Revision 1.7 by jsr166, Sun Apr 23 03:03:16 2017 UTC

# Line 4 | Line 4
4   * http://creativecommons.org/publicdomain/zero/1.0/
5   */
6  
7 < import junit.framework.*;
8 < import java.util.concurrent.*;
7 > import java.util.concurrent.Executors;
8 > import java.util.concurrent.ExecutorService;
9 > import java.util.concurrent.Phaser;
10   import java.util.concurrent.atomic.LongAccumulator;
11  
12 + import junit.framework.Test;
13 + import junit.framework.TestSuite;
14 +
15   public class LongAccumulatorTest extends JSR166TestCase {
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run(suite());
17 >        main(suite(), args);
18      }
19      public static Test suite() {
20          return new TestSuite(LongAccumulatorTest.class);
21      }
22  
23      /**
24 <     * default constructed initializes to zero
24 >     * new instance initialized to supplied identity
25       */
26      public void testConstructor() {
27 <        LongAccumulator ai = new LongAccumulator(Long::max, 0L);
28 <        assertEquals(0, ai.get());
27 >        for (long identity : new long[] { Long.MIN_VALUE, 0, Long.MAX_VALUE })
28 >            assertEquals(identity,
29 >                         new LongAccumulator(Long::max, identity).get());
30      }
31  
32      /**
# Line 38 | Line 43 | public class LongAccumulatorTest extends
43      }
44  
45      /**
46 <     * reset zeroes get
46 >     * reset() causes subsequent get() to return zero
47       */
48      public void testReset() {
49          LongAccumulator ai = new LongAccumulator(Long::max, 0L);
# Line 49 | Line 54 | public class LongAccumulatorTest extends
54      }
55  
56      /**
57 <     * getThenReset returns get then zeros
57 >     * getThenReset() returns current value; subsequent get() returns zero
58       */
59      public void testGetThenReset() {
60          LongAccumulator ai = new LongAccumulator(Long::max, 0L);
# Line 128 | Line 133 | public class LongAccumulatorTest extends
133          pool.shutdown();
134      }
135  
136 <   static final class AccTask implements Runnable {
136 >    static final class AccTask implements Runnable {
137          final LongAccumulator acc;
138          final Phaser phaser;
139          final int incs;
140          volatile long result;
141 <        AccTask(LongAccumulator acc, Phaser phaser, int incs) {
142 <            this.acc = acc;
141 >        AccTask(LongAccumulator acc, Phaser phaser, int incs) {
142 >            this.acc = acc;
143              this.phaser = phaser;
144              this.incs = incs;
145          }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines