diff options
| author | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2025-02-24 00:07:20 -0500 |
|---|---|---|
| committer | Kevinthegreat <92656833+kevinthegreat1@users.noreply.github.com> | 2025-02-24 00:07:20 -0500 |
| commit | bc33f40cb3989d6ac1a1d81d9f4cf0b89e831071 (patch) | |
| tree | 3319fb8ca83ade776f3ba663695e1e0be65fdfb2 /src/test/java | |
| parent | 54b1127efb5f7bfb84ac1d249968ffb035aec72a (diff) | |
| download | Skyblocker-bc33f40cb3989d6ac1a1d81d9f4cf0b89e831071.tar.gz Skyblocker-bc33f40cb3989d6ac1a1d81d9f4cf0b89e831071.tar.bz2 Skyblocker-bc33f40cb3989d6ac1a1d81d9f4cf0b89e831071.zip | |
Fix #1188 sign calculator floating point errors
Diffstat (limited to 'src/test/java')
| -rw-r--r-- | src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java b/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java index c29efdf2..22187004 100644 --- a/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java +++ b/src/test/java/de/hysky/skyblocker/utils/CalculatorTest.java @@ -1,31 +1,42 @@ package de.hysky.skyblocker.utils; +import de.hysky.skyblocker.skyblock.calculators.SignCalculator; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class CalculatorTest { - @Test - void testShorthands() { - Assertions.assertEquals(Calculator.calculate("1k"), 1000); - Assertions.assertEquals(Calculator.calculate("0.12k"), 120); - Assertions.assertEquals(Calculator.calculate("1k + 0.12k"), 1120); - Assertions.assertEquals(Calculator.calculate("1 + 1s + 1k + 1m + 1b"), 1001001065); - } + @Test + void testShorthands() { + assertCalculation(1000, "1k"); + assertCalculation(120, "0.12k"); + assertCalculation(1120, "1k + 0.12k"); + assertCalculation(1001001065, "1 + 1s + 1k + 1m + 1b"); + } - @Test - void testPrecedence() { - Assertions.assertEquals(Calculator.calculate("5 + 2 * 2"), 9); - Assertions.assertEquals(Calculator.calculate("5 - 2 / 2"), 4); - Assertions.assertEquals(Calculator.calculate("5 * (1 + 2)"), 15); - } + @Test + void testPrecedence() { + assertCalculation(9, "5 + 2 * 2"); + assertCalculation(4, "5 - 2 / 2"); + assertCalculation(15, "5 * (1 + 2)"); + } - @Test - void testImplicitMultiplication() { - Assertions.assertEquals(Calculator.calculate("5(2 + 2)"), 20); - } + @Test + void testImplicitMultiplication() { + assertCalculation(20, "5(2 + 2)"); + } - @Test - void testImplicitClosingParenthesis() { - Assertions.assertEquals(Calculator.calculate("5(2 + 2"), 20); - } + @Test + void testImplicitClosingParenthesis() { + assertCalculation(20, "5(2 + 2"); + } + + @Test + void testFloatingPointError() { + SignCalculator.calculate("262.6m"); + Assertions.assertEquals("2.626E8", SignCalculator.getNewValue(true)); + } + + private void assertCalculation(double expected, String input) { + Assertions.assertEquals(expected, Calculator.calculate(input)); + } } |
