From c73fdf29722a7b1586749ed6d9c97655f1d0150c Mon Sep 17 00:00:00 2001 From: Owen <64725743+Ownwn@users.noreply.github.com> Date: Fri, 27 Jun 2025 16:47:16 +1200 Subject: Calculator improvements (#1368) * Display calc errors to player * Add exponentiation * Catch a couple errors, could be worth adding another method to verify the tokens before they're evaluated? * Make errors translatable, fix colon --- .../java/de/hysky/skyblocker/utils/CalculatorTest.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src/test/java/de') diff --git a/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java b/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java index 22187004..f269585d 100644 --- a/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java +++ b/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java @@ -18,6 +18,17 @@ public class CalculatorTest { assertCalculation(9, "5 + 2 * 2"); assertCalculation(4, "5 - 2 / 2"); assertCalculation(15, "5 * (1 + 2)"); + assertCalculation(48, "3*4^2"); + assertCalculation(35, "3^3+(2^3)"); + } + + @Test + void testInvalids() { + assertThrows("5+asdf"); + assertThrows("5++3"); + assertThrows("2^"); + assertThrows("^"); + assertThrows("9 + 3* (0) )"); } @Test @@ -39,4 +50,8 @@ public class CalculatorTest { private void assertCalculation(double expected, String input) { Assertions.assertEquals(expected, Calculator.calculate(input)); } + + private void assertThrows(String input) { + Assertions.assertThrows(UnsupportedOperationException.class, () -> Calculator.calculate(input)); + } } -- cgit