Skip to content

Commit

Permalink
Merge pull request #2076 from GGGGeorge-gao/v5-dev
Browse files Browse the repository at this point in the history
fix Calculator.conversion EmptyStackException bug
  • Loading branch information
looly committed Jan 7, 2022
2 parents 63fc344 + 18ba850 commit 2d2cb45
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ private static String transform(String expression) {
}
}
}
if (arr[0] == '~' || (arr.length > 1 && arr[1] == '(')) {
if (arr[0] == '~' && (arr.length > 1 && arr[1] == '(')) {
arr[0] = '-';
return "0" + new String(arr);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,15 @@ public void conversationTest4(){
}

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

0 comments on commit 2d2cb45

Please sign in to comment.