diff --git a/L2022112452_17_Test.java b/L2022112452_17_Test.java index f0866ba..c9f6d69 100644 --- a/L2022112452_17_Test.java +++ b/L2022112452_17_Test.java @@ -1,72 +1,74 @@ -import org.junit.jupiter.api.Test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.junit.jupiter.api.Assertions.*; - -class L2022112452_17_Test { - - @Test - void testFindRepeatedDnaSequences() { - Solution1 sol = new Solution1(); - - // Test case 1: General case with multiple repeated sequences - String input1 = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"; - List expected1 = new ArrayList<>(); - expected1.add("AAAAACCCCC"); - expected1.add("CCCCCAAAAA"); - List output1 = sol.findRepeatedDnaSequences(input1); - assertTrue(compareLists(output1, expected1), "Test case 1 failed."); - - // Test case 2: All characters are the same, only one repeated sequence - String input2 = "AAAAAAAAAAAAA"; - List expected2 = new ArrayList<>(); - expected2.add("AAAAAAAAAA"); - List output2 = sol.findRepeatedDnaSequences(input2); - assertTrue(compareLists(output2, expected2), "Test case 2 failed."); - - // Test case 3: No repeated sequences - String input3 = "ACGTACGTAC"; - List expected3 = Collections.emptyList(); - List output3 = sol.findRepeatedDnaSequences(input3); - assertTrue(compareLists(output3, expected3), "Test case 3 failed."); - - // Test case 4: Input string shorter than 10 characters - String input4 = "ACGT"; - List expected4 = Collections.emptyList(); - List output4 = sol.findRepeatedDnaSequences(input4); - assertTrue(compareLists(output4, expected4), "Test case 4 failed."); - - // Test case 5: Input string exactly 10 characters with no repeats - String input5 = "ACGTACGTAG"; - List expected5 = Collections.emptyList(); - List output5 = sol.findRepeatedDnaSequences(input5); - assertTrue(compareLists(output5, expected5), "Test case 5 failed."); - - // Test case 6: Edge case, input string exactly 10 characters, with repeats - String input6 = "ACGTACGTAC"; - List expected6 = Collections.emptyList(); // No repetition - List output6 = sol.findRepeatedDnaSequences(input6); - assertTrue(compareLists(output6, expected6), "Test case 6 failed."); - } - - /** - * Helper method to compare two lists regardless of order. - * - * @param list1 First list. - * @param list2 Second list. - * @return True if both lists contain the same elements, regardless of order. - */ - private boolean compareLists(List list1, List list2) { - if (list1.size() != list2.size()) { - return false; - } - List temp1 = new ArrayList<>(list1); - List temp2 = new ArrayList<>(list2); - Collections.sort(temp1); - Collections.sort(temp2); - return temp1.equals(temp2); - } -} +import org.junit.jupiter.api.Test; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import static org.junit.jupiter.api.Assertions.*; +/** + * lhx:测试用例合理且充足,写的挺不错的。 + */ + +class L2022112452_17_Test { + + @Test + void testFindRepeatedDnaSequences() { + Solution1 sol = new Solution1(); + + // Test case 1: General case with multiple repeated sequences + String input1 = "AAAAACCCCCAAAAACCCCCCAAAAAGGGTTT"; + List expected1 = new ArrayList<>(); + expected1.add("AAAAACCCCC"); + expected1.add("CCCCCAAAAA"); + List output1 = sol.findRepeatedDnaSequences(input1); + assertTrue(compareLists(output1, expected1), "Test case 1 failed."); + + // Test case 2: All characters are the same, only one repeated sequence + String input2 = "AAAAAAAAAAAAA"; + List expected2 = new ArrayList<>(); + expected2.add("AAAAAAAAAA"); + List output2 = sol.findRepeatedDnaSequences(input2); + assertTrue(compareLists(output2, expected2), "Test case 2 failed."); + + // Test case 3: No repeated sequences + String input3 = "ACGTACGTAC"; + List expected3 = Collections.emptyList(); + List output3 = sol.findRepeatedDnaSequences(input3); + assertTrue(compareLists(output3, expected3), "Test case 3 failed."); + + // Test case 4: Input string shorter than 10 characters + String input4 = "ACGT"; + List expected4 = Collections.emptyList(); + List output4 = sol.findRepeatedDnaSequences(input4); + assertTrue(compareLists(output4, expected4), "Test case 4 failed."); + + // Test case 5: Input string exactly 10 characters with no repeats + String input5 = "ACGTACGTAG"; + List expected5 = Collections.emptyList(); + List output5 = sol.findRepeatedDnaSequences(input5); + assertTrue(compareLists(output5, expected5), "Test case 5 failed."); + + // Test case 6: Edge case, input string exactly 10 characters, with repeats + String input6 = "ACGTACGTAC"; + List expected6 = Collections.emptyList(); // No repetition + List output6 = sol.findRepeatedDnaSequences(input6); + assertTrue(compareLists(output6, expected6), "Test case 6 failed."); + } + + /** + * Helper method to compare two lists regardless of order. + * + * @param list1 First list. + * @param list2 Second list. + * @return True if both lists contain the same elements, regardless of order. + */ + private boolean compareLists(List list1, List list2) { + if (list1.size() != list2.size()) { + return false; + } + List temp1 = new ArrayList<>(list1); + List temp2 = new ArrayList<>(list2); + Collections.sort(temp1); + Collections.sort(temp2); + return temp1.equals(temp2); + } +}