diff options
| author | Owen <64725743+Ownwn@users.noreply.github.com> | 2025-06-27 16:47:16 +1200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-06-27 00:47:16 -0400 |
| commit | c73fdf29722a7b1586749ed6d9c97655f1d0150c (patch) | |
| tree | fe77a081a5a785c7a2efa6c2c4e8221f9ceab0f4 /src/test/java/de | |
| parent | ee07312774f9df3f80ad9ec1e396b7749edb5a7d (diff) | |
| download | Skyblocker-c73fdf29722a7b1586749ed6d9c97655f1d0150c.tar.gz Skyblocker-c73fdf29722a7b1586749ed6d9c97655f1d0150c.tar.bz2 Skyblocker-c73fdf29722a7b1586749ed6d9c97655f1d0150c.zip | |
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
Diffstat (limited to 'src/test/java/de')
| -rw-r--r-- | src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java | 15 |
1 files changed, 15 insertions, 0 deletions
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)); + } } |
