-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
251 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
generator/src/test/java/fr/inria/diversify/transformation/query/LoopFlipQueryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package fr.inria.diversify.transformation.query; | ||
|
||
import fr.inria.diversify.buildSystem.android.InvalidSdkException; | ||
import fr.inria.diversify.runner.InputConfiguration; | ||
import fr.inria.diversify.runner.InputProgram; | ||
import fr.inria.diversify.transformation.LoopFlip; | ||
import fr.inria.diversify.transformation.Transformation; | ||
import fr.inria.diversify.util.InitUtils; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import spoon.reflect.declaration.CtMethod; | ||
|
||
import java.io.File; | ||
import java.io.FileInputStream; | ||
import java.io.InputStream; | ||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import static org.junit.Assert.*; | ||
|
||
/** | ||
* Created by nharrand on 20/01/17. | ||
*/ | ||
public class LoopFlipQueryTest { | ||
|
||
InputProgram inputProgram; | ||
|
||
@Before | ||
public void setUp() { | ||
try { | ||
FileInputStream propertiesFile = new FileInputStream(new File("src/test/resources/jDummy/loopflip.properties")); | ||
InputConfiguration inputConfiguration = new InputConfiguration(propertiesFile); | ||
|
||
inputProgram = InitUtils.initInputProgram(inputConfiguration); | ||
|
||
InitUtils.initSpoon(inputProgram, false); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
public static boolean containsString(Iterable<String> s, String v) { | ||
for(String str : s) { | ||
if(str.compareTo(v) == 0) return true; | ||
} | ||
return false; | ||
} | ||
|
||
@Test | ||
public void query() throws Exception { | ||
LoopFlipQuery query = new LoopFlipQuery(inputProgram); | ||
Set<String> methods = new HashSet<>(); | ||
methods.add("loopZero"); | ||
methods.add("loopOne"); | ||
methods.add("loopTwo"); | ||
methods.add("loopThree"); | ||
methods.add("loopFour"); | ||
methods.add("loopFive"); | ||
methods.add("loopSix"); | ||
methods.add("loopSeven"); | ||
methods.add("loopEight"); | ||
methods.add("loopNine"); | ||
|
||
for(int i = 0; i < 9; i++) { | ||
LoopFlip t = (LoopFlip) query.query(); | ||
assertTrue(containsString(methods,t.methodLocationName())); | ||
} | ||
} | ||
|
||
@Test | ||
public void hasNextTransformation() throws Exception { | ||
TransformationQuery query = new LoopFlipQuery(inputProgram); | ||
|
||
for(int i = 0; i < 9; i++) { | ||
assertTrue(query.hasNextTransformation()); | ||
query.query(); | ||
} | ||
assertTrue(!query.hasNextTransformation()); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
project=src/test/resources/jDummy | ||
javaVersion=8 | ||
nbRun=2 | ||
timeOut=-1 | ||
runner=simple | ||
transformation.type=loopflip | ||
transformation.subtype=true | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>inria</groupId> | ||
<artifactId>java-dummy</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>java-dummy</name> | ||
<url>http://maven.apache.org</url> | ||
|
||
<properties> | ||
<maven.compiler.source>1.8</maven.compiler.source> | ||
<maven.compiler.target>1.8</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>3.8.1</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
</project> |
124 changes: 124 additions & 0 deletions
124
generator/src/test/resources/jDummy/src/main/java/inria/App.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
package inria; | ||
|
||
|
||
|
||
/** | ||
* Hello world! | ||
* | ||
*/ | ||
public class App | ||
{ | ||
public static void main( String[] args ) { | ||
|
||
System.out.println("0: " + loopZero()); | ||
System.out.println("1: " + loopOne()); | ||
System.out.println("2: " + loopTwo()); | ||
System.out.println("3: " + loopThree()); | ||
System.out.println("4: " + loopFour()); | ||
System.out.println("5: " + loopFive()); | ||
System.out.println("6: " + loopSix()); | ||
System.out.println("7: " + loopSeven()); | ||
System.out.println("8: " + loopEight()); | ||
System.out.println("9: " + loopNine()); | ||
System.out.println("10: " + loopTen()); | ||
System.out.println("11: " + loopEleven()); | ||
} | ||
|
||
public static int loopZero(){ | ||
int s = 0; | ||
for(int i = 0 ; 5 >= i; i = i + 1) { | ||
s += i; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopOne(){ | ||
int s = 0; | ||
for(int i = 0 ; i <= 5; i++) { | ||
s += i; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopTwo(){ | ||
int s = 0; | ||
for(int i = 5 ; i >= 0; i--) { | ||
s += i; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopThree(){ | ||
int s = 0; | ||
for(int i = 0 ; i < 6; i++) { | ||
s += i; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopFour(){ | ||
int s = 0; | ||
for(int i = 6 ; i > 1; i--) { | ||
s += i; | ||
} | ||
return s-5; //15 | ||
} | ||
|
||
public static int loopFive(){ | ||
int s = 0; | ||
for(int i = 0 ; i <= 10; i += 2) { | ||
s += i/2; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopSix(){ | ||
int s = 0; | ||
for(int i = 10 ; i >= 0; i -= 2) { | ||
s += i/2; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopSeven(){ | ||
int s = 0; | ||
for(int i = 0 ; i < 12; i += 2) { | ||
s += i/2; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopEight(){ | ||
int s = 0; | ||
for(int i = 12 ; i > 1; i -= 2) { | ||
s += i/2; | ||
} | ||
return s-6; //15 | ||
} | ||
|
||
public static int loopNine(){ | ||
int s = 0; | ||
for(int i = 0 ; i < 11; i += 2) { | ||
s += i/2; | ||
} | ||
return s; //15 | ||
} | ||
|
||
public static int loopTen(){ | ||
int s = 0; | ||
int[] array = {1,2,3,4,5}; | ||
for(int i : array) { | ||
s += i; | ||
} | ||
return s; | ||
} | ||
|
||
public static int loopEleven() { | ||
int s = 0; | ||
int[] array = {1,2,3,4,5}; | ||
for(int i : array) { | ||
s += i; | ||
} | ||
return s; | ||
} | ||
} |