From 95d2cd79d33295bfba08d58793cbcc546648beb8 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 13:46:23 +0200 Subject: [PATCH 01/28] refactor(core): remove check on duplicate names --- core/src/main/java/de/jplag/JPlag.java | 24 ------------------------ 1 file changed, 24 deletions(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 41f1c08c8e..16f0fa49c0 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -1,11 +1,8 @@ package de.jplag; import java.io.File; -import java.util.ArrayList; -import java.util.HashSet; import java.util.List; import java.util.ResourceBundle; -import java.util.Set; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -111,26 +108,5 @@ private static void checkForConfigurationConsistency(JPlagOptions options) throw if (options.normalize() && !options.language().supportsNormalization()) { logger.error(String.format("The language %s cannot be used with normalization.", options.language().getName())); } - - List duplicateNames = getDuplicateSubmissionFolderNames(options); - if (duplicateNames.size() > 0) { - throw new RootDirectoryException(String.format("Duplicate root directory names found: %s", String.join(", ", duplicateNames))); - } - } - - private static List getDuplicateSubmissionFolderNames(JPlagOptions options) { - List duplicateNames = new ArrayList<>(); - Set alreadyFoundNames = new HashSet<>(); - for (File file : options.submissionDirectories()) { - if (!alreadyFoundNames.add(file.getName())) { - duplicateNames.add(file.getName()); - } - } - for (File file : options.oldSubmissionDirectories()) { - if (!alreadyFoundNames.add(file.getName())) { - duplicateNames.add(file.getName()); - } - } - return duplicateNames; } } From e96cf70784ff69dc48967d7a75535a5b415abcf0 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 13:47:11 +0200 Subject: [PATCH 02/28] refactor(core): remove throws into method checkForConfigurationConsistency --- core/src/main/java/de/jplag/JPlag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 16f0fa49c0..63e4a5d0d7 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -104,7 +104,7 @@ private static void logSkippedSubmissions(SubmissionSet submissionSet, JPlagOpti } } - private static void checkForConfigurationConsistency(JPlagOptions options) throws RootDirectoryException { + private static void checkForConfigurationConsistency(JPlagOptions options) { if (options.normalize() && !options.language().supportsNormalization()) { logger.error(String.format("The language %s cannot be used with normalization.", options.language().getName())); } From e25e584e8b457eada442e0ab9f02768f9eea7e37 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 13:47:28 +0200 Subject: [PATCH 03/28] style(core): use String format --- core/src/main/java/de/jplag/JPlag.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 63e4a5d0d7..9b87f4cc59 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -106,7 +106,7 @@ private static void logSkippedSubmissions(SubmissionSet submissionSet, JPlagOpti private static void checkForConfigurationConsistency(JPlagOptions options) { if (options.normalize() && !options.language().supportsNormalization()) { - logger.error(String.format("The language %s cannot be used with normalization.", options.language().getName())); + logger.error("The language {} cannot be used with normalization.", options.language().getName()); } } } From 67923b9fb0b5242cf441d17bf74331ff603dfb83 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 13:47:42 +0200 Subject: [PATCH 04/28] refactor(core): remove unused imports --- core/src/main/java/de/jplag/JPlag.java | 1 - 1 file changed, 1 deletion(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 9b87f4cc59..9652382d33 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -9,7 +9,6 @@ import de.jplag.clustering.ClusteringFactory; import de.jplag.exceptions.ExitException; -import de.jplag.exceptions.RootDirectoryException; import de.jplag.exceptions.SubmissionException; import de.jplag.merging.MatchMerging; import de.jplag.options.JPlagOptions; From 5f508545e9ab6d864e4d5210e3398ccfab89349e Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 14:03:32 +0200 Subject: [PATCH 05/28] feat(core): add support for same name submissions to SubmissionSetBuilder --- .../java/de/jplag/SubmissionSetBuilder.java | 101 +++++++++++++++++- 1 file changed, 97 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/de/jplag/SubmissionSetBuilder.java b/core/src/main/java/de/jplag/SubmissionSetBuilder.java index c74252fba8..ab1af4408e 100644 --- a/core/src/main/java/de/jplag/SubmissionSetBuilder.java +++ b/core/src/main/java/de/jplag/SubmissionSetBuilder.java @@ -14,6 +14,8 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -80,10 +82,13 @@ public SubmissionSet buildSubmissionSet() throws ExitException { submissionFiles.addAll(listSubmissionFiles(submissionDirectory, false)); } + Set allRootDirectories = submissionFiles.stream().map(SubmissionFileData::root).collect(Collectors.toSet()); + Map rootDirectoryNamePrefixesMapper = getRootDirectoryNamesPrefixesMapper(allRootDirectories); + ProgressBar progressBar = ProgressBarLogger.createProgressBar(ProgressBarType.LOADING, submissionFiles.size()); Map foundSubmissions = new HashMap<>(); for (SubmissionFileData submissionFile : submissionFiles) { - processSubmissionFile(submissionFile, multipleRoots, foundSubmissions); + processSubmissionFile(submissionFile, multipleRoots, rootDirectoryNamePrefixesMapper, foundSubmissions); progressBar.step(); } progressBar.dispose(); @@ -103,6 +108,92 @@ public SubmissionSet buildSubmissionSet() throws ExitException { return new SubmissionSet(submissions, baseCodeSubmission.orElse(null), options); } + private static String[] getCanonicalPathComponents(File path) { + try { + return path.getCanonicalPath().split(File.separator.equals("\\") ? "\\\\" : File.separator); + } catch (Exception e) { + throw new RuntimeException("Error getting canonical path", e); + } + } + + public static File getCommonAncestor(File firstPath, File secondPath) { + String[] firstComponents = getCanonicalPathComponents(firstPath); + String[] secondComponents = getCanonicalPathComponents(secondPath); + + int minLength = Math.min(firstComponents.length, secondComponents.length); + int commonLength = 0; + + for (int i = 0; i < minLength; i++) { + if (firstComponents[i].equals(secondComponents[i])) { + commonLength++; + } else { + break; + } + } + + if (commonLength == 0) { + return null; + } + + StringBuilder commonPath = new StringBuilder(firstComponents[0]); + for (int i = 1; i < commonLength; i++) { + commonPath.append(File.separator).append(firstComponents[i]); + } + + return new File(commonPath.toString()); + } + + private String findCommonPathPrefix(List canonicalPaths) { + if (canonicalPaths == null) { + return ""; + } + + File prefix = canonicalPaths.getFirst(); + for (int i = 1; i < canonicalPaths.size(); i++) { + prefix = getCommonAncestor(prefix, canonicalPaths.get(i)); + } + + return prefix == null ? null : prefix.toString(); + } + + private String getPathPrefix(File path, String commonPrefix) { + String result = path.toString().substring(commonPrefix.length()); + return result.startsWith(File.separator) ? result.substring(1) : result; + } + + private Map getRootDirectoryNamesPrefixesMapper(Set allRootDirectories) { + Map> conflicts = getRootDirectoryNameConflicts(allRootDirectories); + + Map result = new HashMap<>(); + conflicts.forEach((name, paths) -> { + if (paths.size() > 1) { + String commonPrefix = findCommonPathPrefix(paths); + for (File path : paths) { + result.put(path, getPathPrefix(path, commonPrefix)); + } + } else { + result.put(paths.getFirst(), ""); + } + }); + + return result; + } + + private static Map> getRootDirectoryNameConflicts(Set allRootDirectories) { + Map> conflicts = new HashMap<>(); + + for (File rootDir : allRootDirectories) { + String roodDirName = rootDir.getName(); + if (conflicts.containsKey(roodDirName)) { + conflicts.get(roodDirName).add(rootDir); + } else { + conflicts.put(roodDirName, Stream.of(rootDir).collect(Collectors.toList())); + } + } + + return conflicts; + } + /** * Verify that the given root directories exist and have no duplicate entries. */ @@ -219,14 +310,16 @@ private Submission processSubmission(String submissionName, File submissionFile, return new Submission(submissionName, file, isNew, parseFilesRecursively(file), options.language()); } - private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map foundSubmissions) throws ExitException { + private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map rootDirectoryNamePrefixesMapper, Map foundSubmissions) throws ExitException { if (isFileExcluded(file.submissionFile())) { logger.error("Exclude submission: {}", file.submissionFile().getName()); } else if (file.submissionFile().isFile() && !hasValidSuffix(file.submissionFile())) { logger.error("Ignore submission with invalid suffix: {}", file.submissionFile().getName()); } else { - String rootDirectoryPrefix = multipleRoots ? (file.root().getName() + File.separator) : ""; - String submissionName = rootDirectoryPrefix + file.submissionFile().getName(); + String rootDirectoryPrefix = rootDirectoryNamePrefixesMapper.get(file.root()); + rootDirectoryPrefix = rootDirectoryPrefix.isEmpty() && multipleRoots ? file.root().getName() : rootDirectoryPrefix; + String submissionName = rootDirectoryPrefix.isEmpty() ? file.submissionFile().getName() + : rootDirectoryPrefix + File.separator + file.submissionFile().getName(); Submission submission = processSubmission(submissionName, file.submissionFile(), file.isNew()); foundSubmissions.put(submission.getRoot(), submission); } From 407b629841c2fd7723d979eb9d89814b75bb7c02 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 16:24:47 +0200 Subject: [PATCH 06/28] test(core): fix should not throw --- core/src/test/java/de/jplag/RootFolderTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index c5acd3cb1f..92e7d1b742 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -1,8 +1,5 @@ package de.jplag; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - import java.io.File; import java.util.List; @@ -10,7 +7,8 @@ import org.junit.jupiter.api.Test; import de.jplag.exceptions.ExitException; -import de.jplag.exceptions.RootDirectoryException; + +import static org.junit.jupiter.api.Assertions.*; /** * Test class for the multi-root feature and the old-new feature. @@ -71,7 +69,7 @@ void testDisjunctNewAndOldRootDirectories() throws ExitException { void testOverlappingNewAndOldDirectoriesOverlap() throws ExitException { List newDirectories = List.of(getBasePath(ROOT_2)); List oldDirectories = List.of(getBasePath(ROOT_2)); - assertThrows(RootDirectoryException.class, () -> runJPlag(newDirectories, oldDirectories, it -> it)); + assertDoesNotThrow(() -> runJPlag(newDirectories, oldDirectories, it -> it)); } @Test From 5eb1c7424dfb3a5231445948e60d53054a28d4e4 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 16:57:38 +0200 Subject: [PATCH 07/28] style: apply spotless --- core/src/main/java/de/jplag/SubmissionSetBuilder.java | 3 ++- core/src/test/java/de/jplag/RootFolderTest.java | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/de/jplag/SubmissionSetBuilder.java b/core/src/main/java/de/jplag/SubmissionSetBuilder.java index ab1af4408e..56cab68859 100644 --- a/core/src/main/java/de/jplag/SubmissionSetBuilder.java +++ b/core/src/main/java/de/jplag/SubmissionSetBuilder.java @@ -310,7 +310,8 @@ private Submission processSubmission(String submissionName, File submissionFile, return new Submission(submissionName, file, isNew, parseFilesRecursively(file), options.language()); } - private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map rootDirectoryNamePrefixesMapper, Map foundSubmissions) throws ExitException { + private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map rootDirectoryNamePrefixesMapper, + Map foundSubmissions) throws ExitException { if (isFileExcluded(file.submissionFile())) { logger.error("Exclude submission: {}", file.submissionFile().getName()); } else if (file.submissionFile().isFile() && !hasValidSuffix(file.submissionFile())) { diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 92e7d1b742..bc3c7d742f 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -1,5 +1,7 @@ package de.jplag; +import static org.junit.jupiter.api.Assertions.*; + import java.io.File; import java.util.List; @@ -8,8 +10,6 @@ import de.jplag.exceptions.ExitException; -import static org.junit.jupiter.api.Assertions.*; - /** * Test class for the multi-root feature and the old-new feature. */ From 6071f1b8cef6eef8768c041796f7b4d496e266c0 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 17:14:47 +0200 Subject: [PATCH 08/28] test(core): add test about different submissions with same root name --- .../reportobject/ReportObjectFactoryTest.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java index 36a7f610dd..d359155158 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java @@ -6,6 +6,8 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; +import java.util.List; +import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -37,6 +39,27 @@ void testCreateAndSaveReportWithBasecode() throws ExitException, IOException { assertTrue(isArchive(testZip)); } + @Test + void testWithSamenameSubmissions() throws ExitException, IOException { + File submission1 = new File(BASE_PATH, "basecode/A"); + File submission2 = new File(BASE_PATH, "basecode/B"); + File submission3 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); + File submission4 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); + List submissions = Stream.of(submission1, submission2, submission3, submission4).map(File::toString).toList(); + JPlagResult result = runJPlag(submissions, it -> it.withBaseCodeSubmissionDirectory(new File(BASE_PATH, BASECODE_BASE))); + File testZip = File.createTempFile("result", ".zip"); + ReportObjectFactory reportObjectFactory = new ReportObjectFactory(testZip); + reportObjectFactory.createAndSaveReport(result); + + assertNotNull(result); + assertTrue(isArchive(testZip)); + + String[] expectedSubmissionNames = new String[] { "B/TerrainType.java", "basecode/A/TerrainType.java" }; + for (String expected : expectedSubmissionNames) { + assertTrue(result.getSubmissions().getSubmissions().stream().anyMatch(submission -> submission.getName().equals(expected))); + } + } + /** * Checks if the given file is a valid archive * @param file The file to check From 018293f88ac7b86dbbf7cb1d1edf050725fa39f3 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 18:25:20 +0200 Subject: [PATCH 09/28] test(core): add test about different submissions with same root name --- .../test/java/de/jplag/RootFolderTest.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index bc3c7d742f..68b170439b 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -3,6 +3,7 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.File; +import java.util.Arrays; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -82,4 +83,22 @@ void testBasecodeInOldDirectory() throws ExitException { int numberOfExpectedComparison = 1 + ROOT_COUNT_2 * (ROOT_COUNT_1 - 1); // -1 for basecode assertEquals(numberOfExpectedComparison, result.getAllComparisons().size()); } + + @Test + @DisplayName("test multiple submissions with same folder name") + void testSubmissionsWithSameFolderName() throws ExitException { + String[] roots = new String[]{"A", "B", "base"}; + List submissions = Arrays.stream(roots) + .map(it -> getBasePath("basecode" + File.separator + it)) + .toList(); + JPlagResult result = runJPlag(submissions, it -> it); + List submissionNames = result.getSubmissions().getSubmissions().stream().map(Submission::getName).sorted().toList(); + String conflictingFile = "TerrainType.java"; + + for (int i = 0; i < roots.length; i++) { + String expectedName = roots[i] + File.separator + conflictingFile; + String effectiveName = submissionNames.get(i); + assertEquals(expectedName, effectiveName); + } + } } From c87778f65aa341a4f85166eb572a88aa659a1025 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 18:32:56 +0200 Subject: [PATCH 10/28] test(core): add test about single new submission with an old submission --- core/src/test/java/de/jplag/RootFolderTest.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 68b170439b..d2fa9b4f63 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -101,4 +101,17 @@ void testSubmissionsWithSameFolderName() throws ExitException { assertEquals(expectedName, effectiveName); } } + + @Test + @DisplayName("test single new submission") + void testSingleNewSubmission() throws ExitException { + List newSubmissions = List.of(getBasePath("basecode" + File.separator + "A")); + List oldSubmissions = List.of(getBasePath("basecode" + File.separator + "B")); + JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); + long numberOfNewSubmissions = result.getSubmissions().getSubmissions().stream().filter(Submission::isNew).count(); + long numberOfOldSubmissions = result.getSubmissions().getSubmissions().stream().filter(it -> !it.isNew()).count(); + assertEquals(1, numberOfNewSubmissions); + assertEquals(1, numberOfOldSubmissions); + } + } From a6761b45b5223589c6b62935762ac7ff8be29252 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 18:33:24 +0200 Subject: [PATCH 11/28] test(core): add test about single new submission with an old submission --- core/src/test/java/de/jplag/RootFolderTest.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index d2fa9b4f63..896f6f4464 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -87,10 +87,8 @@ void testBasecodeInOldDirectory() throws ExitException { @Test @DisplayName("test multiple submissions with same folder name") void testSubmissionsWithSameFolderName() throws ExitException { - String[] roots = new String[]{"A", "B", "base"}; - List submissions = Arrays.stream(roots) - .map(it -> getBasePath("basecode" + File.separator + it)) - .toList(); + String[] roots = new String[] {"A", "B", "base"}; + List submissions = Arrays.stream(roots).map(it -> getBasePath("basecode" + File.separator + it)).toList(); JPlagResult result = runJPlag(submissions, it -> it); List submissionNames = result.getSubmissions().getSubmissions().stream().map(Submission::getName).sorted().toList(); String conflictingFile = "TerrainType.java"; @@ -104,7 +102,7 @@ void testSubmissionsWithSameFolderName() throws ExitException { @Test @DisplayName("test single new submission") - void testSingleNewSubmission() throws ExitException { + void testSingleNewSubmission() throws ExitException { List newSubmissions = List.of(getBasePath("basecode" + File.separator + "A")); List oldSubmissions = List.of(getBasePath("basecode" + File.separator + "B")); JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); From 99643012b50b6afb1ee907fe268794c46e5b354f Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 26 Aug 2024 18:33:39 +0200 Subject: [PATCH 12/28] style: execute spotless --- .../reportobject/ReportObjectFactoryTest.java | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java index d359155158..64ff032a6f 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java @@ -39,26 +39,26 @@ void testCreateAndSaveReportWithBasecode() throws ExitException, IOException { assertTrue(isArchive(testZip)); } - @Test - void testWithSamenameSubmissions() throws ExitException, IOException { + @Test + void testWithSamenameSubmissions() throws ExitException, IOException { File submission1 = new File(BASE_PATH, "basecode/A"); File submission2 = new File(BASE_PATH, "basecode/B"); File submission3 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); File submission4 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); - List submissions = Stream.of(submission1, submission2, submission3, submission4).map(File::toString).toList(); - JPlagResult result = runJPlag(submissions, it -> it.withBaseCodeSubmissionDirectory(new File(BASE_PATH, BASECODE_BASE))); - File testZip = File.createTempFile("result", ".zip"); - ReportObjectFactory reportObjectFactory = new ReportObjectFactory(testZip); - reportObjectFactory.createAndSaveReport(result); + List submissions = Stream.of(submission1, submission2, submission3, submission4).map(File::toString).toList(); + JPlagResult result = runJPlag(submissions, it -> it.withBaseCodeSubmissionDirectory(new File(BASE_PATH, BASECODE_BASE))); + File testZip = File.createTempFile("result", ".zip"); + ReportObjectFactory reportObjectFactory = new ReportObjectFactory(testZip); + reportObjectFactory.createAndSaveReport(result); - assertNotNull(result); - assertTrue(isArchive(testZip)); + assertNotNull(result); + assertTrue(isArchive(testZip)); - String[] expectedSubmissionNames = new String[] { "B/TerrainType.java", "basecode/A/TerrainType.java" }; - for (String expected : expectedSubmissionNames) { - assertTrue(result.getSubmissions().getSubmissions().stream().anyMatch(submission -> submission.getName().equals(expected))); - } - } + String[] expectedSubmissionNames = new String[] {"B/TerrainType.java", "basecode/A/TerrainType.java"}; + for (String expected : expectedSubmissionNames) { + assertTrue(result.getSubmissions().getSubmissions().stream().anyMatch(submission -> submission.getName().equals(expected))); + } + } /** * Checks if the given file is a valid archive From 92a729d69ba4c2dd2fb5198ca77baa1c9709b803 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Tue, 27 Aug 2024 16:22:56 +0200 Subject: [PATCH 13/28] test(e2e): add test about single new submission --- .github/workflows/complete-e2e.yml | 1 + .github/workflows/files/singleNewSubmission.zip | Bin 0 -> 2771 bytes .../tests/e2e/OpenComparisonTest.spec.ts | 5 +++++ 3 files changed, 6 insertions(+) create mode 100644 .github/workflows/files/singleNewSubmission.zip diff --git a/.github/workflows/complete-e2e.yml b/.github/workflows/complete-e2e.yml index 332cc834e1..e90c686159 100644 --- a/.github/workflows/complete-e2e.yml +++ b/.github/workflows/complete-e2e.yml @@ -70,6 +70,7 @@ jobs: {zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}, + {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "--old 2022 2021 2020"}, {zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""}, {zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""}, {zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""} diff --git a/.github/workflows/files/singleNewSubmission.zip b/.github/workflows/files/singleNewSubmission.zip new file mode 100644 index 0000000000000000000000000000000000000000..e736486091880446a2d2c1f6a0e48a8684ef798e GIT binary patch literal 2771 zcmaKuc{J2}AIHbOCHop`k~QmS$i8MtmKwx_o9@NPWpFdr$C^C$5kuEjStd(7vXwDo zNw#ZiLSoRkD3{EYU8HA*Ce9(hbAI3R{r&NIpZEEFUZ2I3vvdH!?qN+1=OqU)?}i5}yi*FM0RYnI0RSFq z_*Dqp?+!&s;kFCH<%bvwe@F}k(T2ZN;v7%i;84>@$OdIZyqYM=ztKiyOv8YED@9A| z7T?cT^V|oJV%sA6*C)n90=Nj5J=p&Ddq2!8rjV_Cqywjf&=8AT?vT_Gvt6y`RiC~u zM8{#C2{x0G2~9E~S}tR1py_P`tcZ3AosaY4+Zwh{y)>4y~IgSEK zxH;|wxSUKu-#!J(ic|`e_bH%=9YH}7#Nv-AC0?xNRCpk+MNepTuA@9wOmnT>#}te* zNi78GiLN%OosO`6?a?lj_K6gdZP6_5ZeU<=nVXk;;O6-*lBas^6)Eh7sV`GQ`m{RM zi_c5>M$e>HZiFxxgQBfA6l@8oV76>HXMjv2AXl5Me0mg~4kP(ISThrf7-V`+g5GXb z=NWP6y8=PxjuVf{5bxv?Kk~VO5>=7&48{C4rIATfh;&Adz|@Xpv>;!O%ZK$|tyYl= zQWXImuUtgb8ex6VBvP-XPHL`_moY^=`paZI<#S#_7L!aFZ--B-!?a;y?2GXSCb%7o zcxW}KM}HnI*KxmV_;;&t8)eJ8Msaf0n_HNYg_U7^bZ8zAm7K3VRS8ov{w8zb5_lT&~-+$yH3*fmNCz5yFuk*RIzn#lSUZR=5Mqj>{9&B zrExeQco{p%=Fu3V6c;6`DN9(%RY&94%AWn(+^GeZTZ~`);D(Q#_C*(z5>R*A{AU?) z0>NEAaL*)$LJERM8~qb z#alghI~ygvs!nR@{e}QqM1s>_F1QW2rB@cnt?Z0Fp5-)BjT(7n%Q3z+Q{S>}_}qPl z=YdoOiI+c(2K;ElIwa=`Q6i0AL1dlIcOAxZCQWa1NP$(0-*SGKRwmL^qIuLL>2$o^ zWK6d}ozz350g5G#TivtYWsp4poG*KxX;5axbXt7ghKHOp)-g7t!6pPl;xBMv4hYoj@X2qMy+ zWzXbyE{Vy_gtk2kR~vm^B_B|o^U#JcokaN4>ZWM0)II(V8n$^)yV|;6X=mQKz1KE1=9 z%QsZAUUSZ(QQsOvd4;oJ1AZ+Vo7w~`Z_K(doAeykYtr9P=$A`n?i*pDfX~87-WLt4 ztW+-6<~L`D{n5Up7%rE=5kM@FJI8{osF?J_yCz`Hg@hqDVaBN`DD1CB0_|$B7coyx zCUB_dWpDslKVqyZSJ+DpKbIoL6I~uIa|g%YFbr*kGMio;TzMKzN8)%}M;lYiE@ST_ z{7EJpNLb?GhWWLpic3s!UxxZlsSiP~+X~+bnAcD@4g#1r;1?4VZ?AcbeH+Oy^ACAe z`*&fLtV))-B&*FAsSIVLs4LOz#Ty?v+J(yhMm5(3Ve4!D;%Cr~f7Y!wSF)z_)M*_J z)8{0NtmUW`gbNz@!%tL94JyhTOIbK$ms_ZM(R?fs3U~B zNE|2pvtf47BO~puN6Kg;OHroLF&+;Owu2roQKhIJsblUq;XRLs`{qH9x@7#x|B=!~ z$x@WYcZ|owJ@lZ*Fsc;QBekO*C%otJa6KRNXwJCnky71cDN1!8 Date: Tue, 27 Aug 2024 17:12:28 +0200 Subject: [PATCH 14/28] test(e2e): add test about matching names on submissions --- .github/workflows/complete-e2e.yml | 1 + .../workflows/files/submissionsWithSameName.zip | Bin 0 -> 6356 bytes .../tests/e2e/OpenComparisonTest.spec.ts | 5 +++++ 3 files changed, 6 insertions(+) create mode 100644 .github/workflows/files/submissionsWithSameName.zip diff --git a/.github/workflows/complete-e2e.yml b/.github/workflows/complete-e2e.yml index e90c686159..377661f56d 100644 --- a/.github/workflows/complete-e2e.yml +++ b/.github/workflows/complete-e2e.yml @@ -71,6 +71,7 @@ jobs: {zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}, {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "--old 2022 2021 2020"}, + {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "--old old/2022 old/2021 old/2020"}, {zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""}, {zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""}, {zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""} diff --git a/.github/workflows/files/submissionsWithSameName.zip b/.github/workflows/files/submissionsWithSameName.zip new file mode 100644 index 0000000000000000000000000000000000000000..56274385ab10936613a201c277cce1bea7b79a31 GIT binary patch literal 6356 zcmeI0dpK148pmhG3?cU!w^W?du~o#-Fxw^Kkl0fuDzr^^_}Av`R$@^o87P8k>+64LoriOf^VfPN02sJn z^`vd1_(p0iWp3>~Hjyl{&O2l7^3SDwYHU;axYr7va zv($BaM?e{+A~uyL=dP5>D?&2P+eM_7zb=tFFJwEm~8SxmMN6Zsxm;k|d)+NwstGnv}Ln*JjDvT((iMc;@DDd&!Pv}xL%u*x|(uE3x=P=7!K)@BO~>ha$StgZP? z;J;YlMwq}@;PvzM+RxV36?k#Ic)z^t_$Y+k4cY^|8;B5&Jv4yZK@9AbK)vV(X3kK_o6cRPU9wP)KA#vt3lM?N|df2 z)ku~;V~6ny>zw|@owTPi%sF&Ycy(u0l3H@vxROP`U$;zAX~!>Z&T5Pef_E+{l((E! zXu5I{7dWI?m?hWXkrE_ix@wCU_pYv0J%~)q;i-4RYt+I5&QDd~Wb4>!P<{>lfa<7KS(QV$TdOmI&A}K@XIsu}F+M*+!XWsVFd$-nh>fB@Lv|hoAWzVvbiFDW803#cq&8xC7zwo1Sl(D!t}-_U@E)&^@D+M`;X1MqHTnF*3BTZ#zUkuIJ?hRQ?Z0B6=nNJr6HjM;GB=70bG;|km zy+k0s#%_AvF%j^y!^wQ=?B5>~&IOY&F-zx~+vc^?lTL1bwJpVmN)46X`ku);mH%+X zd_}dyeb!AhH)O8!cLOJ6%mF8W##+=3Acl_{5FrBs!36_;bHiWjh7y1%$#36>m!kIH85F zH5fb=!mKkKHnY{RFi^F(J#S>lB`Oqo!65RO%bYj!^%^N*fb+U}Kw!iX5 z4Wfi@$||Q9VY=DxKI=4MQ|NYtTHp0!hS?E{Vx`HLmT-JSaGpv2E@_qfP2NpMo{KA$ ziE3)vbR8DYh|R-&uklIy@oa3wKP5K0YFJq>_5F2wji=nbw<6XGcRdTKDAVxK3z0Y4D)pBwgw*fV8+{8=e@e@{9-_o?km#+%0J z+vW|C^yP#`KZg0JS2n49=u4ud9cWXZ0&V-= zTxAH&$WyL*WwaZAFe(&kd3Aw-={C?ad?%t$7d4dJJXTf15O>NMIPLu%V^qB_(=J+p zlIw7={lbnM)4;jmX`}s(Sh8Z9x>8XzQ-w5D`%aX0>y%n-!3?!WyDOH zT}GvX?JXy6AQkiX4=0ewfYhKBVRCc*17i622N6gh5L__eH~;*<_y>(yA+XqKjyz|0 zmqd+i1TQ&fJ2>{)4oq?zYc2|TvI9jK|AAt6O#lu&=i!N4?39O%12PVk8*u`PgT@;G z=5gKwtrK}b0j*OR!`ZT%Klu9a!~HvTxn&QcP%k*e0CMqcHo0;kXBa4M z42oNji^uQ*-9B=jfo^}jFr-2d3EMt6-SCkM*=0lPoduo|=e!6UojC6(kM7ZAKC(ZAZa)={ zgl!+}7Wv49>_MRQ#z{c7zaSTn<^ftSvLAug`v{JN)yor(171lKiU9mh0#^^Dz`y Date: Tue, 27 Aug 2024 17:23:51 +0200 Subject: [PATCH 15/28] test(core): refactor tests on new features --- .../test/java/de/jplag/RootFolderTest.java | 39 +++++++++------- .../SingleNewSubmission/2020/QSort2020.java | 40 +++++++++++++++++ .../SingleNewSubmission/2021/QSort2021.java | 44 +++++++++++++++++++ .../SingleNewSubmission/2022/QSort2022.java | 41 +++++++++++++++++ .../SingleNewSubmission/2023/QSort2023.java | 37 ++++++++++++++++ .../2023/gr1/QSort.java | 37 ++++++++++++++++ .../2023/gr2/QSort.java | 37 ++++++++++++++++ .../old/2020/gr1/QSort.java | 40 +++++++++++++++++ .../old/2020/gr2/QSort.java | 40 +++++++++++++++++ .../old/2021/gr1/QSort.java | 44 +++++++++++++++++++ .../old/2021/gr2/QSort.java | 44 +++++++++++++++++++ .../old/2022/gr1/QSort.java | 41 +++++++++++++++++ .../old/2022/gr2/QSort.java | 41 +++++++++++++++++ 13 files changed, 510 insertions(+), 15 deletions(-) create mode 100644 core/src/test/resources/de/jplag/samples/SingleNewSubmission/2020/QSort2020.java create mode 100644 core/src/test/resources/de/jplag/samples/SingleNewSubmission/2021/QSort2021.java create mode 100644 core/src/test/resources/de/jplag/samples/SingleNewSubmission/2022/QSort2022.java create mode 100644 core/src/test/resources/de/jplag/samples/SingleNewSubmission/2023/QSort2023.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java create mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 896f6f4464..6c1e059dfb 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -5,6 +5,8 @@ import java.io.File; import java.util.Arrays; import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -87,29 +89,36 @@ void testBasecodeInOldDirectory() throws ExitException { @Test @DisplayName("test multiple submissions with same folder name") void testSubmissionsWithSameFolderName() throws ExitException { - String[] roots = new String[] {"A", "B", "base"}; - List submissions = Arrays.stream(roots).map(it -> getBasePath("basecode" + File.separator + it)).toList(); - JPlagResult result = runJPlag(submissions, it -> it); - List submissionNames = result.getSubmissions().getSubmissions().stream().map(Submission::getName).sorted().toList(); - String conflictingFile = "TerrainType.java"; - - for (int i = 0; i < roots.length; i++) { - String expectedName = roots[i] + File.separator + conflictingFile; - String effectiveName = submissionNames.get(i); - assertEquals(expectedName, effectiveName); - } + List newSubmissionsNames = List.of("2023"); + List oldSubmissionsNames = List.of("2022", "2021", "2020"); + List newSubmissions = newSubmissionsNames.stream().map(it -> getBasePath("SubmissionsWithSameName" + File.separator + it)).toList(); + List oldSubmissions = oldSubmissionsNames.stream().map(it -> getBasePath("SubmissionsWithSameName" + File.separator + "old" + File.separator + it)).toList(); + + JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); + + long numberOfNewSubmissions = result.getSubmissions().getSubmissions().stream().filter(Submission::isNew).count(); + long numberOfOldSubmissions = result.getSubmissions().getSubmissions().stream().filter(it -> !it.isNew()).count(); + assertEquals(2, numberOfNewSubmissions); + assertEquals(6, numberOfOldSubmissions); + + Set submissionNames = result.getSubmissions().getSubmissions().stream().map(Submission::getName).collect(Collectors.toSet()); + Set expectedNames = Set.of("2023/gr1", "2023/gr2", "2022/gr1", "2022/gr2", "2021/gr1", "2021/gr2", "2020/gr1", "2020/gr2"); + assertEquals(expectedNames, submissionNames); } @Test @DisplayName("test single new submission") void testSingleNewSubmission() throws ExitException { - List newSubmissions = List.of(getBasePath("basecode" + File.separator + "A")); - List oldSubmissions = List.of(getBasePath("basecode" + File.separator + "B")); + List newSubmissionsNames = List.of("2023"); + List oldSubmissionsNames = List.of("2022", "2021", "2020"); + List newSubmissions = newSubmissionsNames.stream().map(it -> getBasePath("SingleNewSubmission" + File.separator + it)).toList(); + List oldSubmissions = oldSubmissionsNames.stream().map(it -> getBasePath("SingleNewSubmission" + File.separator + it)).toList(); + JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); + long numberOfNewSubmissions = result.getSubmissions().getSubmissions().stream().filter(Submission::isNew).count(); long numberOfOldSubmissions = result.getSubmissions().getSubmissions().stream().filter(it -> !it.isNew()).count(); assertEquals(1, numberOfNewSubmissions); - assertEquals(1, numberOfOldSubmissions); + assertEquals(3, numberOfOldSubmissions); } - } diff --git a/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2020/QSort2020.java b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2020/QSort2020.java new file mode 100644 index 0000000000..1fdfb3562f --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2020/QSort2020.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class QSort2020 { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + List sortedList = quickSort(List.of(array)); + return sortedList.toArray(new String[0]); + } + + private List quickSort(List list) { + if (list.size() <= 1) { + return list; + } + + String pivot = list.get(list.size() / 2); + List less = new ArrayList<>(); + List equal = new ArrayList<>(); + List greater = new ArrayList<>(); + + for (String s : list) { + int comparison = s.compareTo(pivot); + if (comparison < 0) { + less.add(s); + } else if (comparison > 0) { + greater.add(s); + } else { + equal.add(s); + } + } + + List sorted = new ArrayList<>(); + sorted.addAll(quickSort(less)); + sorted.addAll(equal); + sorted.addAll(quickSort(greater)); + return sorted; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2021/QSort2021.java b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2021/QSort2021.java new file mode 100644 index 0000000000..7fc96abd1b --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2021/QSort2021.java @@ -0,0 +1,44 @@ +import java.util.Stack; + +public class QSort2021 { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + + Stack stack = new Stack<>(); + stack.push(new int[] { 0, array.length - 1 }); + + while (!stack.isEmpty()) { + int[] range = stack.pop(); + int low = range[0], high = range[1]; + + if (low < high) { + int pivotIndex = partition(array, low, high); + stack.push(new int[] { low, pivotIndex - 1 }); + stack.push(new int[] { pivotIndex + 1, high }); + } + } + + return array; + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2022/QSort2022.java b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2022/QSort2022.java new file mode 100644 index 0000000000..7b7dd9102b --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2022/QSort2022.java @@ -0,0 +1,41 @@ +public class QSort2022 { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + while (low < high) { + int pivotIndex = partition(array, low, high); + if (pivotIndex - low < high - pivotIndex) { + quickSort(array, low, pivotIndex - 1); + low = pivotIndex + 1; + } else { + quickSort(array, pivotIndex + 1, high); + high = pivotIndex - 1; + } + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2023/QSort2023.java b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2023/QSort2023.java new file mode 100644 index 0000000000..dfe08fddbb --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SingleNewSubmission/2023/QSort2023.java @@ -0,0 +1,37 @@ +public class QSort2023 { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + if (low < high) { + int pivotIndex = partition(array, low, high); + quickSort(array, low, pivotIndex - 1); + quickSort(array, pivotIndex + 1, high); + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + +} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java new file mode 100644 index 0000000000..091f8a67af --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java @@ -0,0 +1,37 @@ +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + if (low < high) { + int pivotIndex = partition(array, low, high); + quickSort(array, low, pivotIndex - 1); + quickSort(array, pivotIndex + 1, high); + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + +} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java new file mode 100644 index 0000000000..091f8a67af --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java @@ -0,0 +1,37 @@ +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + if (low < high) { + int pivotIndex = partition(array, low, high); + quickSort(array, low, pivotIndex - 1); + quickSort(array, pivotIndex + 1, high); + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } + +} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java new file mode 100644 index 0000000000..e8e36f67da --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + List sortedList = quickSort(List.of(array)); + return sortedList.toArray(new String[0]); + } + + private List quickSort(List list) { + if (list.size() <= 1) { + return list; + } + + String pivot = list.get(list.size() / 2); + List less = new ArrayList<>(); + List equal = new ArrayList<>(); + List greater = new ArrayList<>(); + + for (String s : list) { + int comparison = s.compareTo(pivot); + if (comparison < 0) { + less.add(s); + } else if (comparison > 0) { + greater.add(s); + } else { + equal.add(s); + } + } + + List sorted = new ArrayList<>(); + sorted.addAll(quickSort(less)); + sorted.addAll(equal); + sorted.addAll(quickSort(greater)); + return sorted; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java new file mode 100644 index 0000000000..e8e36f67da --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java @@ -0,0 +1,40 @@ +import java.util.ArrayList; +import java.util.List; + +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + List sortedList = quickSort(List.of(array)); + return sortedList.toArray(new String[0]); + } + + private List quickSort(List list) { + if (list.size() <= 1) { + return list; + } + + String pivot = list.get(list.size() / 2); + List less = new ArrayList<>(); + List equal = new ArrayList<>(); + List greater = new ArrayList<>(); + + for (String s : list) { + int comparison = s.compareTo(pivot); + if (comparison < 0) { + less.add(s); + } else if (comparison > 0) { + greater.add(s); + } else { + equal.add(s); + } + } + + List sorted = new ArrayList<>(); + sorted.addAll(quickSort(less)); + sorted.addAll(equal); + sorted.addAll(quickSort(greater)); + return sorted; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java new file mode 100644 index 0000000000..d548b6fb04 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java @@ -0,0 +1,44 @@ +import java.util.Stack; + +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + + Stack stack = new Stack<>(); + stack.push(new int[] { 0, array.length - 1 }); + + while (!stack.isEmpty()) { + int[] range = stack.pop(); + int low = range[0], high = range[1]; + + if (low < high) { + int pivotIndex = partition(array, low, high); + stack.push(new int[] { low, pivotIndex - 1 }); + stack.push(new int[] { pivotIndex + 1, high }); + } + } + + return array; + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java new file mode 100644 index 0000000000..d548b6fb04 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java @@ -0,0 +1,44 @@ +import java.util.Stack; + +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + + Stack stack = new Stack<>(); + stack.push(new int[] { 0, array.length - 1 }); + + while (!stack.isEmpty()) { + int[] range = stack.pop(); + int low = range[0], high = range[1]; + + if (low < high) { + int pivotIndex = partition(array, low, high); + stack.push(new int[] { low, pivotIndex - 1 }); + stack.push(new int[] { pivotIndex + 1, high }); + } + } + + return array; + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java new file mode 100644 index 0000000000..4730b95303 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java @@ -0,0 +1,41 @@ +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + while (low < high) { + int pivotIndex = partition(array, low, high); + if (pivotIndex - low < high - pivotIndex) { + quickSort(array, low, pivotIndex - 1); + low = pivotIndex + 1; + } else { + quickSort(array, pivotIndex + 1, high); + high = pivotIndex - 1; + } + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java new file mode 100644 index 0000000000..4730b95303 --- /dev/null +++ b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java @@ -0,0 +1,41 @@ +public class QSort { + public String[] qsort(String[] array) { + if (array == null || array.length == 0) { + return array; + } + quickSort(array, 0, array.length - 1); + return array; + } + + private void quickSort(String[] array, int low, int high) { + while (low < high) { + int pivotIndex = partition(array, low, high); + if (pivotIndex - low < high - pivotIndex) { + quickSort(array, low, pivotIndex - 1); + low = pivotIndex + 1; + } else { + quickSort(array, pivotIndex + 1, high); + high = pivotIndex - 1; + } + } + } + + private int partition(String[] array, int low, int high) { + String pivot = array[high]; + int i = low - 1; + for (int j = low; j < high; j++) { + if (array[j].compareTo(pivot) <= 0) { + i++; + swap(array, i, j); + } + } + swap(array, i + 1, high); + return i + 1; + } + + private void swap(String[] array, int i, int j) { + String temp = array[i]; + array[i] = array[j]; + array[j] = temp; + } +} From c300fc1dfcc559b812f3ed33f6236b7a50f00d7d Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Tue, 27 Aug 2024 17:25:28 +0200 Subject: [PATCH 16/28] style: apply spotless --- core/src/test/java/de/jplag/RootFolderTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 6c1e059dfb..945d2f5b87 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -3,7 +3,6 @@ import static org.junit.jupiter.api.Assertions.*; import java.io.File; -import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.stream.Collectors; @@ -92,7 +91,8 @@ void testSubmissionsWithSameFolderName() throws ExitException { List newSubmissionsNames = List.of("2023"); List oldSubmissionsNames = List.of("2022", "2021", "2020"); List newSubmissions = newSubmissionsNames.stream().map(it -> getBasePath("SubmissionsWithSameName" + File.separator + it)).toList(); - List oldSubmissions = oldSubmissionsNames.stream().map(it -> getBasePath("SubmissionsWithSameName" + File.separator + "old" + File.separator + it)).toList(); + List oldSubmissions = oldSubmissionsNames.stream() + .map(it -> getBasePath("SubmissionsWithSameName" + File.separator + "old" + File.separator + it)).toList(); JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); From 37bfdc6d1c24688519e057055e04921569228dc0 Mon Sep 17 00:00:00 2001 From: Eugenio Berretta Date: Wed, 28 Aug 2024 19:05:22 +0200 Subject: [PATCH 17/28] fix(report-viewer): fix regex for e2e tests --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 0c2d279a6b..131f7c6a25 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -8,6 +8,8 @@ interface DataSet { secondSubmissionName: string } +const regexpPathSeparator = '(\\\\|\\/)'; + const testSets: DataSet[] = [ { datasetName: 'fileSingleRoot-report.zip', @@ -41,13 +43,13 @@ const testSets: DataSet[] = [ }, { datasetName: 'singleNewSubmission-report.zip', - firstSubmissionName: '2023\\\\|/QSort2023.java', - secondSubmissionName: '2022\\\\|/QSort2022.java' + firstSubmissionName: `2023${regexpPathSeparator}QSort2023.java`, + secondSubmissionName: `2022${regexpPathSeparator}QSort2022.java`, }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: '2023\\\\|/gr1', - secondSubmissionName: '2023\\\\|/gr2' + firstSubmissionName: `2020${regexpPathSeparator}gr1`, + secondSubmissionName: `2020${regexpPathSeparator}gr2` }, { datasetName: 'python-report.zip', From 68065f66b828fc6c952f69e831ca29c72b27c5a9 Mon Sep 17 00:00:00 2001 From: Eugenio Berretta Date: Fri, 30 Aug 2024 16:54:22 +0200 Subject: [PATCH 18/28] test(report-viewer): fix e2e test --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 131f7c6a25..5bc3e29b1c 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -48,8 +48,8 @@ const testSets: DataSet[] = [ }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `2020${regexpPathSeparator}gr1`, - secondSubmissionName: `2020${regexpPathSeparator}gr2` + firstSubmissionName: `20\d\d${regexpPathSeparator}gr\d`, + secondSubmissionName: `20\d\d${regexpPathSeparator}gr\d` }, { datasetName: 'python-report.zip', From 26a58f740ffe084576c55a125794ad0fd304774a Mon Sep 17 00:00:00 2001 From: Eugenio Berretta Date: Mon, 2 Sep 2024 13:47:08 +0200 Subject: [PATCH 19/28] fix(viewer): fix missing backslash in regexp for e2e tests --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 5bc3e29b1c..16d2cb1a41 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -48,8 +48,8 @@ const testSets: DataSet[] = [ }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `20\d\d${regexpPathSeparator}gr\d`, - secondSubmissionName: `20\d\d${regexpPathSeparator}gr\d` + firstSubmissionName: `20\\d\\d${regexpPathSeparator}gr\\d`, + secondSubmissionName: `20\\d\\d${regexpPathSeparator}gr\\d` }, { datasetName: 'python-report.zip', From 331557f866a61c5bd5ac1b78c9fb1850374c41ba Mon Sep 17 00:00:00 2001 From: Eugenio Berretta Date: Mon, 2 Sep 2024 14:04:10 +0200 Subject: [PATCH 20/28] test(viewer): try to fix e2e test --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 16d2cb1a41..131f7c6a25 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -48,8 +48,8 @@ const testSets: DataSet[] = [ }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `20\\d\\d${regexpPathSeparator}gr\\d`, - secondSubmissionName: `20\\d\\d${regexpPathSeparator}gr\\d` + firstSubmissionName: `2020${regexpPathSeparator}gr1`, + secondSubmissionName: `2020${regexpPathSeparator}gr2` }, { datasetName: 'python-report.zip', From 85ce7a20875cb79d58c5c49f396d382fb7939451 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 2 Sep 2024 23:02:56 +0200 Subject: [PATCH 21/28] ci(complete-e2e): remove additional hyphen to --old --- .github/workflows/complete-e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/complete-e2e.yml b/.github/workflows/complete-e2e.yml index 377661f56d..1805370bc9 100644 --- a/.github/workflows/complete-e2e.yml +++ b/.github/workflows/complete-e2e.yml @@ -70,8 +70,8 @@ jobs: {zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}, - {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "--old 2022 2021 2020"}, - {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "--old old/2022 old/2021 old/2020"}, + {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "-old 2022 2021 2020"}, + {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "-old old/2022 old/2021 old/2020"}, {zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""}, {zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""}, {zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""} From 4fcf51f7ed86b0771773e8e9667fca0d642e78a2 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Mon, 2 Sep 2024 23:04:29 +0200 Subject: [PATCH 22/28] test(viewer): fix e2e regexp --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 131f7c6a25..a5e8bf39e3 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -48,8 +48,8 @@ const testSets: DataSet[] = [ }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `2020${regexpPathSeparator}gr1`, - secondSubmissionName: `2020${regexpPathSeparator}gr2` + firstSubmissionName: `2023${regexpPathSeparator}gr1`, + secondSubmissionName: `2023${regexpPathSeparator}gr2` }, { datasetName: 'python-report.zip', From 39110d083dae70b051073332a7ef6033f1c250c1 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Tue, 3 Sep 2024 18:29:33 +0200 Subject: [PATCH 23/28] ci(complete-e2e): fix old argument by using comma and not spaces --- .github/workflows/complete-e2e.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/complete-e2e.yml b/.github/workflows/complete-e2e.yml index 1805370bc9..2c3f9741b7 100644 --- a/.github/workflows/complete-e2e.yml +++ b/.github/workflows/complete-e2e.yml @@ -70,8 +70,8 @@ jobs: {zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}, - {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "-old 2022 2021 2020"}, - {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "-old old/2022 old/2021 old/2020"}, + {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "-old 2022,2021,2020"}, + {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "-old old/2022,old/2021,old/2020"}, {zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""}, {zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""}, {zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""} From dc09aba642f87e0e5103408894ad4fdcc1eeadd4 Mon Sep 17 00:00:00 2001 From: Eugenio Berretta Date: Wed, 4 Sep 2024 16:14:15 +0200 Subject: [PATCH 24/28] refactor(e2e): rename var --- report-viewer/tests/e2e/OpenComparisonTest.spec.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index a5e8bf39e3..6577953f1e 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -8,7 +8,7 @@ interface DataSet { secondSubmissionName: string } -const regexpPathSeparator = '(\\\\|\\/)'; +const regexPathSeparator = '(\\\\|\\/)'; const testSets: DataSet[] = [ { @@ -43,13 +43,13 @@ const testSets: DataSet[] = [ }, { datasetName: 'singleNewSubmission-report.zip', - firstSubmissionName: `2023${regexpPathSeparator}QSort2023.java`, - secondSubmissionName: `2022${regexpPathSeparator}QSort2022.java`, + firstSubmissionName: `2023${regexPathSeparator}QSort2023.java`, + secondSubmissionName: `2022${regexPathSeparator}QSort2022.java`, }, { datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `2023${regexpPathSeparator}gr1`, - secondSubmissionName: `2023${regexpPathSeparator}gr2` + firstSubmissionName: `2023${regexPathSeparator}gr1`, + secondSubmissionName: `2023${regexPathSeparator}gr2` }, { datasetName: 'python-report.zip', From 4e19222236395eafaa676ef2a2382231bd520e24 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Fri, 6 Sep 2024 16:51:38 +0200 Subject: [PATCH 25/28] ci(e2e): remove submissions with same name part --- .github/workflows/complete-e2e.yml | 3 +-- .../workflows/files/submissionsWithSameName.zip | Bin 6356 -> 0 bytes 2 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 .github/workflows/files/submissionsWithSameName.zip diff --git a/.github/workflows/complete-e2e.yml b/.github/workflows/complete-e2e.yml index 2c3f9741b7..8616f35638 100644 --- a/.github/workflows/complete-e2e.yml +++ b/.github/workflows/complete-e2e.yml @@ -70,8 +70,7 @@ jobs: {zip: "folderMultiRoot.zip", name: "folderMultiRoot", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFile", folder: "f0", language: "java", cliArgs: "--new f1"}, {zip: "mixedMultiRoot.zip", name: "mixedBaseFolder", folder: "f1", language: "java", cliArgs: "--new f0"}, - {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "-old 2022,2021,2020"}, - {zip: "submissionsWithSameName.zip", name: "submissionsWithSameName", folder: "2023", language: "java", cliArgs: "-old old/2022,old/2021,old/2020"}, + {zip: "singleNewSubmission.zip", name: "singleNewSubmission", folder: "2023", language: "java", cliArgs: "--old 2022,2021,2020"}, {zip: "cpp.zip", name: "cpp", folder: "./cpp", language: "cpp", cliArgs: ""}, {zip: "csharp.zip", name: "csharp", folder: "./csharp", language: "csharp", cliArgs: ""}, {zip: "python.zip", name: "python", folder: "./python", language: "python3", cliArgs: ""} diff --git a/.github/workflows/files/submissionsWithSameName.zip b/.github/workflows/files/submissionsWithSameName.zip deleted file mode 100644 index 56274385ab10936613a201c277cce1bea7b79a31..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 6356 zcmeI0dpK148pmhG3?cU!w^W?du~o#-Fxw^Kkl0fuDzr^^_}Av`R$@^o87P8k>+64LoriOf^VfPN02sJn z^`vd1_(p0iWp3>~Hjyl{&O2l7^3SDwYHU;axYr7va zv($BaM?e{+A~uyL=dP5>D?&2P+eM_7zb=tFFJwEm~8SxmMN6Zsxm;k|d)+NwstGnv}Ln*JjDvT((iMc;@DDd&!Pv}xL%u*x|(uE3x=P=7!K)@BO~>ha$StgZP? z;J;YlMwq}@;PvzM+RxV36?k#Ic)z^t_$Y+k4cY^|8;B5&Jv4yZK@9AbK)vV(X3kK_o6cRPU9wP)KA#vt3lM?N|df2 z)ku~;V~6ny>zw|@owTPi%sF&Ycy(u0l3H@vxROP`U$;zAX~!>Z&T5Pef_E+{l((E! zXu5I{7dWI?m?hWXkrE_ix@wCU_pYv0J%~)q;i-4RYt+I5&QDd~Wb4>!P<{>lfa<7KS(QV$TdOmI&A}K@XIsu}F+M*+!XWsVFd$-nh>fB@Lv|hoAWzVvbiFDW803#cq&8xC7zwo1Sl(D!t}-_U@E)&^@D+M`;X1MqHTnF*3BTZ#zUkuIJ?hRQ?Z0B6=nNJr6HjM;GB=70bG;|km zy+k0s#%_AvF%j^y!^wQ=?B5>~&IOY&F-zx~+vc^?lTL1bwJpVmN)46X`ku);mH%+X zd_}dyeb!AhH)O8!cLOJ6%mF8W##+=3Acl_{5FrBs!36_;bHiWjh7y1%$#36>m!kIH85F zH5fb=!mKkKHnY{RFi^F(J#S>lB`Oqo!65RO%bYj!^%^N*fb+U}Kw!iX5 z4Wfi@$||Q9VY=DxKI=4MQ|NYtTHp0!hS?E{Vx`HLmT-JSaGpv2E@_qfP2NpMo{KA$ ziE3)vbR8DYh|R-&uklIy@oa3wKP5K0YFJq>_5F2wji=nbw<6XGcRdTKDAVxK3z0Y4D)pBwgw*fV8+{8=e@e@{9-_o?km#+%0J z+vW|C^yP#`KZg0JS2n49=u4ud9cWXZ0&V-= zTxAH&$WyL*WwaZAFe(&kd3Aw-={C?ad?%t$7d4dJJXTf15O>NMIPLu%V^qB_(=J+p zlIw7={lbnM)4;jmX`}s(Sh8Z9x>8XzQ-w5D`%aX0>y%n-!3?!WyDOH zT}GvX?JXy6AQkiX4=0ewfYhKBVRCc*17i622N6gh5L__eH~;*<_y>(yA+XqKjyz|0 zmqd+i1TQ&fJ2>{)4oq?zYc2|TvI9jK|AAt6O#lu&=i!N4?39O%12PVk8*u`PgT@;G z=5gKwtrK}b0j*OR!`ZT%Klu9a!~HvTxn&QcP%k*e0CMqcHo0;kXBa4M z42oNji^uQ*-9B=jfo^}jFr-2d3EMt6-SCkM*=0lPoduo|=e!6UojC6(kM7ZAKC(ZAZa)={ zgl!+}7Wv49>_MRQ#z{c7zaSTn<^ftSvLAug`v{JN)yor(171lKiU9mh0#^^Dz`y Date: Fri, 6 Sep 2024 17:15:08 +0200 Subject: [PATCH 26/28] refactor: rollback feature of multiple submissions same name --- core/src/main/java/de/jplag/JPlag.java | 27 ++++- .../java/de/jplag/SubmissionSetBuilder.java | 103 +----------------- .../test/java/de/jplag/RootFolderTest.java | 26 +---- .../reportobject/ReportObjectFactoryTest.java | 23 ---- .../2023/gr1/QSort.java | 37 ------- .../2023/gr2/QSort.java | 37 ------- .../old/2020/gr1/QSort.java | 40 ------- .../old/2020/gr2/QSort.java | 40 ------- .../old/2021/gr1/QSort.java | 44 -------- .../old/2021/gr2/QSort.java | 44 -------- .../old/2022/gr1/QSort.java | 41 ------- .../old/2022/gr2/QSort.java | 41 ------- .../tests/e2e/OpenComparisonTest.spec.ts | 5 - 13 files changed, 31 insertions(+), 477 deletions(-) delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java delete mode 100644 core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 9652382d33..38e8d27397 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -1,9 +1,9 @@ package de.jplag; import java.io.File; -import java.util.List; -import java.util.ResourceBundle; +import java.util.*; +import de.jplag.exceptions.RootDirectoryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -103,9 +103,30 @@ private static void logSkippedSubmissions(SubmissionSet submissionSet, JPlagOpti } } - private static void checkForConfigurationConsistency(JPlagOptions options) { + private static void checkForConfigurationConsistency(JPlagOptions options) throws RootDirectoryException { if (options.normalize() && !options.language().supportsNormalization()) { logger.error("The language {} cannot be used with normalization.", options.language().getName()); } + + List duplicateNames = getDuplicateSubmissionFolderNames(options); + if (!duplicateNames.isEmpty()) { + throw new RootDirectoryException(String.format("Duplicate root directory names found: %s", String.join(", ", duplicateNames))); + } + } + + private static List getDuplicateSubmissionFolderNames(JPlagOptions options) { + List duplicateNames = new ArrayList<>(); + Set alreadyFoundNames = new HashSet<>(); + for (File file : options.submissionDirectories()) { + if (!alreadyFoundNames.add(file.getName())) { + duplicateNames.add(file.getName()); + } + } + for (File file : options.oldSubmissionDirectories()) { + if (!alreadyFoundNames.add(file.getName())) { + duplicateNames.add(file.getName()); + } + } + return duplicateNames; } } diff --git a/core/src/main/java/de/jplag/SubmissionSetBuilder.java b/core/src/main/java/de/jplag/SubmissionSetBuilder.java index 56cab68859..1ae09b11f0 100644 --- a/core/src/main/java/de/jplag/SubmissionSetBuilder.java +++ b/core/src/main/java/de/jplag/SubmissionSetBuilder.java @@ -14,8 +14,6 @@ import java.util.Optional; import java.util.Set; import java.util.function.Function; -import java.util.stream.Collectors; -import java.util.stream.Stream; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -82,13 +80,10 @@ public SubmissionSet buildSubmissionSet() throws ExitException { submissionFiles.addAll(listSubmissionFiles(submissionDirectory, false)); } - Set allRootDirectories = submissionFiles.stream().map(SubmissionFileData::root).collect(Collectors.toSet()); - Map rootDirectoryNamePrefixesMapper = getRootDirectoryNamesPrefixesMapper(allRootDirectories); - ProgressBar progressBar = ProgressBarLogger.createProgressBar(ProgressBarType.LOADING, submissionFiles.size()); Map foundSubmissions = new HashMap<>(); for (SubmissionFileData submissionFile : submissionFiles) { - processSubmissionFile(submissionFile, multipleRoots, rootDirectoryNamePrefixesMapper, foundSubmissions); + processSubmissionFile(submissionFile, multipleRoots, foundSubmissions); progressBar.step(); } progressBar.dispose(); @@ -108,92 +103,6 @@ public SubmissionSet buildSubmissionSet() throws ExitException { return new SubmissionSet(submissions, baseCodeSubmission.orElse(null), options); } - private static String[] getCanonicalPathComponents(File path) { - try { - return path.getCanonicalPath().split(File.separator.equals("\\") ? "\\\\" : File.separator); - } catch (Exception e) { - throw new RuntimeException("Error getting canonical path", e); - } - } - - public static File getCommonAncestor(File firstPath, File secondPath) { - String[] firstComponents = getCanonicalPathComponents(firstPath); - String[] secondComponents = getCanonicalPathComponents(secondPath); - - int minLength = Math.min(firstComponents.length, secondComponents.length); - int commonLength = 0; - - for (int i = 0; i < minLength; i++) { - if (firstComponents[i].equals(secondComponents[i])) { - commonLength++; - } else { - break; - } - } - - if (commonLength == 0) { - return null; - } - - StringBuilder commonPath = new StringBuilder(firstComponents[0]); - for (int i = 1; i < commonLength; i++) { - commonPath.append(File.separator).append(firstComponents[i]); - } - - return new File(commonPath.toString()); - } - - private String findCommonPathPrefix(List canonicalPaths) { - if (canonicalPaths == null) { - return ""; - } - - File prefix = canonicalPaths.getFirst(); - for (int i = 1; i < canonicalPaths.size(); i++) { - prefix = getCommonAncestor(prefix, canonicalPaths.get(i)); - } - - return prefix == null ? null : prefix.toString(); - } - - private String getPathPrefix(File path, String commonPrefix) { - String result = path.toString().substring(commonPrefix.length()); - return result.startsWith(File.separator) ? result.substring(1) : result; - } - - private Map getRootDirectoryNamesPrefixesMapper(Set allRootDirectories) { - Map> conflicts = getRootDirectoryNameConflicts(allRootDirectories); - - Map result = new HashMap<>(); - conflicts.forEach((name, paths) -> { - if (paths.size() > 1) { - String commonPrefix = findCommonPathPrefix(paths); - for (File path : paths) { - result.put(path, getPathPrefix(path, commonPrefix)); - } - } else { - result.put(paths.getFirst(), ""); - } - }); - - return result; - } - - private static Map> getRootDirectoryNameConflicts(Set allRootDirectories) { - Map> conflicts = new HashMap<>(); - - for (File rootDir : allRootDirectories) { - String roodDirName = rootDir.getName(); - if (conflicts.containsKey(roodDirName)) { - conflicts.get(roodDirName).add(rootDir); - } else { - conflicts.put(roodDirName, Stream.of(rootDir).collect(Collectors.toList())); - } - } - - return conflicts; - } - /** * Verify that the given root directories exist and have no duplicate entries. */ @@ -310,17 +219,15 @@ private Submission processSubmission(String submissionName, File submissionFile, return new Submission(submissionName, file, isNew, parseFilesRecursively(file), options.language()); } - private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map rootDirectoryNamePrefixesMapper, - Map foundSubmissions) throws ExitException { + private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, + Map foundSubmissions) throws ExitException { if (isFileExcluded(file.submissionFile())) { logger.error("Exclude submission: {}", file.submissionFile().getName()); } else if (file.submissionFile().isFile() && !hasValidSuffix(file.submissionFile())) { logger.error("Ignore submission with invalid suffix: {}", file.submissionFile().getName()); } else { - String rootDirectoryPrefix = rootDirectoryNamePrefixesMapper.get(file.root()); - rootDirectoryPrefix = rootDirectoryPrefix.isEmpty() && multipleRoots ? file.root().getName() : rootDirectoryPrefix; - String submissionName = rootDirectoryPrefix.isEmpty() ? file.submissionFile().getName() - : rootDirectoryPrefix + File.separator + file.submissionFile().getName(); + String rootDirectoryPrefix = multipleRoots ? (file.root().getName() + File.separator) : ""; + String submissionName = rootDirectoryPrefix + file.submissionFile().getName(); Submission submission = processSubmission(submissionName, file.submissionFile(), file.isNew()); foundSubmissions.put(submission.getRoot(), submission); } diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 945d2f5b87..112bccfb2b 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -4,9 +4,8 @@ import java.io.File; import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; +import de.jplag.exceptions.RootDirectoryException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -71,7 +70,7 @@ void testDisjunctNewAndOldRootDirectories() throws ExitException { void testOverlappingNewAndOldDirectoriesOverlap() throws ExitException { List newDirectories = List.of(getBasePath(ROOT_2)); List oldDirectories = List.of(getBasePath(ROOT_2)); - assertDoesNotThrow(() -> runJPlag(newDirectories, oldDirectories, it -> it)); + assertThrows(RootDirectoryException.class, () -> runJPlag(newDirectories, oldDirectories, it -> it)); } @Test @@ -85,27 +84,6 @@ void testBasecodeInOldDirectory() throws ExitException { assertEquals(numberOfExpectedComparison, result.getAllComparisons().size()); } - @Test - @DisplayName("test multiple submissions with same folder name") - void testSubmissionsWithSameFolderName() throws ExitException { - List newSubmissionsNames = List.of("2023"); - List oldSubmissionsNames = List.of("2022", "2021", "2020"); - List newSubmissions = newSubmissionsNames.stream().map(it -> getBasePath("SubmissionsWithSameName" + File.separator + it)).toList(); - List oldSubmissions = oldSubmissionsNames.stream() - .map(it -> getBasePath("SubmissionsWithSameName" + File.separator + "old" + File.separator + it)).toList(); - - JPlagResult result = runJPlag(newSubmissions, oldSubmissions, it -> it); - - long numberOfNewSubmissions = result.getSubmissions().getSubmissions().stream().filter(Submission::isNew).count(); - long numberOfOldSubmissions = result.getSubmissions().getSubmissions().stream().filter(it -> !it.isNew()).count(); - assertEquals(2, numberOfNewSubmissions); - assertEquals(6, numberOfOldSubmissions); - - Set submissionNames = result.getSubmissions().getSubmissions().stream().map(Submission::getName).collect(Collectors.toSet()); - Set expectedNames = Set.of("2023/gr1", "2023/gr2", "2022/gr1", "2022/gr2", "2021/gr1", "2021/gr2", "2020/gr1", "2020/gr2"); - assertEquals(expectedNames, submissionNames); - } - @Test @DisplayName("test single new submission") void testSingleNewSubmission() throws ExitException { diff --git a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java index 64ff032a6f..36a7f610dd 100644 --- a/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java +++ b/core/src/test/java/de/jplag/reporting/reportobject/ReportObjectFactoryTest.java @@ -6,8 +6,6 @@ import java.io.File; import java.io.IOException; import java.io.RandomAccessFile; -import java.util.List; -import java.util.stream.Stream; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -39,27 +37,6 @@ void testCreateAndSaveReportWithBasecode() throws ExitException, IOException { assertTrue(isArchive(testZip)); } - @Test - void testWithSamenameSubmissions() throws ExitException, IOException { - File submission1 = new File(BASE_PATH, "basecode/A"); - File submission2 = new File(BASE_PATH, "basecode/B"); - File submission3 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); - File submission4 = new File(BASE_PATH, "basecode-sameNameOfSubdirectoryAndRootdirectory/A"); - List submissions = Stream.of(submission1, submission2, submission3, submission4).map(File::toString).toList(); - JPlagResult result = runJPlag(submissions, it -> it.withBaseCodeSubmissionDirectory(new File(BASE_PATH, BASECODE_BASE))); - File testZip = File.createTempFile("result", ".zip"); - ReportObjectFactory reportObjectFactory = new ReportObjectFactory(testZip); - reportObjectFactory.createAndSaveReport(result); - - assertNotNull(result); - assertTrue(isArchive(testZip)); - - String[] expectedSubmissionNames = new String[] {"B/TerrainType.java", "basecode/A/TerrainType.java"}; - for (String expected : expectedSubmissionNames) { - assertTrue(result.getSubmissions().getSubmissions().stream().anyMatch(submission -> submission.getName().equals(expected))); - } - } - /** * Checks if the given file is a valid archive * @param file The file to check diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java deleted file mode 100644 index 091f8a67af..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr1/QSort.java +++ /dev/null @@ -1,37 +0,0 @@ -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - quickSort(array, 0, array.length - 1); - return array; - } - - private void quickSort(String[] array, int low, int high) { - if (low < high) { - int pivotIndex = partition(array, low, high); - quickSort(array, low, pivotIndex - 1); - quickSort(array, pivotIndex + 1, high); - } - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - -} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java deleted file mode 100644 index 091f8a67af..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/2023/gr2/QSort.java +++ /dev/null @@ -1,37 +0,0 @@ -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - quickSort(array, 0, array.length - 1); - return array; - } - - private void quickSort(String[] array, int low, int high) { - if (low < high) { - int pivotIndex = partition(array, low, high); - quickSort(array, low, pivotIndex - 1); - quickSort(array, pivotIndex + 1, high); - } - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } - -} \ No newline at end of file diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java deleted file mode 100644 index e8e36f67da..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr1/QSort.java +++ /dev/null @@ -1,40 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - List sortedList = quickSort(List.of(array)); - return sortedList.toArray(new String[0]); - } - - private List quickSort(List list) { - if (list.size() <= 1) { - return list; - } - - String pivot = list.get(list.size() / 2); - List less = new ArrayList<>(); - List equal = new ArrayList<>(); - List greater = new ArrayList<>(); - - for (String s : list) { - int comparison = s.compareTo(pivot); - if (comparison < 0) { - less.add(s); - } else if (comparison > 0) { - greater.add(s); - } else { - equal.add(s); - } - } - - List sorted = new ArrayList<>(); - sorted.addAll(quickSort(less)); - sorted.addAll(equal); - sorted.addAll(quickSort(greater)); - return sorted; - } -} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java deleted file mode 100644 index e8e36f67da..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2020/gr2/QSort.java +++ /dev/null @@ -1,40 +0,0 @@ -import java.util.ArrayList; -import java.util.List; - -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - List sortedList = quickSort(List.of(array)); - return sortedList.toArray(new String[0]); - } - - private List quickSort(List list) { - if (list.size() <= 1) { - return list; - } - - String pivot = list.get(list.size() / 2); - List less = new ArrayList<>(); - List equal = new ArrayList<>(); - List greater = new ArrayList<>(); - - for (String s : list) { - int comparison = s.compareTo(pivot); - if (comparison < 0) { - less.add(s); - } else if (comparison > 0) { - greater.add(s); - } else { - equal.add(s); - } - } - - List sorted = new ArrayList<>(); - sorted.addAll(quickSort(less)); - sorted.addAll(equal); - sorted.addAll(quickSort(greater)); - return sorted; - } -} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java deleted file mode 100644 index d548b6fb04..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr1/QSort.java +++ /dev/null @@ -1,44 +0,0 @@ -import java.util.Stack; - -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - - Stack stack = new Stack<>(); - stack.push(new int[] { 0, array.length - 1 }); - - while (!stack.isEmpty()) { - int[] range = stack.pop(); - int low = range[0], high = range[1]; - - if (low < high) { - int pivotIndex = partition(array, low, high); - stack.push(new int[] { low, pivotIndex - 1 }); - stack.push(new int[] { pivotIndex + 1, high }); - } - } - - return array; - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } -} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java deleted file mode 100644 index d548b6fb04..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2021/gr2/QSort.java +++ /dev/null @@ -1,44 +0,0 @@ -import java.util.Stack; - -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - - Stack stack = new Stack<>(); - stack.push(new int[] { 0, array.length - 1 }); - - while (!stack.isEmpty()) { - int[] range = stack.pop(); - int low = range[0], high = range[1]; - - if (low < high) { - int pivotIndex = partition(array, low, high); - stack.push(new int[] { low, pivotIndex - 1 }); - stack.push(new int[] { pivotIndex + 1, high }); - } - } - - return array; - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } -} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java deleted file mode 100644 index 4730b95303..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr1/QSort.java +++ /dev/null @@ -1,41 +0,0 @@ -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - quickSort(array, 0, array.length - 1); - return array; - } - - private void quickSort(String[] array, int low, int high) { - while (low < high) { - int pivotIndex = partition(array, low, high); - if (pivotIndex - low < high - pivotIndex) { - quickSort(array, low, pivotIndex - 1); - low = pivotIndex + 1; - } else { - quickSort(array, pivotIndex + 1, high); - high = pivotIndex - 1; - } - } - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } -} diff --git a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java b/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java deleted file mode 100644 index 4730b95303..0000000000 --- a/core/src/test/resources/de/jplag/samples/SubmissionsWithSameName/old/2022/gr2/QSort.java +++ /dev/null @@ -1,41 +0,0 @@ -public class QSort { - public String[] qsort(String[] array) { - if (array == null || array.length == 0) { - return array; - } - quickSort(array, 0, array.length - 1); - return array; - } - - private void quickSort(String[] array, int low, int high) { - while (low < high) { - int pivotIndex = partition(array, low, high); - if (pivotIndex - low < high - pivotIndex) { - quickSort(array, low, pivotIndex - 1); - low = pivotIndex + 1; - } else { - quickSort(array, pivotIndex + 1, high); - high = pivotIndex - 1; - } - } - } - - private int partition(String[] array, int low, int high) { - String pivot = array[high]; - int i = low - 1; - for (int j = low; j < high; j++) { - if (array[j].compareTo(pivot) <= 0) { - i++; - swap(array, i, j); - } - } - swap(array, i + 1, high); - return i + 1; - } - - private void swap(String[] array, int i, int j) { - String temp = array[i]; - array[i] = array[j]; - array[j] = temp; - } -} diff --git a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts index 6577953f1e..f4b51f1cc0 100644 --- a/report-viewer/tests/e2e/OpenComparisonTest.spec.ts +++ b/report-viewer/tests/e2e/OpenComparisonTest.spec.ts @@ -46,11 +46,6 @@ const testSets: DataSet[] = [ firstSubmissionName: `2023${regexPathSeparator}QSort2023.java`, secondSubmissionName: `2022${regexPathSeparator}QSort2022.java`, }, - { - datasetName: 'submissionsWithSameName-report.zip', - firstSubmissionName: `2023${regexPathSeparator}gr1`, - secondSubmissionName: `2023${regexPathSeparator}gr2` - }, { datasetName: 'python-report.zip', firstSubmissionName: '01.py', From 81b30c015d34424d9088174c4e00c96031473881 Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Fri, 6 Sep 2024 17:20:10 +0200 Subject: [PATCH 27/28] style(JPlag.java): use explicit imports --- core/src/main/java/de/jplag/JPlag.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index 38e8d27397..db972a6380 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -1,7 +1,11 @@ package de.jplag; import java.io.File; -import java.util.*; +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.ResourceBundle; +import java.util.Set; import de.jplag.exceptions.RootDirectoryException; import org.slf4j.Logger; From bfdfd556a09cece702d7098b859b016edc7d273b Mon Sep 17 00:00:00 2001 From: euberdeveloper Date: Fri, 6 Sep 2024 17:21:37 +0200 Subject: [PATCH 28/28] style: apply spotless --- core/src/main/java/de/jplag/JPlag.java | 2 +- core/src/main/java/de/jplag/SubmissionSetBuilder.java | 3 +-- core/src/test/java/de/jplag/RootFolderTest.java | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/core/src/main/java/de/jplag/JPlag.java b/core/src/main/java/de/jplag/JPlag.java index db972a6380..a38de889ca 100644 --- a/core/src/main/java/de/jplag/JPlag.java +++ b/core/src/main/java/de/jplag/JPlag.java @@ -7,12 +7,12 @@ import java.util.ResourceBundle; import java.util.Set; -import de.jplag.exceptions.RootDirectoryException; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import de.jplag.clustering.ClusteringFactory; import de.jplag.exceptions.ExitException; +import de.jplag.exceptions.RootDirectoryException; import de.jplag.exceptions.SubmissionException; import de.jplag.merging.MatchMerging; import de.jplag.options.JPlagOptions; diff --git a/core/src/main/java/de/jplag/SubmissionSetBuilder.java b/core/src/main/java/de/jplag/SubmissionSetBuilder.java index 1ae09b11f0..c74252fba8 100644 --- a/core/src/main/java/de/jplag/SubmissionSetBuilder.java +++ b/core/src/main/java/de/jplag/SubmissionSetBuilder.java @@ -219,8 +219,7 @@ private Submission processSubmission(String submissionName, File submissionFile, return new Submission(submissionName, file, isNew, parseFilesRecursively(file), options.language()); } - private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, - Map foundSubmissions) throws ExitException { + private void processSubmissionFile(SubmissionFileData file, boolean multipleRoots, Map foundSubmissions) throws ExitException { if (isFileExcluded(file.submissionFile())) { logger.error("Exclude submission: {}", file.submissionFile().getName()); } else if (file.submissionFile().isFile() && !hasValidSuffix(file.submissionFile())) { diff --git a/core/src/test/java/de/jplag/RootFolderTest.java b/core/src/test/java/de/jplag/RootFolderTest.java index 112bccfb2b..99d6253880 100644 --- a/core/src/test/java/de/jplag/RootFolderTest.java +++ b/core/src/test/java/de/jplag/RootFolderTest.java @@ -5,11 +5,11 @@ import java.io.File; import java.util.List; -import de.jplag.exceptions.RootDirectoryException; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import de.jplag.exceptions.ExitException; +import de.jplag.exceptions.RootDirectoryException; /** * Test class for the multi-root feature and the old-new feature.