Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

напиши модульный тест на c# для программы: using System; using…

  1. User

    напиши модульный тест на c# для программы: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MyCalc { public class MyCalcLib { static double Otr(double x1, double y1, double x2, double y2) { return Math.Sqrt(Math.Pow(x2 - x1, 2) + Math.Pow(y2 - y1, 2)); } static double Perim(double Ax, double Ay, double Bx, double By, double Cx, double Cy) { double AB = Otr(Ax, Ay, Bx, By); double BC = Otr(Bx, By, Cx, Cy); double CA = Otr(Cx, Cy, Ax, Ay);

            return AB + BC + CA;
        }
        static void Main()
        {
            double Ax = 0, Ay = 0;
            double Bx = 3, By = 0;
            double Cx = 0, Cy = 4;
            double Dx = 4, Dy = 2;
            double Perim_ABC = Perim(Ax, Ay, Bx, By, Cx, Cy);
            double Perim_ABD = Perim(Ax, Ay, Bx, By, Dx, Dy);
            double Perim_ACD = Perim(Ax, Ay, Cx, Cy, Dx, Dy);
        }
    }
    

    }

  2. Assistant

    Вот пример модульного теста на C# для этой программы:

    using Microsoft.VisualStudio.TestTools.UnitTesting;
    using MyCalc;
    
    [TestClass]
    public class MyCalcLibTests
    {
        [TestMethod]
        public void Otr_ShouldReturnCorrectValue()
        {
            // Arrange
            double x1 = 0, y1 = 0;
            double x2 = 3, y2 = 4;
            double expected = 5;
    
            // Act
            double result = MyCalcLib.Otr(x1, y1, x2, y2);
    
            // Assert
            Assert.AreEqual(expected, result);
        }
    
        [TestMethod]
        public void Perim_ShouldReturnCorrectValue()
        {
            // Arrange
            double Ax = 0, Ay = 0;
            double Bx = 3, By = 0;
            double Cx = 0, Cy = 4;
            double expected = 12;
    
            // Act
            double result = MyCalcLib.Perim(Ax, Ay, Bx, By, Cx, Cy);
    
            // Assert
            Assert.AreEqual(expected, result);
        }
    }
    

    Данный тест будет проверять, что методы Otr и Perim возвращают правильные значения.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.