-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add purity test + Disable TestAllRefactorings
- Loading branch information
Showing
5 changed files
with
29,793 additions
and
0 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
120 changes: 120 additions & 0 deletions
120
src/test/java/org/refactoringminer/test/TestAllRefactoringsByCommitForPurity.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,120 @@ | ||
package org.refactoringminer.test; | ||
|
||
import net.joshka.junit.json.params.JsonFileSource; | ||
|
||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.converter.ConvertWith; | ||
import org.refactoringminer.api.PurityCheckResult; | ||
import org.refactoringminer.api.PurityChecker; | ||
import org.refactoringminer.api.Refactoring; | ||
import org.refactoringminer.api.RefactoringHandler; | ||
import org.refactoringminer.rm1.GitHistoryRefactoringMinerImpl; | ||
import org.refactoringminer.utils.RefactoringPurityJsonConverter; | ||
|
||
import com.fasterxml.jackson.core.JsonParseException; | ||
import com.fasterxml.jackson.databind.JsonMappingException; | ||
|
||
import gr.uom.java.xmi.diff.UMLModelDiff; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.io.BufferedReader; | ||
import java.io.File; | ||
import java.io.FileReader; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
|
||
/** | ||
* @author Victor Guerra Veloso victorgvbh@gmail.com | ||
*/ | ||
public class TestAllRefactoringsByCommitForPurity { | ||
private static final String REPOS = System.getProperty("user.dir") + "/src/test/resources/oracle/commits"; | ||
private static final String EXPECTED = System.getProperty("user.dir") + "/src/test/resources/oracle/expectedPurity.txt"; | ||
private static final Map<String, Integer> expectedTP = new HashMap<>(); | ||
private static final Map<String, Integer> expectedTN = new HashMap<>(); | ||
private static final Map<String, Integer> expectedFP = new HashMap<>(); | ||
private static final Map<String, Integer> expectedFN = new HashMap<>(); | ||
|
||
@BeforeAll | ||
public static void setUp() throws JsonParseException, JsonMappingException, IOException { | ||
try { | ||
BufferedReader reader = new BufferedReader(new FileReader(EXPECTED)); | ||
String line; | ||
while ((line = reader.readLine()) != null) { | ||
String[] tokens = line.split(", "); | ||
String commitId = tokens[0]; | ||
int tp = Integer.parseInt(tokens[1]); | ||
int tn = Integer.parseInt(tokens[2]); | ||
int fp = Integer.parseInt(tokens[3]); | ||
int fn = Integer.parseInt(tokens[4]); | ||
expectedTP.put(commitId, tp); | ||
expectedTN.put(commitId, tn); | ||
expectedFP.put(commitId, fp); | ||
expectedFN.put(commitId, fn); | ||
} | ||
reader.close(); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private RefactoringPopulator.Purity findPurity(RefactoringPopulator.Root testCase, String refDescription) { | ||
for(RefactoringPopulator.Refactoring refactoring : testCase.refactorings) { | ||
if(refactoring.description.equals(refDescription)) { | ||
return refactoring.purity; | ||
} | ||
} | ||
return null; | ||
} | ||
|
||
@ParameterizedTest | ||
@JsonFileSource(resources = "/oracle/sampleResPurity.json") | ||
public void testAllRefactoringsParameterized(@ConvertWith(RefactoringPurityJsonConverter.class) RefactoringPopulator.Root testCase) throws Exception { | ||
GitHistoryRefactoringMinerImpl detector = new GitHistoryRefactoringMinerImpl(); | ||
detector.detectAtCommitWithGitHubAPI(testCase.repository, testCase.sha1, new File(REPOS), new RefactoringHandler() { | ||
|
||
@Override | ||
public boolean skipCommit(String commitId) { | ||
return commitId != testCase.sha1; | ||
} | ||
|
||
@Override | ||
public void handleModelDiff(String commitId, List<Refactoring> refactorings, UMLModelDiff modelDiff) { | ||
int actualTP = 0, actualTN = 0, actualFP = 0, actualFN = 0; | ||
for (Refactoring found : refactorings) { | ||
PurityCheckResult actual = PurityChecker.check(found, refactorings, modelDiff); | ||
String description = found.toString(); | ||
if(actual != null) { | ||
RefactoringPopulator.Purity p = findPurity(testCase, description); | ||
if(p != null) { | ||
if(p.purityValue.equals("1") && actual.isPure()) { | ||
actualTP++; | ||
} | ||
else if(p.purityValue.equals("0") && !actual.isPure()) { | ||
actualTN++; | ||
} | ||
else if(p.purityValue.equals("0") && actual.isPure()) { | ||
actualFP++; | ||
} | ||
else if(p.purityValue.equals("1") && !actual.isPure()) { | ||
actualFN++; | ||
} | ||
} | ||
} | ||
} | ||
final int finalActualTP = actualTP; | ||
final int finalActualTN = actualTN; | ||
final int finalActualFP = actualFP; | ||
final int finalActualFN = actualFN; | ||
Assertions.assertAll( | ||
() -> Assertions.assertEquals(expectedTP.get(commitId), finalActualTP, String.format("Should have %s True Positives, but has %s", expectedTP.get(commitId), finalActualTP)), | ||
() -> Assertions.assertEquals(expectedTN.get(commitId), finalActualTN, String.format("Should have %s True Negatives, but has %s", expectedTN.get(commitId), finalActualTN)), | ||
() -> Assertions.assertEquals(expectedFP.get(commitId), finalActualFP, String.format("Should have %s False Positives, but has %s", expectedFP.get(commitId), finalActualFP)), | ||
() -> Assertions.assertEquals(expectedFN.get(commitId), finalActualFN, String.format("Should have %s False Negatives, but has %s", expectedFN.get(commitId), finalActualFN)) | ||
); | ||
} | ||
}); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/test/java/org/refactoringminer/utils/RefactoringPurityJsonConverter.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,57 @@ | ||
package org.refactoringminer.utils; | ||
|
||
import org.junit.jupiter.api.extension.ParameterContext; | ||
import org.junit.jupiter.params.converter.ArgumentConversionException; | ||
import org.junit.jupiter.params.converter.ArgumentConverter; | ||
import org.refactoringminer.test.RefactoringPopulator; | ||
|
||
import javax.json.JsonObject; | ||
import javax.json.JsonValue; | ||
|
||
public class RefactoringPurityJsonConverter implements ArgumentConverter { | ||
private static RefactoringPopulator.Root fromJsonObject(JsonObject json) { | ||
RefactoringPopulator.Root root = new RefactoringPopulator.Root(); | ||
root.repository = json.getString("repository"); | ||
root.sha1 = json.getString("sha1"); | ||
root.url = json.getString("url"); | ||
root.refactorings = json.getJsonArray("refactorings").getValuesAs((JsonValue value) -> { | ||
JsonObject jsonRefactoring = (JsonObject) value; | ||
RefactoringPopulator.Refactoring refactoring = new RefactoringPopulator.Refactoring(); | ||
refactoring.type = getString(jsonRefactoring, "type"); | ||
refactoring.description = getString(jsonRefactoring, "description"); | ||
RefactoringPopulator.Purity purity = new RefactoringPopulator.Purity(); | ||
JsonObject jsonPurity = jsonRefactoring.getJsonObject("purity"); | ||
purity.purityValue = getString(jsonPurity, "purityValue"); | ||
refactoring.purity = purity; | ||
return refactoring; | ||
}); | ||
return root; | ||
} | ||
|
||
private static String getString(JsonObject json, String name) { | ||
if (json.isNull(name)) { | ||
return null; | ||
} | ||
return json.getString(name); | ||
} | ||
|
||
@Override | ||
public Object convert(Object source, ParameterContext context) { | ||
if (!(source instanceof JsonObject)) { | ||
throw new ArgumentConversionException("Not a JsonObject"); | ||
} | ||
JsonObject json = (JsonObject) source; | ||
String name = context.getParameter().getName(); | ||
Class<?> type = context.getParameter().getType(); | ||
if (type == RefactoringPopulator.Root.class) { | ||
return fromJsonObject(json); | ||
} else if (type == String.class) { | ||
return json.getString(name); | ||
} else if (type == int.class) { | ||
return json.getInt(name); | ||
} else if (type == boolean.class) { | ||
return json.getBoolean(name); | ||
} | ||
throw new ArgumentConversionException("Can't convert to type: '" + type.getName() + "'"); | ||
} | ||
} |
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,139 @@ | ||
0a9301b27130049e6cf147b5110ca7ae5b9c4285, 1, 0, 0, 0 | ||
3af5c7a20e85b1669f17c39f2fc325a26bcf87b0, 1, 0, 0, 0 | ||
cfa5b07af4eb7d465491771535dcefd7269a2a63, 0, 1, 0, 0 | ||
f62c587568ce46dfdc291106a6ab75dc67481da2, 0, 1, 0, 0 | ||
212a7617dfc4044b504b57dee2eb96470952f4b5, 1, 0, 0, 0 | ||
84f67cd771ef9df6dcd5b9ca036acfd8e4cdb19e, 1, 0, 0, 0 | ||
6ed100314ac841102cd6e9ff5406261f04dc1a9a, 3, 0, 0, 0 | ||
57c8f4b94fea628c30cbc69e292dc489cb9790dc, 5, 0, 0, 0 | ||
364d79c94e6c1aa98bf771a0b7671001e4257838, 4, 0, 0, 0 | ||
80108d608d9f0e207f17aa65f87ad172a47c56af, 1, 0, 0, 0 | ||
40521694193241c03c8badbd745abf9be4b13464, 0, 0, 0, 1 | ||
ec5d139337c8db352cced6f80ac7605a596c4b08, 1, 1, 0, 0 | ||
71ad291e6863be57ba51d2dbf79bd8ec259e2f7f, 0, 1, 0, 0 | ||
8474675badad33103cfc7869536316ec9ca5ea29, 0, 3, 0, 0 | ||
a6994138b5a95edb857257b2d553a97465e32604, 1, 0, 0, 0 | ||
43eeb5f419ea6c18c93ba85779f680e7dab74aab, 9, 0, 0, 2 | ||
48cde78cda7948b79d109f128c34c11f8b9ff9bd, 0, 0, 0, 0 | ||
7fc7c0723a2c9dfdf2b6bb23814d6a42d18bb353, 0, 5, 0, 0 | ||
39697a6d5d500f9fced6ca0fa4ffdf0717ba8813, 5, 0, 0, 0 | ||
f85cb537d2abe6bc73ae5b037a3e517a9aa8bcf1, 8, 1, 2, 0 | ||
e96555c7c309a0bc54d5a6464ae89dd543ff47ee, 1, 1, 0, 0 | ||
75d7f08fd6c3dd9d11dfcf0f3171ea3feac99fce, 1, 0, 0, 0 | ||
cd8bd185dc9aa830822d151aefd526890c60dc19, 1, 0, 0, 0 | ||
949d89f4d7847be694f2f082da5ab5814327d1fa, 8, 0, 0, 3 | ||
1c8cea9db7327b02c948346ec02491cbef3cc564, 0, 1, 0, 0 | ||
a5f122a886c4f3058e4e44f154f3fe8e1c414c93, 1, 0, 0, 0 | ||
750d87dda6afc3ca5f3bc5c9f29044c531b51f93, 0, 1, 0, 0 | ||
01fc649167cfe59a64550568d58006fe108bbf90, 1, 0, 0, 0 | ||
8dd7a0380136a2ee0b1592e12ab4dc7010ebbcb2, 0, 1, 0, 1 | ||
6931b450479e0dfbb60c8836c12a91c8ac498038, 1, 0, 0, 0 | ||
4a8f404c0860edc7ef6032463a05dcddbdbd052a, 0, 0, 0, 0 | ||
f541ccfe8b3fdc8feeb5682c3724968854b63f47, 1, 3, 0, 0 | ||
9b2401aa1b4dc8ee57a21247cddcd16065e766ae, 0, 1, 0, 0 | ||
3542d1fc47b29dd90410e7fe34638a03c173a82b, 8, 0, 0, 0 | ||
6d261108e7471db380146f945bb228b5fc8c44cc, 0, 0, 0, 0 | ||
874742233695ee99c3d98ce511505382d047b8ac, 2, 0, 0, 0 | ||
dd99220da7866f94ecce40fe161970dbfd67a8bb, 1, 0, 0, 0 | ||
cb41ea57f4f368108562f4c42bb91f1a63987eba, 3, 5, 0, 0 | ||
eb96034c43c82d994441a794b16fb50c90821291, 0, 1, 0, 0 | ||
6c2c95d2d503609ad26c8865009a0fe519ae9e3c, 3, 1, 0, 2 | ||
50441e1856dc78d73835cd6f23b0d9f087cde968, 3, 0, 0, 0 | ||
74369e6ddd0c2a92bba4efded434f6962854c41c, 0, 0, 0, 0 | ||
ca296ad353bbd2728a7acfb2c300e333e5194866, 5, 0, 0, 0 | ||
e1ad18b5ddb9bd49ac4823e41b5d4ebb8c800caf, 0, 1, 0, 0 | ||
f78ca2784a75b64ce69eb5cc44048bb2be0b9ae7, 2, 4, 0, 1 | ||
9f3705210af24f6d877d0d7f0fce4ee92331cedc, 2, 2, 0, 0 | ||
fb90ea0e69a12e210737aef912b7e894afe52178, 0, 0, 0, 0 | ||
9ca545449adf45694a650e22cbfd70732e66f73c, 0, 0, 0, 1 | ||
5e3f0034618d73f7873da654fde245e9a5365967, 3, 0, 0, 1 | ||
af59738bd7b91771ad95bfc73af2eae1f851bddf, 1, 0, 0, 0 | ||
76ba9bd26316f0d8fbd213df8e2f32e1ca6957ab, 2, 0, 0, 0 | ||
f08c29336a28580402e836f4298c89299919903d, 31, 0, 0, 0 | ||
1ac921b3988a78fcf5131b6371cfdf1072cfd230, 0, 0, 0, 0 | ||
8ca3700173c198819de3bf6183b01d5f89925ae3, 2, 0, 0, 0 | ||
7b21429fc680a9f93434e647a663d39e87721b0c, 0, 0, 0, 0 | ||
d1753466e2acd2d93844031d488e8f5d13b835ea, 0, 0, 0, 3 | ||
fd32ef056ce82d55f0cdc80e124dffe3de23169e, 0, 0, 0, 0 | ||
55c3745502fd9d9e23e49f0bdafc577cacb1fc20, 0, 0, 0, 0 | ||
9806074a5f524a0e45a145aad729aba54851ecac, 0, 0, 0, 0 | ||
16d8daec92c844ccadf90d1efee27f3b9fe75f1f, 0, 0, 0, 0 | ||
f223e451005dd73c06f4512855cfd2ff681e29bb, 1, 0, 0, 0 | ||
8528278c042cb4eb92e3c434ab52beb24860f6c3, 0, 0, 0, 0 | ||
a9bf1d869d40f0ecc6e8b2dc18f0865e563542ad, 1, 0, 0, 0 | ||
84a1ffd45fd92fe1498300af78ccac54f8ab00b0, 5, 1, 0, 3 | ||
a42a18c4cb7775e8c6772d97426200bcd63e00a7, 0, 0, 0, 0 | ||
7b4eb4d7303664c92dc3ec7b910e5585262be961, 2, 4, 1, 0 | ||
2ef05eb448a7b4d53399833f951490d7ece71192, 2, 1, 0, 0 | ||
dbddc1f7f0a9b595c8f4ad02621b7883de0d67ca, 1, 0, 0, 0 | ||
69db8ba6f66a36ee6143f82d45d07af8b9d398fc, 0, 0, 0, 0 | ||
d6c7baf6f0388d525881d6818ed304752e3729e4, 0, 1, 0, 0 | ||
d699f77d36efee1ffa176ddc5047cc66134b5427, 1, 0, 0, 0 | ||
c1f96f785b032b880093f1fd0feedd5ed65b07d1, 0, 0, 0, 0 | ||
0a7f53da1736523b14eb25b4301a7a9924eb3244, 0, 2, 0, 0 | ||
cdd9049b6b3c87dafcc06c3c1c3218065485fc70, 0, 0, 0, 0 | ||
df5232f967d2b08ab2bf50dff030648a8575a305, 9, 5, 0, 0 | ||
ec495f487d164e1f94116a3ca297d01f1028ef74, 0, 1, 0, 1 | ||
a3854f54a8f851a0d2212ae047e2f43553fc69d4, 0, 1, 0, 0 | ||
cfe0376f991a60f7c555ec204d9680405ad4c2ea, 1, 0, 0, 0 | ||
a6a61c6ba94ea2eebde02b82dbcab8e3c99dffd5, 1, 0, 0, 0 | ||
abd9cc0e8d0075a8469dce975b083caecfa6b8cd, 0, 0, 0, 2 | ||
1bacdbd25856d36f9ae4624f5d6699b46ac408a5, 1, 1, 0, 0 | ||
d5de65121c180297791cca836dfa04c2c4acde13, 1, 0, 0, 0 | ||
0e09b34ecf217c71b073001fd733ed3e3c785f0d, 1, 0, 0, 0 | ||
fafbe0bb502232398d983617442bd682dc7225c1, 0, 1, 0, 0 | ||
ea7583935e9bfaeaa9edcf1ca27ce64b5c8e3eae, 0, 1, 0, 0 | ||
98f49b34e0527c1e8995048d7fa3031f1bfb9ec0, 0, 1, 0, 0 | ||
93d982dfc86734f35f64604faa547b133f23f409, 0, 14, 0, 0 | ||
b19189634d4d6ca908764880be796513e70aa114, 0, 0, 0, 0 | ||
c98535420e324e6f5471adec4d31bbec68c9e7ef, 0, 1, 0, 0 | ||
b5d0959c6bfe9b7a83805c07fd4e034bcab61eb9, 1, 0, 0, 0 | ||
b14f3849b6e821597515bf4cd1939f124b7cc752, 0, 0, 0, 1 | ||
bd9a7568aef1953e52b4bec4eb8a9de37f421624, 0, 2, 0, 0 | ||
01f45bc4f525a2f66fe143e6691ecfeb133c27e4, 1, 0, 0, 0 | ||
32db96b3278eae8d8f0f162571adaf3ae5886b8d, 0, 2, 0, 0 | ||
ba4ab81f48a2f14eb75216e902e2ee4d2cce41a1, 1, 0, 0, 0 | ||
eb96034c43c82d994441a794b16fb50c90821291, 0, 1, 0, 0 | ||
24eb9b8d0eb17c30ad2151af1d44b8c8104bf177, 1, 0, 0, 0 | ||
d6e7523463e672af40b3047c48fc84e7fb0c00cb, 0, 1, 0, 0 | ||
909cb48ff31be6476b71e9565826f6579446acce, 2, 0, 0, 0 | ||
13056d5b30614dcb6634dca7255130ff0db2d631, 0, 1, 0, 0 | ||
1d19f7cc53d01bd119c4a20d5419b205b1a604e3, 2, 1, 0, 0 | ||
30a71740df867eb77052568def99b7b7acad54cf, 3, 0, 0, 0 | ||
a03659eead56b82d4e3f34a7da75080ea3869afe, 0, 1, 0, 0 | ||
430fa65bf2ba5098fc02e563cfe84533268def2d, 1, 1, 0, 0 | ||
f4d2c97ad3a7fa41934251e6fd727639ed1bd300, 0, 1, 0, 0 | ||
69f3ca49a846f4de572f9eb73a4924ddff525dd3, 1, 1, 0, 0 | ||
c13a4ce36ec7cf57934dfc06eb3a086497e98db4, 4, 5, 2, 1 | ||
09efe7925f67bbbbd6fe9bf840aa0019d381394a, 0, 1, 0, 0 | ||
aec322a434ee075820dc5b33ff702b43711b6143, 0, 1, 0, 0 | ||
e37546de91200cb13661bf438152e422df6e8814, 0, 1, 0, 0 | ||
8db0faed33f145488aea23efbb30ab5a732a8572, 2, 0, 0, 0 | ||
82c5017541d5dd86619e9d5d2dce57b70b65296e, 0, 3, 0, 0 | ||
58827c96375ca1696f6f2b1a109a0a609b7cee16, 1, 0, 0, 0 | ||
64b8b4d6ddb240526ec1e9b41385e381ba53fec6, 1, 0, 0, 1 | ||
636a1adbae4849b4b86905f9429b3ada43c7642e, 0, 1, 0, 0 | ||
2ea7e3a0cf9eaba708e08af40e0e851f757d4e2d, 0, 0, 0, 0 | ||
c8d678d78a3e77cfe5e5bd9b9abd55753a19d2ab, 1, 0, 0, 0 | ||
ab53317c58a802bf41aa19ff8f115e099c7fe8d1, 0, 1, 0, 0 | ||
fe9225d1bfe30543061c2e6d21ce9fb2a27f170e, 1, 0, 1, 0 | ||
83d7af6d2f966c7baebaad5970db83bb6db02fb5, 1, 0, 0, 0 | ||
8e8c8ca7a270b46ddd9f0bb18fe96a2571fdb665, 1, 0, 0, 0 | ||
94f0acc51bffdad46b40450d098ce09643b3c000, 1, 0, 0, 0 | ||
39fa0237c79bd912de50cbd404a4af71bf5e2eb3, 0, 0, 0, 0 | ||
2ed2cdff17d476a4cefda7e3af6f6c412f485698, 1, 0, 0, 0 | ||
9b93299257fffb5cda262132d46a97c256adb375, 1, 0, 0, 0 | ||
4a66dec4cab77fcb68593b31dc8416d87ee85c21, 1, 5, 0, 2 | ||
e36b91dfbc01029b3d64032702d61cecec106c62, 1, 0, 0, 0 | ||
ee1d50118748b41df3d2559197b6d045ae8ea689, 0, 0, 0, 1 | ||
ed5e4e2de4be7bc290ebf7b9b62ce7949777a727, 2, 7, 0, 0 | ||
b3e50ef2620b6646e1b3fc7c6e0249d47f3da04c, 1, 0, 0, 0 | ||
62c8fe4f9eb9555d28eefb7b10360e48c76ccc90, 1, 0, 0, 0 | ||
594a75dd353c78e4b394eca9d157f722bec2b040, 2, 0, 0, 0 | ||
a1f50ecc1026661fe22f46bb4edf11afc1a69fa0, 5, 0, 0, 2 | ||
68a393c1732738d2bf931731588c72b47c7abc39, 17, 0, 0, 0 | ||
25d26f5fdfed1ab4c7bfa0b8de764572050d9940, 1, 0, 0, 1 | ||
d947a330babf5d8031795a41f56859f7e6af0890, 1, 3, 0, 0 | ||
286603e09839682a92fdea221701ede9e69f095d, 3, 1, 0, 0 | ||
210045f0d60c66e0ee88e4d0dac2bb653ecbe675, 3, 3, 0, 2 | ||
182da4a46db52a99a2f8951b0a25aeaa1a1a6c35, 0, 7, 0, 1 |
Oops, something went wrong.