mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-27 22:43:30 +08:00
Format code with prettier (#3375)
This commit is contained in:
@ -1,11 +1,11 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AlphabeticalTest {
|
||||
|
||||
@Test
|
||||
public void isAlphabetical() {
|
||||
// expected to be true
|
||||
@ -26,5 +26,4 @@ public class AlphabeticalTest {
|
||||
assertFalse(Alphabetical.isAlphabetical(input5));
|
||||
assertFalse(Alphabetical.isAlphabetical(input6));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class AnagramsTest {
|
||||
|
||||
@Test
|
||||
public void isAlphabetical() {
|
||||
String input1 = "late";
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CharacterSameTest {
|
||||
|
||||
@Test
|
||||
public void isAllCharactersSame() {
|
||||
String input1 = "aaa";
|
||||
@ -22,7 +23,5 @@ public class CharacterSameTest {
|
||||
assertTrue(CharactersSame.isAllCharactersSame(input5));
|
||||
assertTrue(CharactersSame.isAllCharactersSame(input6));
|
||||
assertFalse(CharactersSame.isAllCharactersSame(input7));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,35 +1,35 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class CheckAnagramsTest {
|
||||
|
||||
@Test
|
||||
public void CheckAnagrams() {
|
||||
String testString1 = "STUDY";
|
||||
String testString2 = "DUSTY";
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1,testString2));
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1, testString2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CheckFalseAnagrams() {
|
||||
String testString1 = "STUDY";
|
||||
String testString2 = "random";
|
||||
assertFalse(CheckAnagrams.isAnagrams(testString1,testString2));
|
||||
assertFalse(CheckAnagrams.isAnagrams(testString1, testString2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CheckSameWordAnagrams() {
|
||||
String testString1 = "STUDY";
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1,testString1));
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1, testString1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void CheckDifferentCasesAnagram() {
|
||||
String testString1 = "STUDY";
|
||||
String testString2 = "dusty";
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1,testString2));
|
||||
assertTrue(CheckAnagrams.isAnagrams(testString1, testString2));
|
||||
}
|
||||
}
|
||||
|
@ -1,23 +1,39 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class HammingDistanceTest {
|
||||
|
||||
@Test
|
||||
void testHammingDistance() throws Exception {
|
||||
assertEquals(HammingDistance.calculateHammingDistance("", ""), 0);
|
||||
assertEquals(HammingDistance.calculateHammingDistance("java", "java"), 0);
|
||||
assertEquals(HammingDistance.calculateHammingDistance("karolin", "kathrin"), 3);
|
||||
assertEquals(HammingDistance.calculateHammingDistance("kathrin", "kerstin"), 4);
|
||||
assertEquals(HammingDistance.calculateHammingDistance("00000", "11111"), 5);
|
||||
assertEquals(
|
||||
HammingDistance.calculateHammingDistance("java", "java"),
|
||||
0
|
||||
);
|
||||
assertEquals(
|
||||
HammingDistance.calculateHammingDistance("karolin", "kathrin"),
|
||||
3
|
||||
);
|
||||
assertEquals(
|
||||
HammingDistance.calculateHammingDistance("kathrin", "kerstin"),
|
||||
4
|
||||
);
|
||||
assertEquals(
|
||||
HammingDistance.calculateHammingDistance("00000", "11111"),
|
||||
5
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNotEqualStringLengths() {
|
||||
Exception exception = assertThrows(Exception.class, () -> HammingDistance.calculateHammingDistance("ab", "abc"));
|
||||
Exception exception = assertThrows(
|
||||
Exception.class,
|
||||
() -> HammingDistance.calculateHammingDistance("ab", "abc")
|
||||
);
|
||||
assertEquals("String lengths must be equal", exception.getMessage());
|
||||
}
|
||||
}
|
||||
|
@ -1,30 +1,31 @@
|
||||
package com.thealgorithms.strings;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import java.util.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class IsomorphicTest {
|
||||
|
||||
@Test
|
||||
public static void main(String[] args) {
|
||||
String str1 = "abbbbaac";
|
||||
String str2 = "kffffkkd";
|
||||
|
||||
String str1 = "abbbbaac";
|
||||
String str2 = "kffffkkd";
|
||||
String str3 = "xyxyxy";
|
||||
String str4 = "bnbnbn";
|
||||
|
||||
String str3 = "xyxyxy";
|
||||
String str4 = "bnbnbn";
|
||||
String str5 = "ghjknnmm";
|
||||
String str6 = "wertpopo";
|
||||
|
||||
String str5 = "ghjknnmm";
|
||||
String str6 = "wertpopo";
|
||||
String str7 = "aaammmnnn";
|
||||
String str8 = "ggghhhbbj";
|
||||
|
||||
String str7 = "aaammmnnn";
|
||||
String str8 = "ggghhhbbj";
|
||||
Isomorphic isomorphic = new Isomorphic();
|
||||
|
||||
Isomorphic isomorphic = new Isomorphic();
|
||||
|
||||
assertTrue(isomorphic.checkStrings(str1, str2));
|
||||
assertTrue(isomorphic.checkStrings(str3, str4));
|
||||
assertFalse(isomorphic.checkStrings(str5, str6));
|
||||
assertFalse(isomorphic.checkStrings(str7, str8));
|
||||
}
|
||||
assertTrue(isomorphic.checkStrings(str1, str2));
|
||||
assertTrue(isomorphic.checkStrings(str3, str4));
|
||||
assertFalse(isomorphic.checkStrings(str5, str6));
|
||||
assertFalse(isomorphic.checkStrings(str7, str8));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class PalindromeTest {
|
||||
|
||||
@Test
|
||||
public void palindrome() {
|
||||
String input1 = "kayak";
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static com.thealgorithms.strings.Pangram.isPangram;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static com.thealgorithms.strings.Pangram.isPangram;
|
||||
|
||||
|
||||
public class PangramTest {
|
||||
|
||||
@Test
|
||||
public void testPangram() {
|
||||
assertTrue(isPangram("The quick brown fox jumps over the lazy dog"));
|
||||
|
@ -1,10 +1,11 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class UpperTest {
|
||||
|
||||
@Test
|
||||
public void toUpperCase() {
|
||||
String input1 = "hello world";
|
||||
|
@ -4,11 +4,18 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class longestNonRepeativeSubstringTest {
|
||||
|
||||
@Test
|
||||
public void palindrome() {
|
||||
String input1 = "HelloWorld";
|
||||
String input2 = "javaIsAProgrammingLanguage";
|
||||
Assertions.assertEquals( longestNonRepeativeSubstring.lengthOfLongestSubstring( input1 ) , 5 ) ;
|
||||
Assertions.assertEquals( longestNonRepeativeSubstring.lengthOfLongestSubstring( input2 ) , 9 ) ;
|
||||
Assertions.assertEquals(
|
||||
longestNonRepeativeSubstring.lengthOfLongestSubstring(input1),
|
||||
5
|
||||
);
|
||||
Assertions.assertEquals(
|
||||
longestNonRepeativeSubstring.lengthOfLongestSubstring(input2),
|
||||
9
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -4,11 +4,18 @@ import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class zigZagPatternTest {
|
||||
|
||||
@Test
|
||||
public void palindrome() {
|
||||
String input1 = "HelloWorldFromJava";
|
||||
String input2 = "javaIsAProgrammingLanguage";
|
||||
Assertions.assertEquals( zigZagPattern.encode( input1 , 4 ) , "HooeWrrmalolFJvlda" ) ;
|
||||
Assertions.assertEquals( zigZagPattern.encode( input2 , 4 ) , "jAaLgasPrmgaaevIrgmnnuaoig" ) ;
|
||||
Assertions.assertEquals(
|
||||
zigZagPattern.encode(input1, 4),
|
||||
"HooeWrrmalolFJvlda"
|
||||
);
|
||||
Assertions.assertEquals(
|
||||
zigZagPattern.encode(input2, 4),
|
||||
"jAaLgasPrmgaaevIrgmnnuaoig"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user