diff --git a/Models/Calculation.cs b/Models/Calculation.cs index 3a814cc..a3e89aa 100644 --- a/Models/Calculation.cs +++ b/Models/Calculation.cs @@ -20,7 +20,7 @@ public double Calculate() return _operator switch { Operator.Add => _firstValue + _secondValue, - Operator.Substract => _firstValue - _secondValue, + Operator.Subtract => _firstValue - _secondValue, Operator.Multiply => _firstValue * _secondValue, Operator.Divide => _firstValue / _secondValue, _ => throw new InvalidDataException("Operator not allowed") diff --git a/Models/Calculator.cs b/Models/Calculator.cs index 99637a9..eddbc00 100644 --- a/Models/Calculator.cs +++ b/Models/Calculator.cs @@ -26,7 +26,7 @@ public static string Calculate(string str) return character switch { OperatorChar.Add => Operator.Add, - OperatorChar.Substract => Operator.Substract, + OperatorChar.Subtract => Operator.Subtract, OperatorChar.Multiply => Operator.Multiply, OperatorChar.Divide => Operator.Divide, _ => null @@ -101,7 +101,7 @@ private static int SetIndexOfPreviousOperator(MyStringBuilder calculus, int inde // If the first value is negative and not the first calculation, an operator must be just before the index // previously calculated as the indexOfPreviousOperator, e.g. in a+-b/c the - isn't previousOperator, it's + else if (indexOfPreviousOperator > 0 && - calculus[indexOfPreviousOperator].Equals(OperatorChar.Substract) && // minus sign + calculus[indexOfPreviousOperator].Equals(OperatorChar.Subtract) && // minus sign OperatorChar.IsAnOperator(calculus[indexOfPreviousOperator - 1])) // previous index contains an operator { indexOfPreviousOperator--; diff --git a/Models/Operator.cs b/Models/Operator.cs index f13bc6b..e0a7d26 100644 --- a/Models/Operator.cs +++ b/Models/Operator.cs @@ -3,7 +3,7 @@ namespace Calc.Models; public enum Operator { Add, - Substract, + Subtract, Multiply, Divide } \ No newline at end of file diff --git a/Models/OperatorChar.cs b/Models/OperatorChar.cs index 0bf1376..c2ae2e4 100644 --- a/Models/OperatorChar.cs +++ b/Models/OperatorChar.cs @@ -5,13 +5,13 @@ namespace Calc.Models; public static class OperatorChar { public const char Add = '+'; - public const char Substract = '-'; + public const char Subtract = '-'; public const char Multiply = '*'; public const char Divide = '/'; - public static readonly char[] Operators = { Add, Substract, Multiply, Divide }; + public static readonly char[] Operators = { Add, Subtract, Multiply, Divide }; public static readonly char[] PrecedentOperators = { Multiply, Divide }; - public static readonly char[] NonPrecedentOperators = { Add, Substract }; + public static readonly char[] NonPrecedentOperators = { Add, Subtract }; public static bool IsAnOperator(char character) { diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs index 88f102c..48fd7b5 100644 --- a/ViewModels/MainWindowViewModel.cs +++ b/ViewModels/MainWindowViewModel.cs @@ -71,7 +71,7 @@ private void AddOperator(Operator @operator) ShownString += @operator switch { Operator.Add => OperatorChar.Add, - Operator.Substract => OperatorChar.Substract, + Operator.Subtract => OperatorChar.Subtract, Operator.Multiply => OperatorChar.Multiply, Operator.Divide => OperatorChar.Divide, _ => throw new InvalidDataException("Operator not allowed") @@ -98,12 +98,12 @@ private void AlternateNegativePositive() var indexWhereSetOrUnsetSign = SetIndexWhereToSetOrUnsetSign(); if (ShownString.Length == 0 || ShownString[^1].Equals('(')) - ShownString += OperatorChar.Substract; + ShownString += OperatorChar.Subtract; else { switch (ShownString[indexWhereSetOrUnsetSign]) { - case OperatorChar.Substract: + case OperatorChar.Subtract: if (indexWhereSetOrUnsetSign == 0 || ShownString[indexWhereSetOrUnsetSign - 1].Equals('(') || OperatorChar.IsAnOperator(ShownString[indexWhereSetOrUnsetSign - 1])) @@ -112,13 +112,13 @@ private void AlternateNegativePositive() else // Add - ShownString = ShownString[..indexWhereSetOrUnsetSign] + - OperatorChar.Substract + + OperatorChar.Subtract + ShownString[indexWhereSetOrUnsetSign..]; break; default: // Add - ShownString = ShownString[..indexWhereSetOrUnsetSign] + - OperatorChar.Substract + + OperatorChar.Subtract + ShownString[indexWhereSetOrUnsetSign..]; break; } @@ -197,7 +197,7 @@ private int SetIndexWhereToSetOrUnsetSign() char[] nonSubstractOperators = { OperatorChar.Add, OperatorChar.Multiply, OperatorChar.Divide }; var indexAfterLastNonSubstractOperator = ShownString.LastIndexOfAny(nonSubstractOperators) + 1; - var indexOfLastSubstractOperator = ShownString.LastIndexOf(OperatorChar.Substract); + var indexOfLastSubstractOperator = ShownString.LastIndexOf(OperatorChar.Subtract); var indexAfterLastParenthesis = ShownString.LastIndexOf('(') + 1; var indexLastOperator = MaxOf(indexAfterLastNonSubstractOperator, indexOfLastSubstractOperator); diff --git a/Views/MainWindow.axaml b/Views/MainWindow.axaml index 401df05..f197b91 100644 --- a/Views/MainWindow.axaml +++ b/Views/MainWindow.axaml @@ -37,7 +37,7 @@ - + 0 @@ -48,7 +48,7 @@ 0 - + 1 @@ -59,7 +59,7 @@ 1 - + 2 @@ -70,7 +70,7 @@ 2 - + 3 @@ -81,7 +81,7 @@ 3 - + 4 @@ -92,7 +92,7 @@ 4 - + 5 @@ -103,7 +103,7 @@ 5 - + 6 @@ -114,7 +114,7 @@ 6 - + 7 @@ -125,7 +125,7 @@ 7 - + 8 @@ -136,7 +136,7 @@ 8 - + 9 @@ -147,7 +147,7 @@ 9 - + Add @@ -158,34 +158,34 @@ Add - + - Substract + Subtract - Substract + Subtract - - - + + + - - - - - - + + + + + + Multiply - + Divide @@ -196,13 +196,13 @@ Divide - + - + - + - Substract + Subtract