public void AddNumber_Three() { Calculator c = new Calculator(); int result = c.Add("0,1\n2"); Assert.AreEqual(3, result); result = c.Add("1,2\n3"); Assert.AreEqual(6, result); }
public void AddNumbers_One() { Calculator c = new Calculator(); for (int i = 0; i < 3; i++) { int result = c.Add(i.ToString()); Assert.AreEqual(i, result); } }
public void AddNumber_Two() { Calculator c = new Calculator(); int result = c.Add("0,1"); Assert.AreEqual(1, result); result = c.Add("0,2"); Assert.AreEqual(2, result); result = c.Add("1,2"); Assert.AreEqual(3, result); }
public void AddNumber_Random() { var num = new Random().Next(0, 100); List<int> nums = new List<int>(); StringBuilder input = new StringBuilder(); Random r = new Random(); for (int i = 0; i < num; i++) { int nextNum = r.Next(0, num); nums.Add(nextNum); input.Append(nextNum + ","); } var expectedResult = nums.Sum(); Calculator c = new Calculator(); int result = c.Add(input.ToString()); Assert.AreEqual(expectedResult, result); }
public void AddNumber_DelimTest() { Calculator c = new Calculator(); int result = c.Add("//;\n0;1;2"); Assert.AreEqual(3, result); result= c.Add("//:\n3:1:2:7:9:10"); Assert.AreEqual(32, result); }
public void AddNumber_Multiple_MultiSep() { Calculator c = new Calculator(); int result = c.Add("//[***][xx][%]\n2xx1***3xx4xx6%3"); Assert.AreEqual(19, result); }
public void AddNumbers_Empty() { Calculator c = new Calculator(); int result = c.Add(""); Assert.AreEqual(0, result); }
public void AddNumber_MultiSep() { Calculator c = new Calculator(); int result = c.Add("//[***]\n2***1***3"); Assert.AreEqual(6, result); }
public void AddNumber_Two_Big() { Calculator c = new Calculator(); int result = c.Add("1000,1"); Assert.AreEqual(1001, result); result = c.Add("1001,1"); Assert.AreEqual(1, result); }
public void AddNumber_NegativeNumber() { Calculator c = new Calculator(); try { c.Add("0,-1,-2"); } catch (Exception e) { string message = e.Message; Assert.IsTrue(message.Contains("negatives not allowed")); Assert.IsTrue(message.Contains("-1")); return; } Assert.Fail("Negative numbers are not detected"); }