Merge pull request #2076 from GGGGeorge-gao/v5-dev

fix Calculator.conversion EmptyStackException bug
This commit is contained in:
Golden Looly 2022-01-07 19:40:58 +08:00 committed by GitHub
commit 2d2cb4590d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -191,7 +191,7 @@ public class Calculator {
}
}
}
if (arr[0] == '~' || (arr.length > 1 && arr[1] == '(')) {
if (arr[0] == '~' && (arr.length > 1 && arr[1] == '(')) {
arr[0] = '-';
return "0" + new String(arr);
} else {

View File

@ -31,10 +31,15 @@ public class CalculatorTest {
}
@Test
@Ignore
public void conversationTest5(){
// https://github.com/dromara/hutool/issues/1984
final double conversion = Calculator.conversion("((1/1) / (1/1) -1) * 100");
Assert.assertEquals((88D * 66 / 23) % 26, conversion, 2);
Assert.assertEquals(0, conversion, 2);
}
@Test
public void conversationTest6() {
final double conversion = Calculator.conversion("-((2.12-2) * 100)");
Assert.assertEquals(-1D * (2.12 - 2) * 100, conversion, 2);
}
}