From 82f00c5535052ed629bb12cf9f3484617924b3a1 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Mon, 1 Jan 2024 17:49:21 +0100 Subject: [PATCH] Fix "unary operator" warnings in FormulaManagerIT. Okay, the reason the code included the unary plus was to more directly represent the resulting expression, but I'm guessing the compiler isn't going to respect that intent even if it could somehow understand it, so it will probably remove the symbols and just parse it all the same. Unlike with the unary plus, the unary minus can be "fixed" by wrapping it in parentheses. The end result is of course the exact same, but the intent is perhaps a bit clearer this way. We want to try to coerce the compiler into creating an expression with "add a negative value", just for the sake of "correctness" at the runtime evaluation level, but even if that isn't what will actually happen, the explicit code is still a bit easier to read. While unary plus is easy to disregard, "fixing" an unnecessary unary minus would mean having to change the binary operator before it, which muddies the intent of the expression. --- .../garbagemule/MobArena/formula/FormulaManagerIT.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/java/com/garbagemule/MobArena/formula/FormulaManagerIT.java b/src/test/java/com/garbagemule/MobArena/formula/FormulaManagerIT.java index 069c9f7..4a7ca68 100644 --- a/src/test/java/com/garbagemule/MobArena/formula/FormulaManagerIT.java +++ b/src/test/java/com/garbagemule/MobArena/formula/FormulaManagerIT.java @@ -230,8 +230,8 @@ public class FormulaManagerIT { @Parameters(name = "{0} = {1}") public static Iterable data() { return Arrays.asList(new Object[][]{ - {"1 + +1.2", 1 + +1.2}, - {"1 + -1.2", 1 + -1.2}, + {"1 + +1.2", 1 + 1.2}, + {"1 + -1.2", 1 + (-1.2)}, }); } @@ -259,8 +259,8 @@ public class FormulaManagerIT { @Parameters(name = "{0} = {1}") public static Iterable data() { return Arrays.asList(new Object[][]{ - {"1+-2", 1 + -2}, - {"3-+4", 3 - +4}, + {"1+-2", 1 + (-2)}, + {"3-+4", 3 - 4}, {"3*7.5", 3 * 7.5}, {"10/2.5", 10 / 2.5}, {"9%4", 9 % 4},