Browse Source

Add a test case for the files affected by the matches of a comparison.

Timur Sağlam 5 years ago
parent
commit
1498aaa19c

+ 39 - 0
jplag/src/test/java/de/jplag/JPlagComparisonTest.java

@@ -0,0 +1,39 @@
+package de.jplag;
+
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.junit.Test;
+
+public class JPlagComparisonTest extends TestBase {
+
+    private static final String[] FILES = {"GSTiling.java", "Match.java", "Matches.java", "Structure.java", "Submission.java", "Table.java", "Token.java"};
+    private static final String[] FILES_2 = {"Match.java", "Matches.java", "Structure.java", "Submission.java", "Table.java", "Token.java"};
+    private static final String[] FILES_3 = {"Table.java", "Token.java"};
+
+    /**
+     * Tests whether the right set of files corresponding to a set of matches is produced by the {@link JPlagComparison}.
+     */
+    @Test
+    public void testFilesOfMatches() throws ExitException {
+        JPlagResult result = runJPlagWithDefaultOptions("PartialPlagiarism");
+        List<JPlagComparison> comparisons = result.getComparisons();
+        assertEquals(5, result.getNumberOfSubmissions());
+        assertEquals(10, comparisons.size());
+        for (int submission = 0; submission < 2; submission++) { // for both submissions in a comparison
+            assertArrayEquals(FILES, comparisons.get(0).files(submission));
+            for (int i = 1; i < 3; i++) {
+                assertArrayEquals(FILES_2, comparisons.get(i).files(submission));
+            }
+            for (int i = 3; i < 6; i++) {
+                assertArrayEquals(FILES_3, comparisons.get(i).files(submission));
+            }
+            for (int i = 6; i < 10; i++) {
+                assertArrayEquals(new String[] {}, comparisons.get(i).files(submission));
+            }
+        }
+
+    }
+}

+ 1 - 1
jplag/src/test/java/de/jplag/ParallelComparisonTest.java

@@ -10,7 +10,7 @@ import org.junit.Test;
 import de.jplag.strategy.ParallelComparisonStrategy;
 import de.jplag.strategy.ParallelComparisonStrategy;
 
 
 /**
 /**
- * Currently just a copy of {@link NormalComparisonTest} but for the {@link ParallelComparisonStrategy}.
+ * Currently just a copy of {@link NormalComparisonTest} but for the {@link ParallelComparisonStrategy}. // TODO TS: de-duplicate this
  * @author Timur Saglam
  * @author Timur Saglam
  */
  */
 public class ParallelComparisonTest extends TestBase {
 public class ParallelComparisonTest extends TestBase {

+ 3 - 24
jplag/src/test/java/de/jplag/cli/CommandLineInterfaceTest.java

@@ -2,20 +2,18 @@ package de.jplag.cli;
 
 
 import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
 import static de.jplag.CommandLineArgument.ROOT_DIRECTORY;
 import static java.util.stream.Collectors.toSet;
 import static java.util.stream.Collectors.toSet;
-import static org.junit.Assert.fail;
 
 
 import java.util.Arrays;
 import java.util.Arrays;
 
 
 import de.jplag.CLI;
 import de.jplag.CLI;
 import de.jplag.CommandLineArgument;
 import de.jplag.CommandLineArgument;
-import de.jplag.ExitException;
-import de.jplag.JPlag;
-import de.jplag.JPlagResult;
 import de.jplag.options.JPlagOptions;
 import de.jplag.options.JPlagOptions;
 import net.sourceforge.argparse4j.inf.Namespace;
 import net.sourceforge.argparse4j.inf.Namespace;
 
 
 /**
 /**
- * Test base for tests regarding the {@link CLI} and any {@link CommandLineArgument}.
+ * Test base for tests regarding the {@link CLI} and any {@link CommandLineArgument}. Solely tests if the arguments set
+ * via the command line interface are propagated correctly into options. JPlag is not executed for the different command
+ * line arguments, thus these tests do not test the functionality of the options during the comparison.
  * @author Timur Saglam
  * @author Timur Saglam
  */
  */
 public class CommandLineInterfaceTest {
 public class CommandLineInterfaceTest {
@@ -57,23 +55,4 @@ public class CommandLineInterfaceTest {
         options = cli.buildOptionsFromArguments(namespace);
         options = cli.buildOptionsFromArguments(namespace);
     }
     }
 
 
-    /**
-     * Runs JPlag via the command line interface. Sets {@link CommandLineInterfaceTest#cli},
-     * {@link CommandLineInterfaceTest#namespace}, and {@link CommandLineInterfaceTest#options}.
-     * @param arguments arguments are the command line interface arguments.
-     * @return the result of the JPlag run.
-     */
-    protected JPlagResult runViaCLI(String... arguments) {
-        buildOptionsFromCLI(arguments);
-        try {
-            JPlag program = new JPlag(options);
-            return program.run();
-        } catch (ExitException e) {
-            e.printStackTrace();
-            fail(e.getMessage());
-            e.printStackTrace();
-        }
-        throw new IllegalStateException("Should never be reached!");
-    }
-
 }
 }