Changes for Code review feedback:
1. Change main method to use command-line input. 2. Update test class to use static imports. 2. Add more use cases in test-cases.
This commit is contained in:
parent
ed0713046f
commit
ca681a8e67
|
@ -44,8 +44,11 @@ public class LongestSubstringNonRepeatingCharacters {
|
|||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
String input = "CODINGISAWESOME";
|
||||
System.out.println(getUniqueCharacterSubstring(input));
|
||||
if(args.length > 0) {
|
||||
System.out.println(getUniqueCharacterSubstring(args[0]));
|
||||
} else {
|
||||
System.err.println("This program expects command-line input. Please try again!");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,20 +1,31 @@
|
|||
package com.baeldung.algorithms.string;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static com.baeldung.algorithms.string.LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstring;
|
||||
import static com.baeldung.algorithms.string.LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstringBruteForce;
|
||||
|
||||
public class LongestSubstringNonRepeatingCharactersTest {
|
||||
|
||||
@Test
|
||||
void givenString_whenGetUniqueCharacterSubstringBruteForceCalled_thenResultFoundAsExpected() {
|
||||
String input = "CODINGISAWESOME";
|
||||
Assertions.assertEquals("NGISAWE", LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstringBruteForce(input));
|
||||
assertEquals("", getUniqueCharacterSubstringBruteForce(""));
|
||||
assertEquals("A", getUniqueCharacterSubstringBruteForce("A"));
|
||||
assertEquals("ABCDEF", getUniqueCharacterSubstringBruteForce("AABCDEF"));
|
||||
assertEquals("ABCDEF", getUniqueCharacterSubstringBruteForce("ABCDEFF"));
|
||||
assertEquals("NGISAWE", getUniqueCharacterSubstringBruteForce("CODINGISAWESOME"));
|
||||
assertEquals("be coding", getUniqueCharacterSubstringBruteForce("always be coding"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void givenString_whenGetUniqueCharacterSubstringCalled_thenResultFoundAsExpected() {
|
||||
String input = "CODINGISAWESOME";
|
||||
Assertions.assertEquals("NGISAWE",LongestSubstringNonRepeatingCharacters.getUniqueCharacterSubstring(input));
|
||||
assertEquals("", getUniqueCharacterSubstring(""));
|
||||
assertEquals("A", getUniqueCharacterSubstring("A"));
|
||||
assertEquals("ABCDEF", getUniqueCharacterSubstring("AABCDEF"));
|
||||
assertEquals("ABCDEF", getUniqueCharacterSubstring("ABCDEFF"));
|
||||
assertEquals("NGISAWE", getUniqueCharacterSubstring("CODINGISAWESOME"));
|
||||
assertEquals("be coding", getUniqueCharacterSubstring("always be coding"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue