Incorporate the class Upper from string package (#1952)

This commit is contained in:
Jake Antonio Ruiz Zeledón 2020-11-30 23:49:02 -06:00 committed by GitHub
parent 8eb27d712f
commit 09765b8ab4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 35 additions and 0 deletions

View 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);
}
}

View 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");
}
}