Skip to content

Commit 53f292a

Browse files
committed
Adjust testing infrastructure for #178.
1 parent 2f5f56e commit 53f292a

File tree

3 files changed

+46
-6
lines changed

3 files changed

+46
-6
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,11 @@ public StreamAnalyzer(boolean visitDocTags) {
8787
super(visitDocTags);
8888
}
8989

90+
public StreamAnalyzer(boolean visitDocTags, int nForStreams) {
91+
super(visitDocTags);
92+
this.nForStreams = nForStreams;
93+
}
94+
9095
public StreamAnalyzer(boolean visitDocTags, boolean findImplicitEntryPoints) {
9196
this(visitDocTags);
9297
this.findImplicitEntryPoints = findImplicitEntryPoints;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package p;
2+
3+
import java.util.Arrays;
4+
5+
import edu.cuny.hunter.streamrefactoring.annotations.*;
6+
7+
class A {
8+
@EntryPoint
9+
void m() {
10+
Arrays.stream(new Object[1]).count();
11+
}
12+
}

edu.cuny.hunter.streamrefactoring.tests/test cases/edu/cuny/hunter/streamrefactoring/ui/tests/ConvertStreamToParallelRefactoringTest.java

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ public class ConvertStreamToParallelRefactoringTest extends RefactoringTest {
7777

7878
private static final String ENTRY_POINT_FILE = "entry_points.txt";
7979

80+
private static final int N_TO_USE_FOR_STREAMS_DEFAULT = 2;
81+
8082
static {
8183
LOGGER.setLevel(Level.FINER);
8284
}
@@ -327,6 +329,15 @@ public String getRefactoringPath() {
327329
* Runs a single analysis test.
328330
*/
329331
private void helper(StreamAnalysisExpectedResult... expectedResults) throws Exception {
332+
helper(N_TO_USE_FOR_STREAMS_DEFAULT, expectedResults);
333+
}
334+
335+
/**
336+
* Runs a single analysis test.
337+
*/
338+
private void helper(int nToUseForStreams, StreamAnalysisExpectedResult... expectedResults) throws Exception {
339+
LOGGER.info("Using N = " + nToUseForStreams);
340+
330341
// compute the actual results.
331342
ICompilationUnit cu = createCUfromTestFile(getPackageP(), "A");
332343

@@ -336,7 +347,7 @@ private void helper(StreamAnalysisExpectedResult... expectedResults) throws Exce
336347

337348
ASTNode ast = parser.createAST(new NullProgressMonitor());
338349

339-
StreamAnalyzer analyzer = new StreamAnalyzer(false);
350+
StreamAnalyzer analyzer = new StreamAnalyzer(false, nToUseForStreams);
340351
ast.accept(analyzer);
341352

342353
analyzer.analyze();
@@ -472,6 +483,16 @@ public void testArraysStream() throws Exception {
472483
EnumSet.of(PreconditionFailure.NO_APPLICATION_CODE_IN_CALL_STRINGS)));
473484
}
474485

486+
/**
487+
* Test #80. We need to increase N here to 3.
488+
*/
489+
public void testArraysStream2() throws Exception {
490+
helper(3, new StreamAnalysisExpectedResult("Arrays.stream(new Object[1])",
491+
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, false, false,
492+
EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P2,
493+
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK, Collections.emptySet()));
494+
}
495+
475496
public void testConstructor() throws Exception {
476497
helper(new StreamAnalysisExpectedResult("new ArrayList().stream()",
477498
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, false, false,
@@ -728,12 +749,14 @@ public void testStaticInitializer() throws Exception {
728749
null, null, null, RefactoringStatus.ERROR, EnumSet.of(PreconditionFailure.CURRENTLY_NOT_HANDLED)));
729750
}
730751

752+
// N needs to be 3 here.
731753
public void testIntermediateOperations() throws Exception {
732-
helper(new StreamAnalysisExpectedResult("set.stream()", Collections.singleton(ExecutionMode.SEQUENTIAL),
733-
Collections.singleton(Ordering.ORDERED), false, true, false,
734-
EnumSet.of(TransformationAction.UNORDER, TransformationAction.CONVERT_TO_PARALLEL),
735-
PreconditionSuccess.P3, Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
736-
Collections.emptySet()));
754+
helper(3,
755+
new StreamAnalysisExpectedResult("set.stream()", Collections.singleton(ExecutionMode.SEQUENTIAL),
756+
Collections.singleton(Ordering.ORDERED), false, true, false,
757+
EnumSet.of(TransformationAction.UNORDER, TransformationAction.CONVERT_TO_PARALLEL),
758+
PreconditionSuccess.P3, Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
759+
Collections.emptySet()));
737760
}
738761

739762
public void testTypeResolution() throws Exception {

0 commit comments

Comments
 (0)