From 378f804e3cd15b96dd72b417e8c92fd1f48925bf Mon Sep 17 00:00:00 2001 From: jessica kilby Date: Wed, 1 Feb 2017 18:04:54 -0600 Subject: [PATCH 1/9] unit test and other files setup --- SimpleCalculator.Tests/AdditionTests.cs | 14 ++++++++++++++ .../{UnitTest1.cs => ModulusTests.cs} | 2 +- SimpleCalculator.Tests/MultiplicationTests.cs | 14 ++++++++++++++ SimpleCalculator.Tests/SubtractionTests.cs | 15 +++++++++++++++ SimpleCalculator/Addition.cs | 12 ++++++++++++ SimpleCalculator/Integer.cs | 12 ++++++++++++ SimpleCalculator/Modulus.cs | 12 ++++++++++++ SimpleCalculator/Multiplication.cs | 12 ++++++++++++ SimpleCalculator/Subtraction.cs | 12 ++++++++++++ 9 files changed, 104 insertions(+), 1 deletion(-) create mode 100644 SimpleCalculator.Tests/AdditionTests.cs rename SimpleCalculator.Tests/{UnitTest1.cs => ModulusTests.cs} (87%) create mode 100644 SimpleCalculator.Tests/MultiplicationTests.cs create mode 100644 SimpleCalculator.Tests/SubtractionTests.cs create mode 100644 SimpleCalculator/Addition.cs create mode 100644 SimpleCalculator/Integer.cs create mode 100644 SimpleCalculator/Modulus.cs create mode 100644 SimpleCalculator/Multiplication.cs create mode 100644 SimpleCalculator/Subtraction.cs 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/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/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/Integer.cs b/SimpleCalculator/Integer.cs new file mode 100644 index 0000000..fa2fbe9 --- /dev/null +++ b/SimpleCalculator/Integer.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace SimpleCalculator +{ + class Integer + { + } +} 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/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 + { + } +} From 09b7201b848e027bf4272966cb3e9d89dfcec722 Mon Sep 17 00:00:00 2001 From: Taylor Harry Date: Wed, 1 Feb 2017 16:08:34 -0800 Subject: [PATCH 2/9] added regex to verify user math problem is accurate --- SimpleCalculator/Program.cs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/SimpleCalculator/Program.cs b/SimpleCalculator/Program.cs index 70d43bc..cfe26e6 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -3,13 +3,30 @@ using System.Linq; using System.Text; using System.Threading.Tasks; - +using System.Text.RegularExpressions; namespace SimpleCalculator { class Program { static void Main(string[] args) { + int counter = 0; + Console.Write("[" + counter + "]"); + string userMathProblem = Console.ReadLine(); + Match m = Regex.Match(userMathProblem, @"(?\w+)\s+(?[\ *xX%\/\-\+])\s+(?\w+)"); + if (m.Success) + { + string mathA = m.Groups["mathA"].Value.ToString(); + string mathOper = m.Groups["mathOper"].Value.ToString(); + string mathB = m.Groups["mathB"].Value.ToString(); + Console.WriteLine(mathA + mathOper + mathB); + } + else + { + Console.WriteLine("Invalid math problem, please tryagain..."); + } + + Console.ReadLine(); } } } From c0fb80a440bb62b9deed04517b345e3aea3f74a4 Mon Sep 17 00:00:00 2001 From: jessica kilby Date: Wed, 1 Feb 2017 18:08:58 -0600 Subject: [PATCH 3/9] more files --- SimpleCalculator.Tests/SimpleCalculator.Tests.csproj | 9 +++++++-- SimpleCalculator/SimpleCalculator.csproj | 5 +++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj index 34800ea..d4e3972 100644 --- a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj +++ b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj @@ -45,13 +45,18 @@ - + + False + - + + + + diff --git a/SimpleCalculator/SimpleCalculator.csproj b/SimpleCalculator/SimpleCalculator.csproj index 7bf6414..bbab5a6 100644 --- a/SimpleCalculator/SimpleCalculator.csproj +++ b/SimpleCalculator/SimpleCalculator.csproj @@ -43,8 +43,13 @@ + + + + + From 19c69d25e3d08839affa6d81e860be1f703e0087 Mon Sep 17 00:00:00 2001 From: Taylor Harry Date: Wed, 1 Feb 2017 16:32:22 -0800 Subject: [PATCH 4/9] added bug fix to regex in program file --- SimpleCalculator/Program.cs | 5 ----- 1 file changed, 5 deletions(-) diff --git a/SimpleCalculator/Program.cs b/SimpleCalculator/Program.cs index cfe26e6..6737640 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -21,11 +21,6 @@ static void Main(string[] args) string mathB = m.Groups["mathB"].Value.ToString(); Console.WriteLine(mathA + mathOper + mathB); } - else - { - Console.WriteLine("Invalid math problem, please tryagain..."); - } - Console.ReadLine(); } } From c93e7de774f8462f0f857bda72f3a450c9cf1626 Mon Sep 17 00:00:00 2001 From: jessica kilby Date: Wed, 1 Feb 2017 18:51:43 -0600 Subject: [PATCH 5/9] added division --- SimpleCalculator.Tests/DivisionTests.cs | 14 ++++++++++++++ .../SimpleCalculator.Tests.csproj | 1 + SimpleCalculator/{Integer.cs => Division.cs} | 0 3 files changed, 15 insertions(+) create mode 100644 SimpleCalculator.Tests/DivisionTests.cs rename SimpleCalculator/{Integer.cs => Division.cs} (100%) diff --git a/SimpleCalculator.Tests/DivisionTests.cs b/SimpleCalculator.Tests/DivisionTests.cs new file mode 100644 index 0000000..6231c55 --- /dev/null +++ b/SimpleCalculator.Tests/DivisionTests.cs @@ -0,0 +1,14 @@ +using System; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace SimpleCalculator.Tests +{ + [TestClass] + public class UnitTest1 + { + [TestMethod] + public void TestMethod1() + { + } + } +} diff --git a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj index d4e3972..e0b88e6 100644 --- a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj +++ b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj @@ -57,6 +57,7 @@ + diff --git a/SimpleCalculator/Integer.cs b/SimpleCalculator/Division.cs similarity index 100% rename from SimpleCalculator/Integer.cs rename to SimpleCalculator/Division.cs From 09492b80116189fa0d0c744ce70370bd6565fdc4 Mon Sep 17 00:00:00 2001 From: Taylor Harry Date: Wed, 1 Feb 2017 17:15:40 -0800 Subject: [PATCH 6/9] added expression class to handle regexpression by user --- SimpleCalculator.Tests/ExpressionTests.cs | 41 +++++++++++++++++++ .../SimpleCalculator.Tests.csproj | 1 + SimpleCalculator/Expression.cs | 33 +++++++++++++++ SimpleCalculator/Program.cs | 13 +++--- SimpleCalculator/SimpleCalculator.csproj | 1 + 5 files changed, 81 insertions(+), 8 deletions(-) create mode 100644 SimpleCalculator.Tests/ExpressionTests.cs create mode 100644 SimpleCalculator/Expression.cs 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/SimpleCalculator.Tests.csproj b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj index d4e3972..edbea46 100644 --- a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj +++ b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj @@ -57,6 +57,7 @@ + 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/Program.cs b/SimpleCalculator/Program.cs index 6737640..607c633 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -13,14 +13,11 @@ static void Main(string[] args) int counter = 0; Console.Write("[" + counter + "]"); string userMathProblem = Console.ReadLine(); - Match m = Regex.Match(userMathProblem, @"(?\w+)\s+(?[\ *xX%\/\-\+])\s+(?\w+)"); - if (m.Success) - { - string mathA = m.Groups["mathA"].Value.ToString(); - string mathOper = m.Groups["mathOper"].Value.ToString(); - string mathB = m.Groups["mathB"].Value.ToString(); - Console.WriteLine(mathA + mathOper + mathB); - } + Expression userExpression = new Expression(); + userExpression.verifyUserMathProblem(userMathProblem); + Console.WriteLine(userExpression.mathFactorA); + Console.WriteLine(userExpression.mathOperator); + Console.WriteLine(userExpression.mathFactorB); Console.ReadLine(); } } diff --git a/SimpleCalculator/SimpleCalculator.csproj b/SimpleCalculator/SimpleCalculator.csproj index bbab5a6..c553334 100644 --- a/SimpleCalculator/SimpleCalculator.csproj +++ b/SimpleCalculator/SimpleCalculator.csproj @@ -44,6 +44,7 @@ + From 5ed2df50d167706b5501d9c435e856c83dca0991 Mon Sep 17 00:00:00 2001 From: jessica kilby Date: Wed, 1 Feb 2017 19:16:17 -0600 Subject: [PATCH 7/9] division files --- SimpleCalculator.Tests/DivisionTests.cs | 2 +- SimpleCalculator.Tests/SimpleCalculator.Tests.csproj | 2 +- SimpleCalculator/Division.cs | 2 +- SimpleCalculator/SimpleCalculator.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/SimpleCalculator.Tests/DivisionTests.cs b/SimpleCalculator.Tests/DivisionTests.cs index 6231c55..73a587b 100644 --- a/SimpleCalculator.Tests/DivisionTests.cs +++ b/SimpleCalculator.Tests/DivisionTests.cs @@ -4,7 +4,7 @@ namespace SimpleCalculator.Tests { [TestClass] - public class UnitTest1 + public class DivisionTests { [TestMethod] public void TestMethod1() diff --git a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj index e0b88e6..2927704 100644 --- a/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj +++ b/SimpleCalculator.Tests/SimpleCalculator.Tests.csproj @@ -57,7 +57,7 @@ - + diff --git a/SimpleCalculator/Division.cs b/SimpleCalculator/Division.cs index fa2fbe9..2d1fabf 100644 --- a/SimpleCalculator/Division.cs +++ b/SimpleCalculator/Division.cs @@ -6,7 +6,7 @@ namespace SimpleCalculator { - class Integer + class Division { } } diff --git a/SimpleCalculator/SimpleCalculator.csproj b/SimpleCalculator/SimpleCalculator.csproj index bbab5a6..a28fa74 100644 --- a/SimpleCalculator/SimpleCalculator.csproj +++ b/SimpleCalculator/SimpleCalculator.csproj @@ -44,7 +44,7 @@ - + From 5cb0167722ac914b794ded5cef71bd1e311651ae Mon Sep 17 00:00:00 2001 From: Lee Hankins Date: Wed, 1 Feb 2017 21:02:18 -0800 Subject: [PATCH 8/9] if statemnet in projectCS --- SimpleCalculator/Program.cs | 39 ++++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/SimpleCalculator/Program.cs b/SimpleCalculator/Program.cs index 607c633..8fff58b 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -6,19 +6,52 @@ using System.Text.RegularExpressions; namespace SimpleCalculator { - class Program + public class Program { static void Main(string[] args) - { + { int counter = 0; - Console.Write("[" + counter + "]"); + + Console.Write("[" + counter + "]"): string userMathProblem = Console.ReadLine(); Expression userExpression = new Expression(); userExpression.verifyUserMathProblem(userMathProblem); + Console.WriteLine(userExpression.mathFactorA); + Console.WriteLine(userExpression.mathOperator); + + if(userExpression.mathOperator == "+") // call to method goes here instead of "+" + { + Console.WriteLine("add method"); + } + else if (userExpression.mathOperator == "-") + { + Console.WriteLine("subtract method"); + } + else if (userExpression.mathOperator == "*") + { + Console.WriteLine("multiply method"); + } + else if (userExpression.mathOperator == "/") + { + Console.WriteLine("divide method"); + } + else if (userExpression.mathOperator == "%") + { + Console.WriteLine("modulus method"); + } + else + { + Console.WriteLine("please select a valid operator"); + } + + Console.WriteLine(userExpression.mathFactorB); + Console.ReadLine(); + } + } } From e0ffaa0548a327fda00b24817be5f88fe172d63f Mon Sep 17 00:00:00 2001 From: Lee Hankins Date: Fri, 3 Feb 2017 06:15:57 -0800 Subject: [PATCH 9/9] swith statement implimented for operator selection --- SimpleCalculator/Program.cs | 61 +++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/SimpleCalculator/Program.cs b/SimpleCalculator/Program.cs index 8fff58b..f736438 100644 --- a/SimpleCalculator/Program.cs +++ b/SimpleCalculator/Program.cs @@ -4,6 +4,8 @@ using System.Text; using System.Threading.Tasks; using System.Text.RegularExpressions; + + namespace SimpleCalculator { public class Program @@ -11,46 +13,47 @@ public class Program static void Main(string[] args) { int counter = 0; - - Console.Write("[" + counter + "]"): + + 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); - if(userExpression.mathOperator == "+") // call to method goes here instead of "+" - { - Console.WriteLine("add method"); - } - else if (userExpression.mathOperator == "-") - { - Console.WriteLine("subtract method"); - } - else if (userExpression.mathOperator == "*") - { - Console.WriteLine("multiply method"); - } - else if (userExpression.mathOperator == "/") - { - Console.WriteLine("divide method"); - } - else if (userExpression.mathOperator == "%") - { - Console.WriteLine("modulus method"); - } - else + string operationUsed = userExpression.mathOperator; + string description = "Operation used: "; + + switch (operationUsed) { - Console.WriteLine("please select a valid operator"); - } + case "+": + Console.WriteLine(description + operationUsed); + break; + case "-": + Console.WriteLine(description + operationUsed); + break; - Console.WriteLine(userExpression.mathFactorB); + 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(); - + } }