/
Tomatto
/
CourseWork
Обзор
Документация
Войти
/
Tomatto
/
CourseWork
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
branch_1
CourseWorkTest/UnitTest1.cs
93 строки
2 KB
Татьяна
initial commit of Coursework
10 дек 2025, 23:51
10 дек 2025, 23:51
6f22a2c
Код
Авторство
О чём код?
using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using CourseWorkLibrary; namespace CourseWorkTest { [TestClass] public class MathOperationsTests { private MathOperations math; [TestInitialize] public void Setup() { math = new MathOperations(); } [TestMethod] public void Add_TwoNumbers_ReturnsSum() { int result = math.Add(5, 3); Assert.AreEqual(8, result); } [TestMethod] public void Subtract_TwoNumbers_ReturnsDifference() { int result = math.Subtract(5, 3); Assert.AreEqual(2, result); } [TestMethod] public void Multiply_TwoNumbers_ReturnsProduct() { int result = math.Multiply(5, 3); Assert.AreEqual(15, result); } [TestMethod] public void Divide_TwoNumbers_ReturnsQuotient() { double result = math.Divide(6, 3); Assert.AreEqual(2.0, result); } [TestMethod] [ExpectedException(typeof(DivideByZeroException))] public void Divide_ByZero_ThrowsException() { math.Divide(5, 0); } } [TestClass] public class StringOperationsTests { private StringOperations strOps; [TestInitialize] public void Setup() { strOps = new StringOperations(); } [TestMethod] public void Concatenate_TwoStrings_ReturnsConcatenated() { string result = strOps.Concatenate("Hello, ", "World!"); Assert.AreEqual("Hello, World!", result); } [TestMethod] public void IsNullOrEmpty_NullString_ReturnsTrue() { bool result = strOps.IsNullOrEmpty(null); Assert.IsTrue(result); } [TestMethod] public void IsNullOrEmpty_EmptyString_ReturnsTrue() { bool result = strOps.IsNullOrEmpty(""); Assert.IsTrue(result); } [TestMethod] public void IsNullOrEmpty_ValidString_ReturnsFalse() { bool result = strOps.IsNullOrEmpty("Hello"); Assert.IsFalse(result); } } }