Browse files

adding string calculator tests

  • Loading branch information...
1 parent a59833f commit ae5bcbcbdedcc4d55c73d16ca2805db3b88a97d9 @josephbulger committed Oct 22, 2011
View
2 dotnet-questions/c-sharp-version/StringCalculator/Calculator.cs
@@ -1,4 +1,6 @@
using System;
+using System.Diagnostics;
+using System.Linq;
namespace c_sharp_version.StringCalculator
{
View
39 dotnet-questions/c-sharp-version/StringCalculator/Problem.cs
@@ -1,4 +1,5 @@
-using NUnit.Framework;
+using System;
+using NUnit.Framework;
namespace c_sharp_version.StringCalculator
{
@@ -8,37 +9,53 @@ public class Problem
[Test]
public void Add_WhenGivenNoNumbers_ReturnsZero()
{
-
+ var result = Calculator.Add("");
+
+ Assert.That(result, Is.EqualTo(0));
}
+ [TestCase("1")]
+ [TestCase("2")]
+ [TestCase("3")]
+ [TestCase("10")]
[Test]
- public void Add_WhenGivenOneNumber_ReturnsThatNumber()
+ public void Add_WhenGivenOneNumber_ReturnsThatNumber(string value)
{
-
+ var result = Calculator.Add(value);
+ Assert.That(result, Is.EqualTo(Convert.ToInt32(value)));
}
+ [TestCase("6,7", 13)]
+ [TestCase("3,5", 8)]
[Test]
- public void Add_WhenGivenTwoNumbers_AddNumbersTogether()
+ public void Add_WhenGivenTwoNumbers_AddNumbersTogether(string twoNumbers, int expected)
{
-
+ var result = Calculator.Add(twoNumbers);
+ Assert.That(result, Is.EqualTo(expected));
}
+ [TestCase("1\n2", 3)]
+ [TestCase("3\n7", 10)]
[Test]
- public void Add_WhenGivenNewLinesBetweenNumbers_TreatsNewLineAsDelimiter()
+ public void Add_WhenGivenNewLinesBetweenNumbers_TreatsNewLineAsDelimiter(string value, int expected)
{
-
+ var result = Calculator.Add(value);
+ Assert.That(result, Is.EqualTo(expected));
}
+ [TestCase("\\:\n1:3", 4)]
+ [TestCase("\\-\n7-7", 14)]
[Test]
- public void Add_WhenGivenTwoSlashesAtBeginning_UsesDelimiterAfterSlashesInsteadOfComma()
+ public void Add_WhenGivenTwoSlashesAtBeginning_UsesDelimiterAfterSlashesInsteadOfComma(string value, int expected)
{
-
+ var result = Calculator.Add(value);
+ Assert.That(result, Is.EqualTo(expected));
}
[Test]
public void Add_WhenGivenNegativeNumbers_ThrowsExceptionSayingNegativesArentAllowed()
{
-
+ Assert.Throws<ArgumentException>(() => Calculator.Add("-1"));
}
}
}

0 comments on commit ae5bcbc

Please sign in to comment.