summaryrefslogtreecommitdiff
path: root/dsa/NUnitTestProject1/Auxiliary/Calculator
diff options
context:
space:
mode:
Diffstat (limited to 'dsa/NUnitTestProject1/Auxiliary/Calculator')
-rw-r--r--dsa/NUnitTestProject1/Auxiliary/Calculator/ArgumentTests.cs59
-rw-r--r--dsa/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs105
2 files changed, 164 insertions, 0 deletions
diff --git a/dsa/NUnitTestProject1/Auxiliary/Calculator/ArgumentTests.cs b/dsa/NUnitTestProject1/Auxiliary/Calculator/ArgumentTests.cs
new file mode 100644
index 0000000..3e8dbeb
--- /dev/null
+++ b/dsa/NUnitTestProject1/Auxiliary/Calculator/ArgumentTests.cs
@@ -0,0 +1,59 @@
+using DSALib.Auxiliary.Calculator;
+using Moq;
+using NUnit.Framework;
+
+namespace NUnitTest.Auxiliary.Calculator
+{
+ [TestFixture]
+ public class ArgumentTests
+ {
+ private MockRepository mockRepository;
+
+
+
+ [SetUp]
+ public void SetUp()
+ {
+ this.mockRepository = new MockRepository(MockBehavior.Strict);
+
+
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ this.mockRepository.VerifyAll();
+ }
+
+ private Argument CreateArgument()
+ {
+ return new Argument("3");
+ }
+
+ [Test]
+ public void Solve_StateUnderTest_ExpectedBehavior()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateArgument();
+
+ // Act
+ var result = unitUnderTest.Solve();
+
+ // Assert
+ Assert.AreEqual(3, result);
+ }
+
+ [Test]
+ public void ToString_StateUnderTest_ExpectedBehavior()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateArgument();
+
+ // Act
+ var result = unitUnderTest.ToString();
+
+ // Assert
+ Assert.AreEqual("3", result);
+ }
+ }
+}
diff --git a/dsa/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs b/dsa/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs
new file mode 100644
index 0000000..998a78b
--- /dev/null
+++ b/dsa/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs
@@ -0,0 +1,105 @@
+using DSALib.Auxiliary.Calculator;
+using Moq;
+using NUnit.Framework;
+
+namespace NUnitTest.Auxiliary.Calculator
+{
+ [TestFixture]
+ public class StringSolverTests
+ {
+ private MockRepository mockRepository;
+
+
+
+ [SetUp]
+ public void SetUp()
+ {
+ this.mockRepository = new MockRepository(MockBehavior.Strict);
+
+
+ }
+
+ [TearDown]
+ public void TearDown()
+ {
+ this.mockRepository.VerifyAll();
+ }
+
+ private StringSolver CreateStringSolver(string input)
+ {
+ return new StringSolver(input);
+ }
+
+ [Test]
+ public void Solve_StateUnderTest_ExpectedBehavior()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("1+1");
+
+ // Act
+ var result = unitUnderTest.Solve();
+
+ // Assert
+ Assert.AreEqual(2,result);
+ }
+
+ [Test]
+ public void Solve_mult()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("1+1-4*6+2");
+
+ // Act
+ var result = unitUnderTest.Solve();
+
+ // Assert
+ Assert.AreEqual(-20, result);
+ }
+
+ [Test]
+ public void Solve_braces()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("1+(1-4)*6+2");
+
+ // Act
+ var result = unitUnderTest.Solve();
+
+ // Assert
+ Assert.AreEqual(-15, result);
+ }
+
+ [Test]
+ public void Solve_wrong_braces()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("1+)(1-4)*6+2");
+
+ // Act
+ Assert.Throws<System.ArgumentException>(() =>unitUnderTest.Solve(), "Invalid brace sequence");
+ }
+
+ [Test, MaxTime(200)]
+ public void Solve_braces_timeout()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("1+(1-(4)*6+2");
+
+ // Act
+ Assert.Throws<System.ArgumentException>(() => unitUnderTest.Solve(), "Invalid brace sequence");
+ }
+
+ [Test]
+ public void ToString_StateUnderTest_ExpectedBehavior()
+ {
+ // Arrange
+ var unitUnderTest = this.CreateStringSolver("3+-4");
+
+ // Act
+ var result = unitUnderTest.ToString();
+
+ // Assert
+ Assert.AreEqual("(0+3+-4)", result);
+ }
+ }
+}