mirror of
https://github.com/Eaglercraft-TeaVM-Fork/eagler-teavm.git
synced 2024-12-22 08:14:09 -08:00
classlib: fix corner case for Character.forDigit (#769)
This commit is contained in:
parent
a493d003e5
commit
2d91f539c7
|
@ -363,7 +363,7 @@ public class TCharacter extends TObject implements TComparable<TCharacter> {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static char forDigit(int digit, int radix) {
|
public static char forDigit(int digit, int radix) {
|
||||||
if (radix < MIN_RADIX || radix > MAX_RADIX || digit >= radix) {
|
if (radix < MIN_RADIX || radix > MAX_RADIX || digit < 0 || digit >= radix) {
|
||||||
return '\0';
|
return '\0';
|
||||||
}
|
}
|
||||||
return digit < 10 ? (char) ('0' + digit) : (char) ('a' + digit - 10);
|
return digit < 10 ? (char) ('0' + digit) : (char) ('a' + digit - 10);
|
||||||
|
|
|
@ -77,4 +77,15 @@ public class CharacterTest {
|
||||||
assertEquals((char) 12405, Character.reverseBytes((char) 30000));
|
assertEquals((char) 12405, Character.reverseBytes((char) 30000));
|
||||||
assertEquals((char) -12150, Character.reverseBytes((char) -30000));
|
assertEquals((char) -12150, Character.reverseBytes((char) -30000));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void characterForDigit() {
|
||||||
|
assertEquals('\0', Character.forDigit(-1, 5));
|
||||||
|
assertEquals('\0', Character.forDigit(6, 5));
|
||||||
|
assertEquals('\0', Character.forDigit(1, 1));
|
||||||
|
assertEquals('\0', Character.forDigit(1, 37));
|
||||||
|
assertEquals('a', Character.forDigit(10, 11));
|
||||||
|
assertEquals('\0', Character.forDigit(10, 10));
|
||||||
|
assertEquals('5', Character.forDigit(5, 6));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user