-
Notifications
You must be signed in to change notification settings - Fork 332
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #137 from jplag/104-fix-cli
Fix CLI and add testing capabilities
- Loading branch information
Showing
8 changed files
with
143 additions
and
44 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,56 @@ | ||
package jplag.options; | ||
|
||
import jplag.java19.Language; | ||
|
||
import java.util.Arrays; | ||
|
||
/** | ||
* The available languages. | ||
*/ | ||
public enum LanguageOption { | ||
JAVA_1_1("jplag.javax.Language"), | ||
JAVA_1_2("jplag.java.Language"), | ||
JAVA_1_5("jplag.java15.Language"), | ||
JAVA_1_5_DM("jplag.java15.LanguageWithDelimitedMethods"), | ||
JAVA_1_7("jplag.java17.Language"), | ||
JAVA_1_9("jplag.java19.Language"), | ||
PYTHON_3("jplag.python3.Language"), | ||
C_CPP("jplag.cpp.Language"), | ||
C_SHARP("jplag.csharp.Language"), | ||
CHAR("jplag.chars.Language"), | ||
TEXT("jplag.text.Language"), | ||
SCHEME("jplag.scheme.Language"); | ||
JAVA_1_1("java1", "jplag.javax.Language"), | ||
JAVA_1_2("java2", "jplag.java.Language"), | ||
JAVA_1_5("java5", "jplag.java15.Language"), | ||
JAVA_1_5_DM("java5dm", "jplag.java15.LanguageWithDelimitedMethods"), | ||
JAVA_1_7("java7", "jplag.java17.Language"), | ||
JAVA_1_9("java9", "jplag.java19.Language"), | ||
PYTHON_3("python3", "jplag.python3.Language"), | ||
C_CPP("cpp", "jplag.cpp.Language"), | ||
C_SHARP("csharp", "jplag.csharp.Language"), | ||
CHAR("char", "jplag.chars.Language"), | ||
TEXT("text", "jplag.text.Language"), | ||
SCHEME("scheme", "jplag.scheme.Language"); | ||
|
||
private final String classPath; | ||
private final String displayName; | ||
|
||
LanguageOption(String classPath) { | ||
LanguageOption(String displayName, String classPath) { | ||
this.displayName = displayName; | ||
this.classPath = classPath; | ||
} | ||
|
||
public String getClassPath() { | ||
return this.classPath; | ||
} | ||
|
||
public static LanguageOption fromOption(String optionName) { | ||
switch(optionName) { | ||
case "java_1_1": return JAVA_1_1; | ||
case "java_1_2": return JAVA_1_2; | ||
case "java_1_5": return JAVA_1_5; | ||
case "java_1_5_dm": return JAVA_1_5_DM; | ||
case "java_1_7": return JAVA_1_7; | ||
case "java_1_9": return JAVA_1_9; | ||
case "python_3": return PYTHON_3; | ||
case "c_cpp": return C_CPP; | ||
case "c_sharp": return C_SHARP; | ||
case "char": return CHAR; | ||
case "text": return TEXT; | ||
case "scheme": return SCHEME; | ||
default: return JAVA_1_9; | ||
} | ||
public String getDisplayName() { | ||
return this.displayName; | ||
} | ||
|
||
public static LanguageOption fromDisplayName(String displayName) { | ||
return Arrays.stream(LanguageOption.values()) | ||
.filter(languageOption -> languageOption.displayName.equals(displayName)) | ||
.findFirst() | ||
.orElse(getDefault()); | ||
} | ||
|
||
public static String[] getAllDisplayNames() { | ||
return Arrays.stream(LanguageOption.values()) | ||
.map(languageOption -> languageOption.displayName) | ||
.toArray(String[]::new); | ||
} | ||
|
||
public static LanguageOption getDefault() { | ||
return LanguageOption.JAVA_1_9; | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package jplag; | ||
|
||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
public class NormalComparisonTests extends TestBase { | ||
|
||
@Test | ||
public void testSimpleDuplicate() throws ExitException { | ||
JPlagResult result = runJPlagWithDefaultOptions("SimpleDuplicate"); | ||
|
||
assertEquals(2, result.getNumberOfSubmissions()); | ||
assertEquals(1, result.getComparisons().size()); | ||
assertEquals(1, result.getComparisons().get(0).matches.size()); | ||
assertEquals(1, result.getSimilarityDistribution()[6]); | ||
} | ||
|
||
} |
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,17 @@ | ||
package jplag; | ||
|
||
import jplag.options.JPlagOptions; | ||
import jplag.options.LanguageOption; | ||
|
||
public abstract class TestBase { | ||
|
||
protected JPlagResult runJPlagWithDefaultOptions(String testSampleName) throws ExitException { | ||
JPlagOptions options = new JPlagOptions( | ||
String.format("src/test/resources/samples/%s", testSampleName), | ||
LanguageOption.JAVA_1_9); | ||
|
||
JPlag jplag = new JPlag(options); | ||
return jplag.run(); | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
jplag/src/test/resources/samples/SimpleDuplicate/A/SimpleDuplicate.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,11 @@ | ||
public class SimpleDuplicate { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello World!"); | ||
|
||
for(int i = 0; i < 10; i++) { | ||
System.out.println("Number is " + i); | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
jplag/src/test/resources/samples/SimpleDuplicate/B/SimpleDuplicate.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,12 @@ | ||
public class SimpleDuplicate { | ||
|
||
public static void main(String[] args) { | ||
System.out.println("Hello Plagiarism!"); | ||
|
||
int max = 10; | ||
for(int j = 0; j < max; j++) { | ||
System.out.println("Number is " + j); | ||
} | ||
} | ||
|
||
} |