Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
PBoleander committed Sep 12, 2022
1 parent 58f6279 commit 5787104
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Models/Calculation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
4 changes: 2 additions & 2 deletions Models/Calculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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--;
Expand Down
2 changes: 1 addition & 1 deletion Models/Operator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Calc.Models;
public enum Operator
{
Add,
Substract,
Subtract,
Multiply,
Divide
}
6 changes: 3 additions & 3 deletions Models/OperatorChar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
12 changes: 6 additions & 6 deletions ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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]))
Expand All @@ -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;
}
Expand Down Expand Up @@ -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);

Expand Down
56 changes: 28 additions & 28 deletions Views/MainWindow.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
</Window.Styles>

<Window.KeyBindings>
<!-- 0 -->
<!-- 0 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D0">
<KeyBinding.CommandParameter>
<system:Int32>0</system:Int32>
Expand All @@ -48,7 +48,7 @@
<system:Int32>0</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 1 -->
<!-- 1 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D1">
<KeyBinding.CommandParameter>
<system:Int32>1</system:Int32>
Expand All @@ -59,7 +59,7 @@
<system:Int32>1</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 2 -->
<!-- 2 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D2">
<KeyBinding.CommandParameter>
<system:Int32>2</system:Int32>
Expand All @@ -70,7 +70,7 @@
<system:Int32>2</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 3 -->
<!-- 3 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D3">
<KeyBinding.CommandParameter>
<system:Int32>3</system:Int32>
Expand All @@ -81,7 +81,7 @@
<system:Int32>3</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 4 -->
<!-- 4 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D4">
<KeyBinding.CommandParameter>
<system:Int32>4</system:Int32>
Expand All @@ -92,7 +92,7 @@
<system:Int32>4</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 5 -->
<!-- 5 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D5">
<KeyBinding.CommandParameter>
<system:Int32>5</system:Int32>
Expand All @@ -103,7 +103,7 @@
<system:Int32>5</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 6 -->
<!-- 6 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D6">
<KeyBinding.CommandParameter>
<system:Int32>6</system:Int32>
Expand All @@ -114,7 +114,7 @@
<system:Int32>6</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 7 -->
<!-- 7 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D7">
<KeyBinding.CommandParameter>
<system:Int32>7</system:Int32>
Expand All @@ -125,7 +125,7 @@
<system:Int32>7</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 8 -->
<!-- 8 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D8">
<KeyBinding.CommandParameter>
<system:Int32>8</system:Int32>
Expand All @@ -136,7 +136,7 @@
<system:Int32>8</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- 9 -->
<!-- 9 -->
<KeyBinding Command="{Binding AddNumberCommand}" Gesture="D9">
<KeyBinding.CommandParameter>
<system:Int32>9</system:Int32>
Expand All @@ -147,7 +147,7 @@
<system:Int32>9</system:Int32>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- + -->
<!-- + -->
<KeyBinding Command="{Binding AddOperatorCommand}" Gesture="Add">
<KeyBinding.CommandParameter>
<m:Operator>Add</m:Operator>
Expand All @@ -158,34 +158,34 @@
<m:Operator>Add</m:Operator>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- - -->
<!-- - -->
<KeyBinding Command="{Binding AddOperatorCommand}" Gesture="Subtract">
<KeyBinding.CommandParameter>
<m:Operator>Substract</m:Operator>
<m:Operator>Subtract</m:Operator>
</KeyBinding.CommandParameter>
</KeyBinding>
<KeyBinding Command="{Binding AddOperatorCommand}" Gesture="OemMinus">
<KeyBinding.CommandParameter>
<m:Operator>Substract</m:Operator>
<m:Operator>Subtract</m:Operator>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- . -->
<KeyBinding Command="{Binding AddDecimalSeparatorCommand}" Gesture="OemPeriod"/>
<!-- +- -->
<!-- . -->
<KeyBinding Command="{Binding AddDecimalSeparatorCommand}" Gesture="OemPeriod" />
<!-- +- -->
<KeyBinding Command="{Binding AlternateNegativePositiveCommand}" Gesture="Alt+Subtract" />
<KeyBinding Command="{Binding AlternateNegativePositiveCommand}" Gesture="Alt+OemMinus" />
<!-- Backspace -->
<KeyBinding Command="{Binding DeleteLastCommand}" Gesture="Back"/>
<!-- Delete -->
<KeyBinding Command="{Binding ClearScreenCommand}" Gesture="Escape"/>
<KeyBinding Command="{Binding ClearScreenCommand}" Gesture="Delete"/>
<!-- * -->
<!-- Backspace -->
<KeyBinding Command="{Binding DeleteLastCommand}" Gesture="Back" />
<!-- Delete -->
<KeyBinding Command="{Binding ClearScreenCommand}" Gesture="Escape" />
<KeyBinding Command="{Binding ClearScreenCommand}" Gesture="Delete" />
<!-- * -->
<KeyBinding Command="{Binding AddOperatorCommand}" Gesture="Multiply">
<KeyBinding.CommandParameter>
<m:Operator>Multiply</m:Operator>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- / -->
<!-- / -->
<KeyBinding Command="{Binding AddOperatorCommand}" Gesture="Divide">
<KeyBinding.CommandParameter>
<m:Operator>Divide</m:Operator>
Expand All @@ -196,13 +196,13 @@
<m:Operator>Divide</m:Operator>
</KeyBinding.CommandParameter>
</KeyBinding>
<!-- () -->
<!-- () -->
<KeyBinding Command="{Binding AddParenthesisCommand}" Gesture="OemOpenBrackets" />
<KeyBinding Command="{Binding AddParenthesisCommand}" Gesture="OemCloseBrackets" />
<!-- = -->
<!-- = -->
<KeyBinding Command="{Binding PickResultCommand}" Gesture="Enter" />
</Window.KeyBindings>

<Grid Margin="5" RowDefinitions="Auto, Auto, *">
<!-- Screens -->
<TextBlock
Expand Down Expand Up @@ -366,7 +366,7 @@
Grid.Column="4"
Grid.Row="2">
<Button.CommandParameter>
<m:Operator>Substract</m:Operator>
<m:Operator>Subtract</m:Operator>
</Button.CommandParameter>
<material:MaterialIcon Kind="Minus" />
</Button>
Expand Down

0 comments on commit 5787104

Please sign in to comment.