diff --git a/src/main/java/com/string/Upper.java b/src/main/java/com/string/Upper.java new file mode 100644 index 000000000000..87e2abe167ed --- /dev/null +++ b/src/main/java/com/string/Upper.java @@ -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); + } +} diff --git a/src/test/java/com/string/UpperTest.java b/src/test/java/com/string/UpperTest.java new file mode 100644 index 000000000000..0f99b70d2233 --- /dev/null +++ b/src/test/java/com/string/UpperTest.java @@ -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"); + } + +} \ No newline at end of file