Untitled

 avatar
unknown
plain_text
2 years ago
1.4 kB
6
Indexable
public class StringManipulationTest {

    private StringManipulation sm;

    @Before
    public void setUp() {
        sm = new StringManipulation();
    }

    @Test
    public void testFormat() {
        String format = "Name: %s, Age: %d, Height: %.2f";
        String[] args = {"John", "25", "178.5"};
        String result = sm.format(format, args);
        assertEquals("Name: John, Age: 25, Height: 178.50", result);
    }

    @Test
    public void testStartsWith() {
        assertTrue(sm.startsWith("Hello, World!", "Hello"));
        assertFalse(sm.startsWith("Hello, World!", "World"));
    }

    @Test
    public void testEndsWith() {
        assertTrue(sm.endsWith("Hello, World!", "World!"));
        assertFalse(sm.endsWith("Hello, World!", "Hello"));
    }

    @Test
    public void testToLowerCase() {
        assertEquals("hello, world!", sm.toLowerCase("Hello, World!"));
    }

    @Test
    public void testToUpperCase() {
        assertEquals("HELLO, WORLD!", sm.toUpperCase("Hello, World!"));
    }

    @Test
    public void testTrim() {
        assertEquals("Hello, World!", sm.trim("   Hello, World!   "));
    }

    @Test
    public void testCompareTo() {
        assertEquals(0, sm.compareTo("Hello", "Hello"));
        assertTrue(sm.compareTo("Hello", "World") < 0);
        assertTrue(sm.compareTo("World", "Hello") > 0);
    }
}
Editor is loading...
Leave a Comment