Incorporate the class Upper from string package (#1952)
This commit is contained in:
parent
8eb27d712f
commit
09765b8ab4
20
src/main/java/com/string/Upper.java
Normal file
20
src/main/java/com/string/Upper.java
Normal file
@ -0,0 +1,20 @@
|
||||
package com.string;
|
||||
|
||||
public class Upper {
|
||||
|
||||
/**
|
||||
* Converts all of the characters in this {@code String} to upper case
|
||||
*
|
||||
* @param s the string to convert
|
||||
* @return the {@code String}, converted to uppercase.
|
||||
*/
|
||||
public static String toUpperCase(String s) {
|
||||
char[] values = s.toCharArray();
|
||||
for (int i = 0; i < values.length; ++i) {
|
||||
if (Character.isLetter(values[i]) && Character.isLowerCase(values[i])) {
|
||||
values[i] = Character.toUpperCase(values[i]);
|
||||
}
|
||||
}
|
||||
return new String(values);
|
||||
}
|
||||
}
|
15
src/test/java/com/string/UpperTest.java
Normal file
15
src/test/java/com/string/UpperTest.java
Normal file
@ -0,0 +1,15 @@
|
||||
package com.string;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class UpperTest extends Upper {
|
||||
|
||||
@Test
|
||||
void testUpper() {
|
||||
Assertions.assertEquals(toUpperCase("abc"), ("abc").toUpperCase(), "The strings are equals");
|
||||
//Assertions fail for functional reasons
|
||||
Assertions.assertEquals(toUpperCase("abc"), "abc", "The strings are not equals");
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user