Test replace methods
()
| 474 | |
| 475 | /** Test replace methods */ |
| 476 | @Test |
| 477 | public void replaceTest () { |
| 478 | CharArray array = new CharArray("Hello World!"); |
| 479 | |
| 480 | // Replace first char |
| 481 | Assert.assertTrue(array.replaceFirst('l', 'L')); |
| 482 | Assert.assertEquals("HeLlo World!", array.toString()); |
| 483 | Assert.assertFalse(array.replaceFirst('z', 'Z')); |
| 484 | |
| 485 | // Replace all chars |
| 486 | array = new CharArray("Hello World!"); |
| 487 | int count = array.replaceAll('l', 'L'); |
| 488 | Assert.assertEquals(3, count); |
| 489 | Assert.assertEquals("HeLLo WorLd!", array.toString()); |
| 490 | |
| 491 | // Replace string range |
| 492 | array = new CharArray("Hello World!"); |
| 493 | array.replace(0, 5, "Hi"); |
| 494 | Assert.assertEquals("Hi World!", array.toString()); |
| 495 | |
| 496 | // Replace all strings |
| 497 | array = new CharArray("Hello World! Hello!"); |
| 498 | array.replaceAll("Hello", "Hi"); |
| 499 | Assert.assertEquals("Hi World! Hi!", array.toString()); |
| 500 | |
| 501 | // Replace first string |
| 502 | array = new CharArray("Hello World! Hello!"); |
| 503 | array.replaceFirst("Hello", "Hi"); |
| 504 | Assert.assertEquals("Hi World! Hello!", array.toString()); |
| 505 | |
| 506 | // Replace char with string |
| 507 | array = new CharArray("a-b-c"); |
| 508 | array.replace('-', " to "); |
| 509 | Assert.assertEquals("a to b to c", array.toString()); |
| 510 | } |
| 511 | |
| 512 | /** Test insert methods */ |
| 513 | @Test |
nothing calls this directly
no test coverage detected