Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CPE200Lab1/CPE200Lab1.sln
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1", "CPE200Lab1\CP
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1Tests", "CPE200Lab1Tests\CPE200Lab1Tests.csproj", "{C92330F4-DC76-46B0-970C-73126DE55500}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CPE200Lab1Test", "CPE200Lab1Test\CPE200Lab1Test.csproj", "{0E964631-C30F-4089-ADD6-D2F374C1E02D}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,10 +19,17 @@ Global
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}.Release|Any CPU.Build.0 = Release|Any CPU

{C92330F4-DC76-46B0-970C-73126DE55500}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C92330F4-DC76-46B0-970C-73126DE55500}.Release|Any CPU.Build.0 = Release|Any CPU

{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Debug|Any CPU.Build.0 = Debug|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Release|Any CPU.ActiveCfg = Release|Any CPU
{0E964631-C30F-4089-ADD6-D2F374C1E02D}.Release|Any CPU.Build.0 = Release|Any CPU

EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
11 changes: 11 additions & 0 deletions CPE200Lab1/CPE200Lab1/RPNCalculatorEngine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace CPE200Lab1
{

public class RPNCalculatorEngine : CalculatorEngine
{
public new string Process(string str)
Expand Down Expand Up @@ -39,4 +40,14 @@ public class RPNCalculatorEngine : CalculatorEngine
return result;
}
}
/*
public class RPNCalculatorEngine
{
public string Process(string str)
{
// your code here
return "E";
}
}
*/
}
37 changes: 37 additions & 0 deletions CPE200Lab1/CPE200Lab1Test/CPE200Lab1Test.csproj
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

<!--
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2BBC8667-ACA7-40E0-9149-6E41BD175265}</ProjectGuid>
-->

<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0E964631-C30F-4089-ADD6-D2F374C1E02D}</ProjectGuid>

<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>CPE200Lab1Test</RootNamespace>
Expand Down Expand Up @@ -39,24 +50,43 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">

<!--
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.1.18\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>
-->

<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions, Version=14.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<HintPath>..\packages\MSTest.TestFramework.1.3.2\lib\net45\Microsoft.VisualStudio.TestPlatform.TestFramework.Extensions.dll</HintPath>

</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
</ItemGroup>
<ItemGroup>
<!--
<Compile Include="RPNCalculatorEngineTest.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
-->
<Compile Include="CalculatorEngineTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="RPNCalculatorEngineTests.cs" />

</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\CPE200Lab1\CPE200Lab1.csproj">
<!--
<Project>{c2b44135-f1ac-48a9-bd70-3be2c38c2a15}</Project>
-->
<Project>{C2B44135-F1AC-48A9-BD70-3BE2C38C2A15}</Project>

<Name>CPE200Lab1</Name>
</ProjectReference>
</ItemGroup>
Expand All @@ -66,8 +96,15 @@
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<!--
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.1.18\build\net45\MSTest.TestAdapter.targets')" />
-->
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets'))" />
</Target>
<Import Project="..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets" Condition="Exists('..\packages\MSTest.TestAdapter.1.3.2\build\net45\MSTest.TestAdapter.targets')" />

</Project>
247 changes: 247 additions & 0 deletions CPE200Lab1/CPE200Lab1Test/CalculatorEngineTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,247 @@
using CPE200Lab1;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace CPE200Lab1.Tests
{
[TestClass()]
public class CalculatorEngineTest
{
//
// Test process()
//
[TestMethod()]
public void Process_BasicPlus_Test()
{
string input = "1 + 2";
string expected = "3";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Process_BasicMinus_Test()
{
string input = "5 - 3";
string expected = "2";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Process_BasicMultiply_Test()
{
string input = "5 X 3";
string expected = "15";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Process_BasicDivide_Test()
{
string input = "6 ÷ 3";
string expected = "2";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void Process_ErrorDivideByZero_Test()
{
string input = "6 ÷ 0";
string expected = "E";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void Process_ErrorMalformate_Test()
{
string input = "1+2";
string expected = "E";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.Process(input);
Assert.AreEqual(expected, actual);
}


//
// Test calculate()
//
[TestMethod()]
public void Calculate_BasicPlus_Test()
{
string firstOperand = "1";
string secondOperand = "2";
string expected = "3";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("+", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicNegativePlus_Test()
{
string firstOperand = "-1";
string secondOperand = "2";
string expected = "1";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("+", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicMinus_Test()
{
string firstOperand = "2";
string secondOperand = "1";
string expected = "1";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("-", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicNegativeMinus_Test()
{
string firstOperand = "2";
string secondOperand = "-1";
string expected = "3";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("-", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
public void Calculate_BasicMinusNegative_Test()
{
string firstOperand = "1";
string secondOperand = "2";
string expected = "-1";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("-", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicMultiply_Test()
{
string firstOperand = "2";
string secondOperand = "2";
string expected = "4";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("X", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicNegativeMultiply_Test()
{
string firstOperand = "-2";
string secondOperand = "2";
string expected = "-4";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("X", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicDivide_Test()
{
string firstOperand = "4";
string secondOperand = "2";
string expected = "2";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("÷", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_BasicNegativeDivide_Test()
{
string firstOperand = "-4";
string secondOperand = "2";
string expected = "-2";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("÷", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}
[TestMethod()]
public void Calculate_DivideByZero_Test()
{
string firstOperand = "4";
string secondOperand = "0";
string expected = "E";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.calculate("÷", firstOperand, secondOperand);
Assert.AreEqual(expected, actual);
}


//
// Test Unary()
//
[TestMethod()]
public void UnaryCalculate_BasicSquareRoot_Test()
{
string operand = "4";
string expected = "2";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.unaryCalculate("√", operand);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void UnaryCalculate_BasicOneOverX_Test()
{
string operand = "4";
string expected = "0.25";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.unaryCalculate("1/x", operand);
Assert.AreEqual(expected, actual);
}

[TestMethod()]
public void UnaryCalculate_ErrorOneOverX_Test()
{
string operand = "0";
string expected = "E";
string actual;

CalculatorEngine engine = new CalculatorEngine();
actual = engine.unaryCalculate("1/x", operand);
Assert.AreEqual(expected, actual);
}
}
}

Loading