mirror of
https://github.com/TheAlgorithms/Java.git
synced 2026-03-13 08:40:43 +08:00
Add string algorithms: RemoveStars and ComplexNumberMultiply (#7275)
* Add RemoveStars and ComplexNumberMultiply string algorithms * Add RemoveStars and ComplexNumberMultiply string algorithms * Add unit tests for RemoveStars and ComplexNumber Multiply * Fix checkstyle * Remove redundant main method * Move ComplexNumberMultiply to maths package and add input validation with tests * Apply spotless formatting --------- Co-authored-by: Deniz Altunkapan <deniz.altunkapan@outlook.com>
This commit is contained in:
committed by
GitHub
parent
1646edaeb9
commit
c9bda3dad7
@@ -0,0 +1,34 @@
|
||||
package com.thealgorithms.maths;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class ComplexNumberMultiplyTest {
|
||||
|
||||
@Test
|
||||
void testExample() {
|
||||
assertEquals("0+2i", ComplexNumberMultiply.multiply("1+1i", "1+1i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNegative() {
|
||||
assertEquals("0+-2i", ComplexNumberMultiply.multiply("1+-1i", "1+-1i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testZero() {
|
||||
assertEquals("0+0i", ComplexNumberMultiply.multiply("0+0i", "5+3i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testInvalidFormat() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ComplexNumberMultiply.multiply("1+1", "1+1i"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNullInput() {
|
||||
assertThrows(IllegalArgumentException.class, () -> ComplexNumberMultiply.multiply(null, "1+1i"));
|
||||
}
|
||||
}
|
||||
28
src/test/java/com/thealgorithms/strings/RemoveStarsTest.java
Normal file
28
src/test/java/com/thealgorithms/strings/RemoveStarsTest.java
Normal file
@@ -0,0 +1,28 @@
|
||||
package com.thealgorithms.strings;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
public class RemoveStarsTest {
|
||||
|
||||
@Test
|
||||
void testExampleCase() {
|
||||
assertEquals("lecoe", RemoveStars.removeStars("leet**cod*e"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testAllStars() {
|
||||
assertEquals("", RemoveStars.removeStars("abc***"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNoStars() {
|
||||
assertEquals("hello", RemoveStars.removeStars("hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSingleCharacter() {
|
||||
assertEquals("", RemoveStars.removeStars("a*"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user