From 42a4917ef9f7afbb43196051df5cc032ab071dd3 Mon Sep 17 00:00:00 2001 From: Lukasz Baldyga Date: Sun, 29 Nov 2020 10:54:18 +0000 Subject: [PATCH] Fixed bug in ExpressionValue --- .../Verbs/Value/ValueTypes/ExpressionValue.cs | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/ExpressionValue.cs b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/ExpressionValue.cs index 2085d9f..aa94c16 100644 --- a/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/ExpressionValue.cs +++ b/Advanced Software Engineering/Advanced Software Engineering/Verbs/Value/ValueTypes/ExpressionValue.cs @@ -64,26 +64,26 @@ namespace Advanced_Software_Engineering.Verbs.Value { case "bool": //operations as standard for bool expressions eg // (a + b) => a or b, (a * b) => a and b, (a ^ b) => a xor b - if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() || variable1.ToBool()); - else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() ^ variable1.ToBool()); - else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() && variable1.ToBool()); + if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() || variable2.ToBool()); + else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() ^ variable2.ToBool()); + else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToBool() && variable2.ToBool()); else if (operation == DIVIDE) throw new Exception("Bool cannot be divided"); else throw new Exception("Bad operation"); break; case "int": - if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() + variable1.ToInt()); - else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() - variable1.ToInt()); - else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() * variable1.ToInt()); - else if (operation == DIVIDE) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() / variable1.ToInt()); + if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() + variable2.ToInt()); + else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() - variable2.ToInt()); + else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() * variable2.ToInt()); + else if (operation == DIVIDE) evaluatedValue = ValueFactory.CreateValue(variable1.ToInt() / variable2.ToInt()); else throw new Exception("Bad operation"); break; case "double": - if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() + variable1.ToDouble()); - else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() - variable1.ToDouble()); - else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() * variable1.ToDouble()); - else if (operation == DIVIDE) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() / variable1.ToDouble()); + if (operation == ADD) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() + variable2.ToDouble()); + else if (operation == SUBTRACT) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() - variable2.ToDouble()); + else if (operation == MULTIPLY) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() * variable2.ToDouble()); + else if (operation == DIVIDE) evaluatedValue = ValueFactory.CreateValue(variable1.ToDouble() / variable2.ToDouble()); else throw new Exception("Bad operation"); break;