namespace Solution { public class MyCalculator { public int Add(params int[] values) { int sum = 0; foreach (int v in values) { sum += v; } return sum; } } }
- namespace Solution
- {
- public class MyCalculator
- {
public int Add(int a, int b)- public int Add(params int[] values)
- {
return a + b;- int sum = 0;
- foreach (int v in values) {
- sum += v;
- }
- return sum;
- }
- }
- }
using NUnit.Framework; using Solution; namespace Tests { [TestFixture] public class MyCalculatorTests { [TestCase(5, 7, 12)] [TestCase(-10, -5, -15)] [TestCase(-47, 93, 46)] public void Add_TwoNumbers_ReturnsSum(int a, int b, int expectedResult) { Assert.AreEqual(expectedResult, new MyCalculator().Add(a, b)); } [TestCase(5, 7, 20, 32)] [TestCase(-1, -1, -1, -3)] public void Add_ThreeNumbers_ReturnsSum(int a, int b, int c, int expectedResult) { Assert.AreEqual(expectedResult, new MyCalculator().Add(a, b, c)); } } }
- using NUnit.Framework;
- using Solution;
- namespace Tests
- {
- [TestFixture]
- public class MyCalculatorTests
- {
[Test]public void Add_TwoNumbers_ReturnsSum()- [TestCase(5, 7, 12)]
- [TestCase(-10, -5, -15)]
- [TestCase(-47, 93, 46)]
- public void Add_TwoNumbers_ReturnsSum(int a, int b, int expectedResult)
- {
// ArrangeMyCalculator calculator = new MyCalculator();int a = 5;int b = 7;int expectedResult = 12;// Actint actualResult = calculator.Add(a, b);// AssertAssert.AreEqual(expectedResult, actualResult);- Assert.AreEqual(expectedResult, new MyCalculator().Add(a, b));
- }
- [TestCase(5, 7, 20, 32)]
- [TestCase(-1, -1, -1, -3)]
- public void Add_ThreeNumbers_ReturnsSum(int a, int b, int c, int expectedResult)
- {
- Assert.AreEqual(expectedResult, new MyCalculator().Add(a, b, c));
- }
- }
- }