diff --git a/SimpleCalculator.Tests/AdditionTests.cs b/SimpleCalculator.Tests/AdditionTests.cs new file mode 100644 index 0000000..2f43d14 --- /dev/null +++ b/SimpleCalculator.Tests/AdditionTests.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class AdditionTests + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/SimpleCalculator.Tests/DivisionTests.cs b/SimpleCalculator.Tests/DivisionTests.cs new file mode 100644 index 0000000..73a587b --- /dev/null +++ b/SimpleCalculator.Tests/DivisionTests.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class DivisionTests + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/SimpleCalculator.Tests/ExpressionTests.cs b/SimpleCalculator.Tests/ExpressionTests.cs new file mode 100644 index 0000000..08714db --- /dev/null +++ b/SimpleCalculator.Tests/ExpressionTests.cs @@ -0,0 +1,41 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SimpleCalculator; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class ExpressionTests + { + [TestMethod] + public void EnsureICanCreateAnExpressionInstance() + { + Expression regEx = new Expression(); + Assert.IsNotNull(regEx); + } + + [TestMethod] + public void EnsureICanPassMathProblemAndSetValues() + { + Expression regex = new Expression(); + string expectedResult = "success"; + + string actualResult = regex.verifyUserMathProblem("2 + 1"); + Assert.AreEqual(expectedResult, actualResult); + } + + [TestMethod] + public void EnsureICanAccessSetValues() + { + Expression regex = new Expression(); + int expectedMathAResult = 2; + int expectedMathBResult = 1; + string expectedOperator = "+"; + + string actualResult = regex.verifyUserMathProblem("2 + 1"); + Assert.AreEqual(expectedMathAResult, regex.mathFactorA); + Assert.AreEqual(expectedMathBResult, regex.mathFactorB); + Assert.AreEqual(expectedOperator, regex.mathOperator); + } + } +} diff --git a/SimpleCalculator.Tests/UnitTest1.cs b/SimpleCalculator.Tests/ModulusTests.cs similarity index 87% rename from SimpleCalculator.Tests/UnitTest1.cs rename to SimpleCalculator.Tests/ModulusTests.cs index 6231c55..2fae0c4 100644 --- a/SimpleCalculator.Tests/UnitTest1.cs +++ b/SimpleCalculator.Tests/ModulusTests.cs @@ -4,7 +4,7 @@ namespace SimpleCalculator.Tests { [TestClass] - public class UnitTest1 + public class ModulusTests { [TestMethod] public void TestMethod1() diff --git a/SimpleCalculator.Tests/MultiplicationTests.cs b/SimpleCalculator.Tests/MultiplicationTests.cs new file mode 100644 index 0000000..c54c79a --- /dev/null +++ b/SimpleCalculator.Tests/MultiplicationTests.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class MultiplicationTests + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj index 34800ea..03d2fed 100644 --- a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj +++ b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj @@ -45,13 +45,20 @@ - + + False + - + + + + + + diff --git a/SimpleCalculator.Tests/SubtractionTests.cs b/SimpleCalculator.Tests/SubtractionTests.cs new file mode 100644 index 0000000..e524e85 --- /dev/null +++ b/SimpleCalculator.Tests/SubtractionTests.cs @@ -0,0 +1,15 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class SubtractionTests + { + [TestMethod] + public void MakeSureWeCanCreateAnInstance() + { + + } + } +} diff --git a/SimpleCalculator/Addition.cs b/SimpleCalculator/Addition.cs new file mode 100644 index 0000000..6cedd13 --- /dev/null +++ b/SimpleCalculator/Addition.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Addition + { + } +} diff --git a/SimpleCalculator/Division.cs b/SimpleCalculator/Division.cs new file mode 100644 index 0000000..2d1fabf --- /dev/null +++ b/SimpleCalculator/Division.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Division + { + } +} diff --git a/SimpleCalculator/Expression.cs b/SimpleCalculator/Expression.cs new file mode 100644 index 0000000..075d1fa --- /dev/null +++ b/SimpleCalculator/Expression.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Text.RegularExpressions; + +namespace SimpleCalculator +{ + public class Expression + { + public string mathOperator { get; set; } + public decimal mathFactorA { get; set; } + public decimal mathFactorB { get; set; } + public Expression() + { + mathOperator = null; + mathFactorA = 0; + mathFactorB = 0; + } + + public void verifyUserMathProblem (string userMathProblem) + { + Match m = Regex.Match(userMathProblem, @"(?\w+)\s+(?[\ *xX%\/\-\+])\s+(?\w+)"); + if (m.Success) + { + mathFactorA = int.Parse(m.Groups["mathA"].Value); + mathOperator = m.Groups["mathOper"].Value.ToString(); + mathFactorB = int.Parse(m.Groups["mathB"].Value); + } + } + } +} diff --git a/SimpleCalculator/Modulus.cs b/SimpleCalculator/Modulus.cs new file mode 100644 index 0000000..59ad1a7 --- /dev/null +++ b/SimpleCalculator/Modulus.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Modulus + { + } +} diff --git a/SimpleCalculator/Multiplication.cs b/SimpleCalculator/Multiplication.cs new file mode 100644 index 0000000..2c0b34e --- /dev/null +++ b/SimpleCalculator/Multiplication.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Multiplication + { + } +} diff --git a/SimpleCalculator/Program.cs b/SimpleCalculator/Program.cs index 70d43bc..f736438 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -3,13 +3,58 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using System.Text.RegularExpressions; + namespace SimpleCalculator { - class Program + public class Program { static void Main(string[] args) - { + { + int counter = 0; + + Console.Write("[" + counter + "]"); + string userMathProblem = Console.ReadLine(); + Expression userExpression = new Expression(); + userExpression.verifyUserMathProblem(userMathProblem); + Console.WriteLine(userExpression.mathFactorA); + Console.WriteLine(userExpression.mathOperator); + Console.WriteLine(userExpression.mathFactorB); + + string operationUsed = userExpression.mathOperator; + string description = "Operation used: "; + + switch (operationUsed) + { + case "+": + Console.WriteLine(description + operationUsed); + break; + + case "-": + Console.WriteLine(description + operationUsed); + break; + + case "*": + Console.WriteLine(description + operationUsed); + break; + + case "/": + Console.WriteLine(description + operationUsed); + break; + + case "%": + Console.WriteLine(description + operationUsed); + break; + + default: + Console.WriteLine("Please select a valid operation"); + break; + } + + Console.ReadLine(); + } + } } diff --git a/SimpleCalculator/SimpleCalculator.csproj b/SimpleCalculator/SimpleCalculator.csproj index 7bf6414..eaebf77 100644 --- a/SimpleCalculator/SimpleCalculator.csproj +++ b/SimpleCalculator/SimpleCalculator.csproj @@ -43,8 +43,14 @@ + + + + + + diff --git a/SimpleCalculator/Subtraction.cs b/SimpleCalculator/Subtraction.cs new file mode 100644 index 0000000..1dbe646 --- /dev/null +++ b/SimpleCalculator/Subtraction.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Subtraction + { + } +}