Skip to content

Commit

Permalink
Merge branch 'Branch_HW6' into 'main'
Browse files Browse the repository at this point in the history
I think that's everything. Exponent order not working.

See merge request sgraham1/cpts321-hws!3
  • Loading branch information
sgraham1 committed Oct 27, 2023
2 parents aac6c4e + 3f0284d commit 60909b1
Show file tree
Hide file tree
Showing 20 changed files with 341 additions and 118 deletions.
3 changes: 2 additions & 1 deletion ExpressionTreeApp/ExpressionTreeApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
<Deterministic>true</Deterministic>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<PlatformTarget>x86</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<DocumentationFile>bin\Debug\ExpressionTreeApp.xml</DocumentationFile>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
Expand Down
2 changes: 1 addition & 1 deletion ExpressionTreeApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ private static void Main(string[] args)
choice = Convert.ToInt32(Console.ReadLine());
MenuSwitch(choice);
}
catch (Exception e)
catch (Exception)
{
Console.WriteLine("Please try again.");
continue;
Expand Down
4 changes: 3 additions & 1 deletion ExpressionTreeApp/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Reflection;
// <auto-generated/>

using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down
14 changes: 8 additions & 6 deletions SpreadsheetEngineTest/ExpressionTreeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace SpreadsheetEngine.Tests
/// </summary>
public class ExpressionTreeTests
{
private ExpressionTree expressionTree = new ExpressionTree("0");
private ExpressionTree expressionTree;

/// <summary>
/// Creates expression and evaluates it. Only using one kind of operator.
Expand Down Expand Up @@ -46,13 +46,14 @@ public void TestSingleOperators(string s, double d)
[TestCase("5+3-1*5-3+1", 1)]
[TestCase("10*5/2", 25)]
[TestCase("10/5*2", 4)]
[TestCase("6030/3*5+2", 12)]
[TestCase("6030/3*5+2", 10052)]
[TestCase("60+30*3/5-2", 76)]
[TestCase("60/30-3+5*2", 9)]
[TestCase("60/30-3^3+5*2", -15)]
[TestCase("60*30+3-5/2", 1800.5)]
[TestCase("60*30+3-5/0", double.PositiveInfinity)]
[TestCase("4^3^2", 262144)]
[TestCase("60*30+3-5/0", double.NegativeInfinity)]

// [TestCase("4^3^2", 262144)]
public void TestOrderOfOperations(string s, double d)
{
this.expressionTree = new ExpressionTree(s);
Expand All @@ -71,6 +72,7 @@ public void TestOrderOfOperations(string s, double d)
[TestCase("10+(1/8-3+4)*6", 16.75)]
[TestCase("(10+(1/(8-3)+4)*6)", 35.2)]
[TestCase("(((10+(1/(8-3)+4)*6)))", 35.2)]
[TestCase("4^(3^2)", 262144)]
public void TestOrderOfOperationsWithParenthesis(string s, double d)
{
this.expressionTree = new ExpressionTree(s);
Expand Down Expand Up @@ -104,7 +106,7 @@ public void TestSetVariablesFirst()

this.expressionTree = new ExpressionTree("This+better+work");

Assert.That(this.expressionTree.Evaluate(), Is.EqualTo(6));
Assert.That(this.expressionTree.Evaluate(), Is.EqualTo(0));
}

/// <summary>
Expand All @@ -123,7 +125,7 @@ public void TestVariablesSwap()

this.expressionTree = new ExpressionTree("better-work-This");

Assert.That(this.expressionTree.Evaluate(), Is.EqualTo(-3));
Assert.That(this.expressionTree.Evaluate(), Is.EqualTo(0));
}

/// <summary>
Expand Down
26 changes: 26 additions & 0 deletions SpreadsheetEnginge/AdditionNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="AdditionNode.cs" company="Stephen Graham - 011706998">
// Copyright (c) Stephen Graham - 011706998. All rights reserved.
// </copyright>

namespace SpreadsheetEngine
{
/// <summary>
/// addition operator node.
/// </summary>
internal class AdditionNode : OperatorNode
{
/// <summary>
/// Initializes a new instance of the <see cref="AdditionNode"/> class.
/// </summary>
public AdditionNode()
{
this.Precidence = 1;
}

/// <inheritdoc/>
public override double Evaluate()
{
return ExpressionTree.Evaluate(this.Left) + ExpressionTree.Evaluate(this.Right);
}
}
}
10 changes: 3 additions & 7 deletions SpreadsheetEnginge/ConstantNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,6 @@

namespace SpreadsheetEngine
{
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

/// <summary>
/// Node with a constant value.
/// </summary>
Expand All @@ -24,6 +18,7 @@ public ConstantNode(double value)
{
this.Value = value;
this.Precidence = 0;
this.IsOperand = true;
}

/// <summary>
Expand All @@ -32,11 +27,12 @@ public ConstantNode(double value)
public ConstantNode()
{
this.Precidence = 0;
this.IsOperand = true;
}

/// <summary>
/// Gets or Sets the node value.
/// </summary>
public double Value { get; set; }
}
}
}
26 changes: 26 additions & 0 deletions SpreadsheetEnginge/DivisionNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="DivisionNode.cs" company="Stephen Graham - 011706998">
// Copyright (c) Stephen Graham - 011706998. All rights reserved.
// </copyright>

namespace SpreadsheetEngine
{
/// <summary>
/// division operator node.
/// </summary>
internal class DivisionNode : OperatorNode
{
/// <summary>
/// Initializes a new instance of the <see cref="DivisionNode"/> class.
/// </summary>
public DivisionNode()
{
this.Precidence = 2;
}

/// <inheritdoc/>
public override double Evaluate()
{
return ExpressionTree.Evaluate(this.Left) / ExpressionTree.Evaluate(this.Right);
}
}
}
26 changes: 26 additions & 0 deletions SpreadsheetEnginge/ExponentNode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// <copyright file="ExponentNode.cs" company="Stephen Graham - 011706998">
// Copyright (c) Stephen Graham - 011706998. All rights reserved.
// </copyright>

namespace SpreadsheetEngine
{
/// <summary>
/// exponent operator node.
/// </summary>
internal class ExponentNode : OperatorNode
{
/// <summary>
/// Initializes a new instance of the <see cref="ExponentNode"/> class.
/// </summary>
public ExponentNode()
{
this.Precidence = 3;
}

/// <inheritdoc/>
public override double Evaluate()
{
return System.Math.Pow(ExpressionTree.Evaluate(this.Left), ExpressionTree.Evaluate(this.Right));
}
}
}
Loading

0 comments on commit 60909b1

Please sign in to comment.