test cases from srcml

This commit is contained in:
fixminer
2020-01-31 10:53:47 +01:00
parent 32b638f482
commit 8799804a82
11 changed files with 187 additions and 3 deletions
@@ -4,7 +4,7 @@ import com.github.gumtreediff.actions.model.Action;
import com.github.gumtreediff.gen.srcml.GumTreeCComparer;
import edu.lu.uni.serval.gumtree.GumTreeComparer;
import edu.lu.uni.serval.utils.ListSorter;
import redis.clients.jedis.JedisPool;
import java.io.File;
@@ -3,7 +3,7 @@ package edu.lu.uni.serval.fixminer.akka.ediff;
import com.github.gumtreediff.actions.model.*;
import com.github.gumtreediff.tree.ITree;
import edu.lu.uni.serval.utils.ASTNodeMap;
import edu.lu.uni.serval.utils.ListSorter;
import java.util.ArrayList;
import java.util.List;
@@ -7,7 +7,7 @@ import com.github.gumtreediff.gen.srcml.NodeMap_new;
import com.github.gumtreediff.io.CNodeMap;
import com.github.gumtreediff.tree.ITree;
import edu.lu.uni.serval.gumtree.GumTreeComparer;
import edu.lu.uni.serval.utils.ListSorter;
import java.util.ArrayList;
import java.util.List;
@@ -0,0 +1,45 @@
package edu.lu.uni.serval.fixminer.akka.ediff;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
public class ListSorter<T extends Comparable<? super T>> {
private List<T> list;
public ListSorter(List<T> list) {
this.list = new ArrayList<>();
this.list.addAll(list);
}
public List<T> getList() {
return this.list;
}
public List<T> sortAscending() {
try {
if (list != null && list.size() > 0) {
Collections.sort(this.list, new Comparator<T>() {
@Override
public int compare(T t1, T t2) {
return t1.compareTo(t2);
}
});
}
} catch (Exception e) {
return null;
}
return this.list;
}
public List<T> sortDescending() {
if (list != null && list.size() > 0) {
Collections.sort(this.list, Collections.reverseOrder());
}
return this.list;
}
}
@@ -0,0 +1,104 @@
package edu.lu.uni.serval.fixminer.akka.ediff;
import com.github.gumtreediff.tree.ITree;
import edu.lu.uni.serval.fixminer.akka.compare.AkkaTreeParser;
import edu.lu.uni.serval.utils.ClusterToPattern;
import edu.lu.uni.serval.utils.EDiffHelper;
import edu.lu.uni.serval.utils.PoolBuilder;
import org.apache.commons.io.FileUtils;
import org.javatuples.Pair;
import org.junit.Assert;
import org.junit.Test;
import redis.clients.jedis.JedisPool;
import java.io.File;
import java.io.IOException;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
public class TestPredefinedCases {
@Test
public void testIFCase1() throws IOException {
File revFile = new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/if_example_1.c");
File prevFile =new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/prev_if_example_1.c");
EDiffHunkParser parser = new EDiffHunkParser();
String srcMLPath = "/usr/local/bin/srcml";
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath);
hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.toString(),"[UPD if@@x >= 5 y += 4 @TO@ x > 5 y += 4 @AT@ 2 @LENGTH@ 13\n" +
"---UPD condition@@x >= 5 @TO@ x > 5 @AT@ 2 @LENGTH@ 9\n" +
"------UPD expr@@x >= 5 @TO@ x > 5 @AT@ 3 @LENGTH@ 6\n" +
"---------UPD operator@@>= @TO@ > @AT@ 5 @LENGTH@ 2\n" +
"]");
}
@Test
public void testForCase1() throws IOException {
File revFile = new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/for_example_1.c");
File prevFile =new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/prev_for_example_1.c");
EDiffHunkParser parser = new EDiffHunkParser();
String srcMLPath = "/usr/local/bin/srcml";
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath);
hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.size(),1);
Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@i = 0 i < max i ++ line ] == ' ' line ] == '\\t' tab ++ @TO@ i = 0 i < max i ++ line ] == ' ' space ++ line ] == '\\t' tab ++ @AT@ 4 @LENGTH@ 54\n" +
"---UPD block@@line ] == ' ' line ] == '\\t' tab ++ @TO@ line ] == ' ' space ++ line ] == '\\t' tab ++ @AT@ 26 @LENGTH@ 98\n" +
"------UPD if@@line ] == ' ' @TO@ line ] == ' ' space ++ @AT@ 33 @LENGTH@ 13\n" +
"---------UPD then@@ @TO@ space ++ @AT@ 54 @LENGTH@ 0\n" +
"------------UPD block@@ @TO@ space ++ @AT@ 54 @LENGTH@ 22\n" +
"---------------INS expr_stmt@@space ++ @TO@ block@@ @AT@ 62 @LENGTH@ 8\n" +
"------------------INS expr@@space ++ @TO@ expr_stmt@@space ++ @AT@ 62 @LENGTH@ 8\n" +
"---------------------INS name@@space @TO@ expr@@space ++ @AT@ 62 @LENGTH@ 5\n" +
"---------------------INS operator@@++ @TO@ expr@@space ++ @AT@ 67 @LENGTH@ 2\n" +
"---------------DEL continue@@ @AT@ 62 @LENGTH@ 0\n");
}
@Test
public void testWhileCase1() throws IOException {
File revFile = new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/while_example_1.c");
File prevFile =new File("/Users/anilkoyuncu/projects/fixminer/fixminer_source/src/main/resource/testFiles/prev_while_example_1.c");
EDiffHunkParser parser = new EDiffHunkParser();
String srcMLPath = "/usr/local/bin/srcml";
List<HierarchicalActionSet> hierarchicalActionSets = parser.parseChangedSourceCodeWithGumTree2(prevFile, revFile, srcMLPath);
hierarchicalActionSets.size();
Assert.assertEquals(hierarchicalActionSets.size(),1);
//TODO fixme
// Assert.assertEquals(hierarchicalActionSets.get(0).toString(),"UPD for@@i = 0 i < max i ++ line ] == ' ' line ] == '\\t' tab ++ @TO@ i = 0 i < max i ++ line ] == ' ' space ++ line ] == '\\t' tab ++ @AT@ 4 @LENGTH@ 54\n" +
// "---UPD block@@line ] == ' ' line ] == '\\t' tab ++ @TO@ line ] == ' ' space ++ line ] == '\\t' tab ++ @AT@ 26 @LENGTH@ 98\n" +
// "------UPD if@@line ] == ' ' @TO@ line ] == ' ' space ++ @AT@ 33 @LENGTH@ 13\n" +
// "---------UPD then@@ @TO@ space ++ @AT@ 54 @LENGTH@ 0\n" +
// "------------UPD block@@ @TO@ space ++ @AT@ 54 @LENGTH@ 22\n" +
// "---------------INS expr_stmt@@space ++ @TO@ block@@ @AT@ 62 @LENGTH@ 8\n" +
// "------------------INS expr@@space ++ @TO@ expr_stmt@@space ++ @AT@ 62 @LENGTH@ 8\n" +
// "---------------------INS name@@space @TO@ expr@@space ++ @AT@ 62 @LENGTH@ 5\n" +
// "---------------------INS operator@@++ @TO@ expr@@space ++ @AT@ 67 @LENGTH@ 2\n" +
// "---------------DEL continue@@ @AT@ 62 @LENGTH@ 0\n");
}
}
@@ -0,0 +1,11 @@
for (i = 0; i < max; i++ )
{
if ( line[i] == ' ' )
{
space++;
}
if ( line[i] == '\t' )
{
tab++;
}
}
@@ -0,0 +1,2 @@
if(x > 5)
y+=4;
@@ -0,0 +1,11 @@
for (i = 0; i < max; i++ )
{
if ( line[i] == ' ' )
{
continue;
}
if ( line[i] == '\t' )
{
tab++;
}
}
@@ -0,0 +1,2 @@
if(x >= 5)
y+=4;
@@ -0,0 +1,5 @@
do {
y = f( x );
x--;
print(x);
} while ( x > 0 );
@@ -0,0 +1,4 @@
do {
y = f( x );
x--;
} while ( x > 0 );