From d51f315a8da246c3852017b4a1c127a29a43811f Mon Sep 17 00:00:00 2001 From: uzvkl Date: Mon, 20 May 2019 03:00:44 +0200 Subject: Begin Testing --- .../Auxiliary/Calculator/StringSolverTests.cs | 105 +++++++++++++++++++++ NUnitTestProject1/Auxiliary/DiceTests.cs | 71 ++++++++++++++ 2 files changed, 176 insertions(+) create mode 100644 NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs create mode 100644 NUnitTestProject1/Auxiliary/DiceTests.cs (limited to 'NUnitTestProject1/Auxiliary') diff --git a/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs b/NUnitTestProject1/Auxiliary/Calculator/StringSolverTests.cs new file mode 100644 index 0000000..998a78b --- /dev/null +++ b/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(() =>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(() => 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); + } + } +} diff --git a/NUnitTestProject1/Auxiliary/DiceTests.cs b/NUnitTestProject1/Auxiliary/DiceTests.cs new file mode 100644 index 0000000..6b37492 --- /dev/null +++ b/NUnitTestProject1/Auxiliary/DiceTests.cs @@ -0,0 +1,71 @@ +using DSALib.Auxiliary; +using Moq; +using NUnit.Framework; +using System; + +namespace NUnitTest.Auxiliary +{ + [TestFixture] + public class DiceTests + { + private MockRepository mockRepository; + + + + [SetUp] + public void SetUp() + { + this.mockRepository = new MockRepository(MockBehavior.Strict); + + + } + + [TearDown] + public void TearDown() + { + this.mockRepository.VerifyAll(); + } + + private void CreateDice() + {} + + [Test] + public void Roll_StateUnderTest_ExpectedBehavior() + { + // Arrange + int d = 20; + + // Act + var result = Dice.Roll(d); + + // Assert + Assert.True(result > 0 && result < d+1); + } + + [Test] + public void Roll_StateUnderTest_ExpectedBehavior1() + { + // Arrange + string input = "w"; + + // Act + Assert.Throws( () => Dice.Roll(input)); + } + + [Test] + public void Roll_zero_dice() + { + // Arrange + int count = 0; + int d = 2; + + // Act + var result = Dice.Roll( + count, + d); + + // Assert + Assert.AreEqual(0, result); + } + } +} -- cgit v1.2.3-54-g00ecf