diff --git a/src/main/java/net/akami/mask/operation/Sum.java b/src/main/java/net/akami/mask/operation/Adder.java similarity index 93% rename from src/main/java/net/akami/mask/operation/Sum.java rename to src/main/java/net/akami/mask/operation/Adder.java index e657ccc..6c76f0c 100644 --- a/src/main/java/net/akami/mask/operation/Sum.java +++ b/src/main/java/net/akami/mask/operation/Adder.java @@ -10,18 +10,18 @@ import java.util.List; import java.util.Map; -public class Sum extends BinaryOperationHandler { +public class Adder extends BinaryOperationHandler { - private static final Sum INSTANCE = new Sum(); + private static final Adder INSTANCE = new Adder(); @Override public String operate(String a, String b) { - LOGGER.info("Sum process of {} |+| {}: \n", a, b); + LOGGER.info("Adder process of {} |+| {}: \n", a, b); List monomials = ExpressionUtils.toMonomials(a); monomials.addAll(ExpressionUtils.toMonomials(b)); LOGGER.info("Monomials : {}", monomials); String result = monomialSum(monomials, false); - LOGGER.info("---> Sum result of {} |+| {}: {}", a, b, result); + LOGGER.info("---> Adder result of {} |+| {}: {}", a, b, result); return result; } @@ -147,7 +147,7 @@ public String outFormat(String origin) { return FormatterFactory.removeMultiplicationSigns(origin); } - public static Sum getInstance() { + public static Adder getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/Derivative.java b/src/main/java/net/akami/mask/operation/Differentiator.java similarity index 88% rename from src/main/java/net/akami/mask/operation/Derivative.java rename to src/main/java/net/akami/mask/operation/Differentiator.java index 8c810ed..876dd86 100644 --- a/src/main/java/net/akami/mask/operation/Derivative.java +++ b/src/main/java/net/akami/mask/operation/Differentiator.java @@ -13,11 +13,11 @@ /** * Does not work yet */ -public class Derivative { +public class Differentiator { - private static final Derivative INSTANCE = new Derivative(); + private static final Differentiator INSTANCE = new Differentiator(); private static final QuaternaryOperationSign[] PROCEDURAL_OPERATIONS; - private static final Logger LOGGER = LoggerFactory.getLogger(Derivative.class); + private static final Logger LOGGER = LoggerFactory.getLogger(Differentiator.class); static { PROCEDURAL_OPERATIONS = new QuaternaryOperationSign[]{ @@ -84,10 +84,11 @@ public static String differentiateElement(String element) { if(element.length() == 1) return "1"; - return MathUtils.diffPow(String.valueOf(element.charAt(0)), null, element.substring(2), null); + String[] parts = element.split("\\^", 2); + return MathUtils.diffPow(parts[0], differentiateElement(parts[0]), parts[1], null); } - public static Derivative getInstance() { + public static Differentiator getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/Division.java b/src/main/java/net/akami/mask/operation/Divider.java similarity index 90% rename from src/main/java/net/akami/mask/operation/Division.java rename to src/main/java/net/akami/mask/operation/Divider.java index b20125f..9db11bf 100644 --- a/src/main/java/net/akami/mask/operation/Division.java +++ b/src/main/java/net/akami/mask/operation/Divider.java @@ -8,23 +8,29 @@ import java.math.MathContext; import java.util.List; -public class Division extends BinaryOperationHandler { +public class Divider extends BinaryOperationHandler { - private static final Division INSTANCE = new Division(); + private static final Divider INSTANCE = new Divider(); private static final MathContext CONTEXT = new MathContext(120); @Override protected String operate(String a, String b) { + LOGGER.info("Divider process of {} |/| {}: \n", a, b); + // Avoids division by zero error. if(a.equals(b)) return "1"; - LOGGER.info("Division process of {} |/| {}: \n", a, b); - if (ExpressionUtils.isANumber(a) && ExpressionUtils.isANumber(b)) { return numericalDivision(a, b); } + String unsignedB = b.substring(1); + if(unsignedB.contains("+") || unsignedB.contains("-")) { + LOGGER.error("Unable to calculate a division, the denominator being a polynomial. Returns a/b"); + return a+"/"+b; + } + List numMonomials = ExpressionUtils.toMonomials(a); int index = 0; for(String numMonomial : numMonomials) { @@ -131,7 +137,7 @@ private boolean proceedForVarDivision(String num, String den, int i, int j, List nPow = nPow.isEmpty() ? "1" : nPow; dPow = dPow.isEmpty() ? "1" : dPow; - String subResult = Subtraction.getInstance().rawOperate(nPow, dPow); + String subResult = Subtractor.getInstance().rawOperate(nPow, dPow); if(ExpressionUtils.isANumber(subResult)) { float subNumericResult = Float.parseFloat(subResult); @@ -153,7 +159,7 @@ private String assembleFactors(List factors) { BUILDER.append(1); for(String factor : factors) { if(factor != null && !factor.equals("1") && !factor.equals("1.0")) { - BUILDER.replace(0, BUILDER.length(), Multiplication.getInstance().simpleMult(BUILDER.toString(), factor)); + BUILDER.replace(0, BUILDER.length(), Multiplicator.getInstance().simpleMult(BUILDER.toString(), factor)); } } return BUILDER.toString(); @@ -197,7 +203,7 @@ public String outFormat(String origin) { return FormatterFactory.removeMultiplicationSigns(origin); } - public static Division getInstance() { + public static Divider getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/Multiplication.java b/src/main/java/net/akami/mask/operation/Multiplicator.java similarity index 86% rename from src/main/java/net/akami/mask/operation/Multiplication.java rename to src/main/java/net/akami/mask/operation/Multiplicator.java index 2576562..7d15dac 100644 --- a/src/main/java/net/akami/mask/operation/Multiplication.java +++ b/src/main/java/net/akami/mask/operation/Multiplicator.java @@ -8,9 +8,9 @@ import java.math.MathContext; import java.util.List; -public class Multiplication extends BinaryOperationHandler { +public class Multiplicator extends BinaryOperationHandler { - private static final Multiplication INSTANCE = new Multiplication(); + private static final Multiplicator INSTANCE = new Multiplicator(); private static final MathContext CONTEXT = new MathContext(120); @Override protected String operate(String a, String b) { @@ -23,7 +23,7 @@ protected String operate(String a, String b) { LOGGER.info("Trigonometry result : {}", result); return result; } - LOGGER.info("Multiplication process of {} |*| {}: \n", a, b); + LOGGER.info("Multiplicator process of {} |*| {}: \n", a, b); List aMonomials = ExpressionUtils.toMonomials(a); List bMonomials = ExpressionUtils.toMonomials(b); @@ -33,7 +33,7 @@ protected String operate(String a, String b) { for (String part : aMonomials) { for (String part2 : bMonomials) { - LOGGER.error("Treating simple mult : {} |*| {}", part, part2); + LOGGER.debug("Treating simple mult : {} |*| {}", part, part2); String result = simpleMult(part, part2); LOGGER.error("Result of simple mult between {} and {} : {}", part, part2, result); boolean first = part.equals(aMonomials.get(0)) && part2.equals(bMonomials.get(0)); @@ -46,7 +46,7 @@ protected String operate(String a, String b) { } String unReducedResult = builder.toString(); LOGGER.info("FINAL RESULT : {}", unReducedResult); - String finalResult = Sum.getInstance().operate(unReducedResult, ""); + String finalResult = Adder.getInstance().operate(unReducedResult, ""); LOGGER.error("- Result of mult {} |*| {} : {}", a, b, finalResult); return finalResult; } @@ -64,7 +64,7 @@ public String simpleMult(String a, String b) { String concatenated = a + "*" + b; String originalVars = ExpressionUtils.toVariables(concatenated); - LOGGER.error("Variables of {} and {} : {}", a, b, originalVars); + LOGGER.debug("Variables of {} and {} : {}", a, b, originalVars); a = ExpressionUtils.toNumericValue(a); b = ExpressionUtils.toNumericValue(b); @@ -104,7 +104,7 @@ public String outFormat(String origin) { return FormatterFactory.removeMultiplicationSigns(origin); } - public static Multiplication getInstance() { + public static Multiplicator getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/Pow.java b/src/main/java/net/akami/mask/operation/PowCalculator.java similarity index 75% rename from src/main/java/net/akami/mask/operation/Pow.java rename to src/main/java/net/akami/mask/operation/PowCalculator.java index 557ae1d..74d6b5f 100644 --- a/src/main/java/net/akami/mask/operation/Pow.java +++ b/src/main/java/net/akami/mask/operation/PowCalculator.java @@ -4,13 +4,13 @@ import net.akami.mask.utils.FormatterFactory; import net.akami.mask.utils.MathUtils; -public class Pow extends BinaryOperationHandler { +public class PowCalculator extends BinaryOperationHandler { - private static final Pow INSTANCE = new Pow(); + private static final PowCalculator INSTANCE = new PowCalculator(); @Override public String operate(String a, String b) { - LOGGER.info("Pow operation process between {} and {} : \n", a, b); + LOGGER.info("PowCalculator operation process between {} and {} : \n", a, b); String aVars = ExpressionUtils.toVariables(a); String bVars = ExpressionUtils.toVariables(b); @@ -25,7 +25,7 @@ public String operate(String a, String b) { // If pow value is too high, there is no point in developing the entire expression if (bVars.length() != 0 || (powValue = Float.parseFloat(b)) > 199 || (aVars.length() != 0 && powValue % 1 != 0)) { - LOGGER.info("Pow value contains variables or pow value is greater than 199. Returns a^b"); + LOGGER.info("PowCalculator value contains variables or pow value is greater than 199. Returns a^b"); a = ExpressionUtils.isReduced(a) ? a : "(" + a + ")"; b = ExpressionUtils.isReduced(b) ? b : "(" + b + ")"; return a + "^" + b; @@ -35,7 +35,7 @@ public String operate(String a, String b) { StringBuilder builder = new StringBuilder(); builder.append(a); for (int i = 1; i < powValue; i++) { - builder.replace(0, builder.length(), Multiplication.getInstance().rawOperate(builder.toString(), a)); + builder.replace(0, builder.length(), Multiplicator.getInstance().rawOperate(builder.toString(), a)); LOGGER.info("{} steps left. Currently : {}", powValue - i - 1, builder.toString()); } return builder.toString(); @@ -51,7 +51,7 @@ public String outFormat(String origin) { return MathUtils.cutSignificantZero(FormatterFactory.removeMultiplicationSigns(origin)); } - public static Pow getInstance() { + public static PowCalculator getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/Subtraction.java b/src/main/java/net/akami/mask/operation/Subtractor.java similarity index 75% rename from src/main/java/net/akami/mask/operation/Subtraction.java rename to src/main/java/net/akami/mask/operation/Subtractor.java index ed46705..bc9eb8f 100644 --- a/src/main/java/net/akami/mask/operation/Subtraction.java +++ b/src/main/java/net/akami/mask/operation/Subtractor.java @@ -5,13 +5,13 @@ import java.util.List; -public class Subtraction extends BinaryOperationHandler { +public class Subtractor extends BinaryOperationHandler { - private static final Subtraction INSTANCE = new Subtraction(); + private static final Subtractor INSTANCE = new Subtractor(); @Override protected String operate(String a, String b) { - LOGGER.info("Subtraction process of {} |-| {}: \n", a, b); + LOGGER.info("Subtractor process of {} |-| {}: \n", a, b); List monomials = ExpressionUtils.toMonomials(a); List bMonomials = ExpressionUtils.toMonomials(b); @@ -29,7 +29,7 @@ protected String operate(String a, String b) { } } monomials.addAll(bMonomials); - return Sum.getInstance().monomialSum(monomials, true); + return Adder.getInstance().monomialSum(monomials, true); } @Override @@ -42,7 +42,7 @@ public String outFormat(String origin) { return FormatterFactory.removeMultiplicationSigns(origin); } - public static Subtraction getInstance() { + public static Subtractor getInstance() { return INSTANCE; } } diff --git a/src/main/java/net/akami/mask/operation/sign/BinaryOperationSign.java b/src/main/java/net/akami/mask/operation/sign/BinaryOperationSign.java index 25de2da..4aba8b5 100644 --- a/src/main/java/net/akami/mask/operation/sign/BinaryOperationSign.java +++ b/src/main/java/net/akami/mask/operation/sign/BinaryOperationSign.java @@ -36,7 +36,6 @@ public String compute(String a, String b) { return binaryFunction.compute(a, b); } - public static BinaryOperationSign getBySign(char sign) { for(BinaryOperationSign operation : values()) { if(operation.sign == sign) { diff --git a/src/main/java/net/akami/mask/tree/FormatterTree.java b/src/main/java/net/akami/mask/tree/FormatterTree.java index 8357b3b..09bb850 100644 --- a/src/main/java/net/akami/mask/tree/FormatterTree.java +++ b/src/main/java/net/akami/mask/tree/FormatterTree.java @@ -25,6 +25,10 @@ protected void evalBranch(Branch self) { if(ExpressionUtils.hasHigherPriority(String.valueOf(self.getOperation()), right)) right = addRequiredBrackets(right); + if(ExpressionUtils.hasHigherPriority(String.valueOf(self.getOperation()), left)) + left = addRequiredBrackets(left); + // TODO + char operation = self.getOperation(); if(operation == '*') { diff --git a/src/main/java/net/akami/mask/utils/FormatterFactory.java b/src/main/java/net/akami/mask/utils/FormatterFactory.java index ecfc65d..f1125bd 100644 --- a/src/main/java/net/akami/mask/utils/FormatterFactory.java +++ b/src/main/java/net/akami/mask/utils/FormatterFactory.java @@ -9,6 +9,7 @@ import java.util.List; import static net.akami.mask.utils.ExpressionUtils.MATH_SIGNS; import static net.akami.mask.utils.ExpressionUtils.VARIABLES; +import static net.akami.mask.utils.ExpressionUtils.NUMBERS; public class FormatterFactory { @@ -60,12 +61,6 @@ public static String formatTrigonometry(String origin) { // TODO : remove 1's in front of variables, remove useless brackets public static String formatForVisual(String origin) { - /*origin = origin - .replaceAll("\\(\\((.*?)\\)(\\*@|@)\\)", "sin\\($1\\)") - .replaceAll("\\(\\((.*?)\\)(\\*#|#)\\)", "cos\\($1\\)") - .replaceAll("\\(\\((.*?)\\)(\\*§|§)\\)", "tan\\($1\\)"); - - return removeMultiplicationSigns(origin);*/ BinaryTree tree = new FormatterTree(origin); return tree.merge(); } @@ -108,21 +103,20 @@ public static String addMultiplicationSigns(String self, boolean addForTrigonome BUILDER.append(c); } } - LOGGER.error("Converted : " + self + " to " + BUILDER.toString()); + LOGGER.debug("Converted : " + self + " to " + BUILDER.toString()); return BUILDER.toString(); } public static String addAllCoefficients(String origin) { clearBuilder(); - for(int i = 0; i monomials) { - return Sum.getInstance().monomialSum(monomials, true); + return Adder.getInstance().monomialSum(monomials, true); } public static String subtract(String a, String b) { - return Subtraction.getInstance().rawOperate(a, b); + return Subtractor.getInstance().rawOperate(a, b); } public static String mult(String a, String b) { - return Multiplication.getInstance().rawOperate(a, b); + return Multiplicator.getInstance().rawOperate(a, b); } public static String divide(String a, String b) { - return Division.getInstance().rawOperate(a, b); + return Divider.getInstance().rawOperate(a, b); } public static String diffSum(String a, String altA, String b, String altB) { return sum(altA, altB); @@ -53,9 +53,13 @@ else if(!ExpressionUtils.isReduced(subtractResult)) subtractResult = "^("+subtractResult+')'; else subtractResult = '^'+subtractResult; - b = ExpressionUtils.isReduced(b) || ExpressionUtils.areEdgesBracketsConnected(b, true) ? b+"*" : "("+b+")*"; - if(!ExpressionUtils.isReduced(a)) + + if(!ExpressionUtils.isReduced(a) && !ExpressionUtils.areEdgesBracketsConnected(a, false)) a = '(' + a + ')'; + if(!ExpressionUtils.isReduced(b) && !ExpressionUtils.areEdgesBracketsConnected(b, false)) + b = '(' + b + ")*"; + else + b += '*'; if(altA.equals("1")) altA = ""; @@ -78,7 +82,7 @@ public static String breakNumericalFraction(String self) { // TODO : optimize : use other method to chain multiplications public static String pow(String a, String b) { - return Pow.getInstance().rawOperate(a, b); + return PowCalculator.getInstance().rawOperate(a, b); } public static String sin(String a) { @@ -120,7 +124,7 @@ public static String highPow(String a, String b) { float powValue; if (bVars.length() != 0 || (powValue = Float.parseFloat(b)) > 199) { - LOGGER.info("Pow value contains variables or pow value is greater than 9. Returns a^b"); + LOGGER.info("PowCalculator value contains variables or pow value is greater than 9. Returns a^b"); return a + "^" + (ExpressionUtils.isReduced(b) ? b : "(" + b + ")"); } diff --git a/src/test/java/net/akami/mask/core/EquationTest.java b/src/test/java/net/akami/mask/core/EquationTest.java index 764ae97..f167290 100644 --- a/src/test/java/net/akami/mask/core/EquationTest.java +++ b/src/test/java/net/akami/mask/core/EquationTest.java @@ -52,7 +52,15 @@ public void twoUnknownSingleLineTest() { }*/ @Test - public void twoUnknownTwoLinesTest() { + public void multiUnknownMultiLines() { + BiMask b5 = new BiMask(new MaskExpression("5x+2y+7z"), new MaskExpression("2")); + BiMask b6 = new BiMask(new MaskExpression("2x+y-3z"), new MaskExpression("7")); + BiMask b7 = new BiMask(new MaskExpression("x+2y+z"), new MaskExpression("4")); + + Map result2 = EquationSolver.solve(Arrays.asList(b5, b6, b7)); + Assertions.assertThat(result2.get('x')).isEqualTo("1"); + Assertions.assertThat(result2.get('y')).isEqualTo("2"); + Assertions.assertThat(result2.get('z')).isEqualTo("-1"); List test = EquationSolver.build("x=y", "x+y=2"); Map testSolved = EquationSolver.solve(test); @@ -72,15 +80,6 @@ public void twoUnknownTwoLinesTest() { Map result1 = EquationSolver.solve(Arrays.asList(b3, b4)); Assertions.assertThat(result1.get('x')).isEqualTo("1"); Assertions.assertThat(result1.get('y')).isEqualTo("4"); - - BiMask b5 = new BiMask(new MaskExpression("5x+2y+7z"), new MaskExpression("2")); - BiMask b6 = new BiMask(new MaskExpression("2x+y-3z"), new MaskExpression("7")); - BiMask b7 = new BiMask(new MaskExpression("x+2y+z"), new MaskExpression("4")); - - Map result2 = EquationSolver.solve(Arrays.asList(b5, b6, b7)); - Assertions.assertThat(result2.get('x')).isEqualTo("1"); - Assertions.assertThat(result2.get('y')).isEqualTo("2"); - Assertions.assertThat(result2.get('z')).isEqualTo("-1"); List lines = EquationSolver.build("x+y+z=6", "x+2y+2z=11", "x+3y+z=10"); Map result3 = EquationSolver.solve(lines); diff --git a/src/test/java/net/akami/mask/operation/DerivativeTest.java b/src/test/java/net/akami/mask/operation/DerivativeTest.java index 4f849ea..edec07f 100644 --- a/src/test/java/net/akami/mask/operation/DerivativeTest.java +++ b/src/test/java/net/akami/mask/operation/DerivativeTest.java @@ -7,12 +7,12 @@ public class DerivativeTest { @Test public void diffElementTest() { - Assertions.assertThat(Derivative.differentiateElement("x")).isEqualTo("1"); - Assertions.assertThat(Derivative.differentiateElement("a")).isEqualTo("1"); - Assertions.assertThat(Derivative.differentiateElement("3")).isEqualTo("0"); - Assertions.assertThat(Derivative.differentiateElement("-1324")).isEqualTo("0"); - Assertions.assertThat(Derivative.differentiateElement("x^2")).isEqualTo("2*x"); - Assertions.assertThat(Derivative.differentiateElement("x^(y+1)")).isEqualTo("(y+1)*x^(y)"); + Assertions.assertThat(Differentiator.differentiateElement("x")).isEqualTo("1"); + Assertions.assertThat(Differentiator.differentiateElement("a")).isEqualTo("1"); + Assertions.assertThat(Differentiator.differentiateElement("3")).isEqualTo("0"); + Assertions.assertThat(Differentiator.differentiateElement("-1324")).isEqualTo("0"); + Assertions.assertThat(Differentiator.differentiateElement("x^2")).isEqualTo("2*x"); + Assertions.assertThat(Differentiator.differentiateElement("x^(y+1)")).isEqualTo("(y+1)*x^y"); } } diff --git a/src/test/java/net/akami/mask/operation/MultiplicationTest.java b/src/test/java/net/akami/mask/operation/MultiplicationTest.java index ecad4e6..abe62b2 100644 --- a/src/test/java/net/akami/mask/operation/MultiplicationTest.java +++ b/src/test/java/net/akami/mask/operation/MultiplicationTest.java @@ -7,7 +7,7 @@ public class MultiplicationTest { @Test public void inFormatTest() { - Multiplication mult = Multiplication.getInstance(); + Multiplicator mult = Multiplicator.getInstance(); Assertions.assertThat(mult.inFormat("8x+y-3")).isEqualTo("8x+y-3"); } } diff --git a/src/test/java/net/akami/mask/operation/SumTest.java b/src/test/java/net/akami/mask/operation/SumTest.java index 73f4cbe..283c67c 100644 --- a/src/test/java/net/akami/mask/operation/SumTest.java +++ b/src/test/java/net/akami/mask/operation/SumTest.java @@ -7,7 +7,7 @@ public class SumTest { @Test public void sum() { - Sum sum = new Sum(); + Adder sum = new Adder(); Assertions.assertThat(sum.rawOperate("2", "5")).isEqualTo("7"); Assertions.assertThat(sum.rawOperate("2x", "5")).isEqualTo("2x+5"); Assertions.assertThat(sum.rawOperate("3x", "5x")).isEqualTo("8x"); @@ -18,8 +18,8 @@ public void sum() { @Test public void inFormatTest() { - Assertions.assertThat(Sum.getInstance().inFormat("5x")).isEqualTo("5x"); - Assertions.assertThat(Sum.getInstance().inFormat("5x/5")).isEqualTo("1x"); - Assertions.assertThat(Sum.getInstance().inFormat("3x/4")).isEqualTo("0.75x"); + Assertions.assertThat(Adder.getInstance().inFormat("5x")).isEqualTo("5x"); + Assertions.assertThat(Adder.getInstance().inFormat("5x/5")).isEqualTo("1x"); + Assertions.assertThat(Adder.getInstance().inFormat("3x/4")).isEqualTo("0.75x"); } } diff --git a/src/test/java/net/akami/mask/tree/DerivativeTreeTest.java b/src/test/java/net/akami/mask/tree/DerivativeTreeTest.java index 4c4511a..1eabc67 100644 --- a/src/test/java/net/akami/mask/tree/DerivativeTreeTest.java +++ b/src/test/java/net/akami/mask/tree/DerivativeTreeTest.java @@ -26,6 +26,11 @@ public void powDerivatives() { assertDerivative("(x+3)^2", "2*(x+3)"); } + @Test + public void divisionDerivatives() { + assertDerivative("(5x^2+3x)/(4x+1)", "(20x^2+10x+3)/(4x+1)^2"); + } + public void assertDerivative(String a, String b) { DerivativeTree tree = new DerivativeTree(a); Assertions.assertThat(tree.merge()).isEqualTo(b); diff --git a/src/test/java/net/akami/mask/tree/FormatterTreeTest.java b/src/test/java/net/akami/mask/tree/FormatterTreeTest.java index 151401f..2d472a4 100644 --- a/src/test/java/net/akami/mask/tree/FormatterTreeTest.java +++ b/src/test/java/net/akami/mask/tree/FormatterTreeTest.java @@ -47,6 +47,11 @@ public void complexExpression() { assertTree("5*(2+x+y)", "5(2+x+y)"); } + @Test + public void bracketsExpression() { + assertTree("(5+x)^2", "(5+x)^2"); + } + public void assertTree(String a, String b) { FormatterTree t = new FormatterTree(a); Assertions.assertThat(t.merge()).isEqualTo(b); diff --git a/src/test/java/net/akami/mask/utils/MathUtilsTest.java b/src/test/java/net/akami/mask/utils/MathUtilsTest.java index f10deb7..05663d5 100644 --- a/src/test/java/net/akami/mask/utils/MathUtilsTest.java +++ b/src/test/java/net/akami/mask/utils/MathUtilsTest.java @@ -1,6 +1,6 @@ package net.akami.mask.utils; -import net.akami.mask.operation.Division; +import net.akami.mask.operation.Divider; import net.akami.mask.operation.sign.QuaternaryOperationSign.QuaternaryMathOperation; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -44,7 +44,7 @@ public void multTest() { @Test public void divideTest() { Assertions.assertThat(MathUtils.divide("6.4+6.4z", "3.2")).isEqualTo("2+2z"); - Assertions.assertThat(Division.getInstance().simpleDivision("-2x", "4")).isEqualTo("x/-2"); + Assertions.assertThat(Divider.getInstance().simpleDivision("-2x", "4")).isEqualTo("x/-2"); } @Test @@ -74,7 +74,7 @@ public void diffDivideTest() { @Test public void diffPowTest() { QuaternaryMathOperation pow = MathUtils::diffPow; - Assertions.assertThat(pow.compute("3x", "3", "3", "0")).isEqualTo("3*3x^(2)"); - Assertions.assertThat(pow.compute("-5x", "-5", "x+1", "1")).isEqualTo("(x+1)*-5x^(x)"); + Assertions.assertThat(pow.compute("3x", "3", "3", "0")).isEqualTo("3*3x^2*3"); + Assertions.assertThat(pow.compute("-5x", "-5", "x+1", "1")).isEqualTo("(x+1)*(-5x)^x(-5)"); } } diff --git a/src/test/java/net/akami/mask/utils/ReducerTest.java b/src/test/java/net/akami/mask/utils/ReducerTest.java index ec2f5f2..d085b8a 100644 --- a/src/test/java/net/akami/mask/utils/ReducerTest.java +++ b/src/test/java/net/akami/mask/utils/ReducerTest.java @@ -1,7 +1,7 @@ package net.akami.mask.utils; import net.akami.mask.math.MaskExpression; -import net.akami.mask.operation.Division; +import net.akami.mask.operation.Divider; import org.assertj.core.api.Assertions; import org.junit.Test; @@ -116,7 +116,7 @@ public void groupingWorks() { // (x^2 + 2x + 1) / (x+1) won't give (x+1) @Test public void decomposeExpressionTest() { - Division div = Division.getInstance(); + Divider div = Divider.getInstance(); Assertions.assertThat(div.simpleDivision("4", "2")).isEqualTo("2"); Assertions.assertThat(div.simpleDivision("5", "2")).isEqualTo("5/2"); Assertions.assertThat(div.simpleDivision("6", "4")).isEqualTo("3/2"); diff --git a/src/test/resources/log4j2.xml b/src/test/resources/log4j2.xml index 57bc123..c2a1879 100644 --- a/src/test/resources/log4j2.xml +++ b/src/test/resources/log4j2.xml @@ -21,7 +21,7 @@ # put DEBUG for debug - +