Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NUnit
- public class Task1Tests
- {
- Calculator _calculator;
- [SetUp]
- public void SetUp() => _calculator = new();
- [Test]
- [TestCase(2, 3, 5)]
- [TestCase(0, 0, 0)]
- [TestCase(-2, 3, 1)]
- public void AddTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Add(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [Test]
- [TestCase(2, 3, -1)]
- [TestCase(0, -1, 1)]
- [TestCase(1000, 200, 800)]
- public void SubTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Sub(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [Test]
- [TestCase(2, 3, 6)]
- [TestCase(0, 100, 0)]
- [TestCase(-2, -20, 40)]
- public void MultiplyTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Multiply(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [Test]
- [TestCase(2, 3, 0)]
- [TestCase(0, -1, 0)]
- [TestCase(1000, 200, 5)]
- public void DivideTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Sub(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- }
- XUnit
- public class Task1Tests
- {
- private Calculator _calculator = new();
- [Fact]
- public void AddTest()
- {
- Assert.Equal(5, _calculator.Add(2, 3));
- Assert.Equal(0, _calculator.Add(0, 0));
- Assert.Equal(1, _calculator.Add(-2, 3));
- }
- [Fact]
- public void SubTest()
- {
- Assert.Equal(-1, _calculator.Sub(2, 3));
- Assert.Equal(1, _calculator.Sub(0, -1));
- Assert.Equal(800, _calculator.Sub(1000, 200));
- }
- [Fact]
- public void MultiplyTest()
- {
- Assert.Equal(6, _calculator.Multiply(2, 3));
- Assert.Equal(0, _calculator.Multiply(0, 100));
- Assert.Equal(40, _calculator.Multiply(-2, -20));
- }
- [Fact]
- public void DivideTest()
- {
- Assert.Equal(0, _calculator.Divide(2, 3));
- Assert.Equal(0, _calculator.Divide(0, -1));
- Assert.Equal(5, _calculator.Divide(1000, 200));
- }
- }
- MSUnit
- [TestClass]
- public class Task1Tests
- {
- Calculator _calculator;
- [TestInitialize]
- public void TestInitialize() => _calculator = new();
- [TestMethod]
- [DataRow(2, 3, 5)]
- [DataRow(0, 0, 0)]
- [DataRow(-2, 3, 1)]
- public void AddTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Add(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [TestMethod]
- [DataRow(2, 3, -1)]
- [DataRow(0, -1, 1)]
- [DataRow(1000, 200, 800)]
- public void SubTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Sub(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [TestMethod]
- [DataRow(2, 3, 6)]
- [DataRow(0, 100, 0)]
- [DataRow(-2, -20, 40)]
- public void MultiplyTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Multiply(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- [TestMethod]
- [DataRow(2, 3, 0)]
- [DataRow(0, -1, 0)]
- [DataRow(1000, 200, 5)]
- public void DivideTest(int num1, int num2, int expectedValue)
- {
- var result = _calculator.Divide(num1, num2);
- Assert.AreEqual(expectedValue, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement