public void FunctionalTest() { //Creating a loop (for) to generate more situations //Создадим цикл, чтобы сгенерировать больше ситуаций for (int i = 0; i < 100; i++) { var rnd = new Random(); //Initialize random value for coefficients of double variable type //Инициализируем случайные значения типа Double для переменных (коэффициентов) var a = rnd.NextDouble() * 100; var b = rnd.NextDouble() * 100; var c = rnd.NextDouble() * 100; //Solving the equation with random coefficients //Решаем уравнение со случайными коэффициентами var result = QuadraticEquationSolver.Solve(a, b, c); //Checking the quadratic equation solver, which should be zero //Подставляем корни в квадратичное уравнение, которое должно быть равно 0 foreach (var x in result) { Assert.AreEqual(0, a * x * x + b * x + c, 1e-10); //Take into account a certain interval //Учитываем не строгое равенство, а близость на таком промежутке 1е-10 } } }
public void PositiveTestRealStrategy() { var strategy = new RealDiscriminantStrategy(); var solver = new QuadraticEquationSolver(strategy); var results = solver.Solve(1, 10, 16); Assert.That(results.Item1, Is.EqualTo(new Complex(-2, 0))); Assert.That(results.Item2, Is.EqualTo(new Complex(-8, 0))); }
public void NegativeTestOrdinaryStrategy() { var strategy = new OrdinaryDiscriminantStrategy(); var solver = new QuadraticEquationSolver(strategy); var results = solver.Solve(1, 4, 5); Assert.That(results.Item1, Is.EqualTo(new Complex(-2, 1))); Assert.That(results.Item2, Is.EqualTo(new Complex(-2, -1))); }
void Test(double a, double b, double c, params double[] expectedResult) { var result = QuadraticEquationSolver.Solve(a, b, c); Assert.AreEqual(expectedResult.Length, result.Length); for (int i = 0; i < result.Length; i++) { Assert.AreEqual(expectedResult[i], result[i]); } }
public void TwoRoots() { // arrange var(rootX1, rootX2) = (3.0, -1.0); // act var(x1, x2) = QuadraticEquationSolver.Solve(1.0, -2.0, -3.0); // assert Assert.AreEqual(rootX1, x1); Assert.AreEqual(rootX2, x2); }
public void NoRoots() { // arrange var(rootX1, rootX2) = (double.NaN, double.NaN); // act var(x1, x2) = QuadraticEquationSolver.Solve(5.0, 2.0, 3.0); // assert //result roots are same x1 == x2 Assert.AreEqual(double.IsNaN(rootX1), double.IsNaN(x1)); Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2)); }
//result roots are same x1 == x2 public void OneRoot() { // arrange var(rootX1, rootX2) = (-6.0, -6.0); // act var(x1, x2) = QuadraticEquationSolver.Solve(1.0, 12.0, 36.0); // assert //result roots are same x1 == x2 Assert.AreEqual(rootX1, x1); Assert.AreEqual(rootX2, x2); }
public void FirstCoefficientIsZeroSecondIsNegative() { // arrange var(rootX1, rootX2) = (double.PositiveInfinity, double.NaN); // act var(x1, x2) = QuadraticEquationSolver.Solve(0.0, -2.0, 3.0); // assert //result roots are same x1 == x2 Assert.AreEqual(double.IsInfinity(rootX1), double.IsInfinity(x1)); Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2)); }
static void Main(string[] args) { var a = double.Parse(Console.ReadLine()); var b = double.Parse(Console.ReadLine()); var c = double.Parse(Console.ReadLine()); var result = QuadraticEquationSolver.Solve(a, b, c); foreach (var response in result) { Console.WriteLine(response); } }
public void AllCoefficientsAreZero() { // arrange var(rootX1, rootX2) = (double.NaN, double.NaN); // act var(x1, x2) = QuadraticEquationSolver.Solve(0.0, 0.0, 0.0); // assert //result roots are same x1 == x2 Assert.AreEqual(double.IsNaN(rootX1), double.IsNaN(x1)); Assert.AreEqual(double.IsNaN(rootX2), double.IsNaN(x2)); }
public void Run() { //DynamicStrategyDemo(); //var tp = new TextProcessorStatic<HtmlListStrategy>(); //tp.AppendList(new[] { "foo", "bar", "baz" }); //Console.WriteLine(tp); var solver = new QuadraticEquationSolver(new RealDiscriminantStrategy()); var solution = solver.Solve(1, 4, 5); var solution2 = solver.Solve(1, 10, 16); }
public void FunctionalTest() { for (int i = 0; i < 100; i++) { var rnd = new Random(); var a = rnd.NextDouble() * 10; var b = rnd.NextDouble() * 10; var c = rnd.NextDouble() * 10; var result = QuadraticEquationSolver.Solve(a, b, c); foreach (var x in result) { Assert.AreEqual(0, a * x * x + b * x + c, 1e-10); } } }
public void NegativeTestRealStrategy() { var strategy = new RealDiscriminantStrategy(); var solver = new QuadraticEquationSolver(strategy); var results = solver.Solve(1, 4, 5); var complexNaN = new Complex(double.NaN, double.NaN); Assert.That(results.Item1, Is.EqualTo(complexNaN)); Assert.That(results.Item2, Is.EqualTo(complexNaN)); Assert.IsTrue(double.IsNaN(results.Item1.Real)); Assert.IsTrue(double.IsNaN(results.Item1.Imaginary)); Assert.IsTrue(double.IsNaN(results.Item2.Real)); Assert.IsTrue(double.IsNaN(results.Item2.Imaginary)); }
//coefficients A and B is Zero //коэффициенты А и В равны нулю //Unit test. Accepts coefficient values(A, B, C) and an array of quadratic equation solver //Модульное тестирование. Принимает значения коэффициентов(A, B, C) и массив из корней public static void TestEquation(double a, double b, double c, params double[] expectedResult) { var result = QuadraticEquationSolver.Solve(a, b, c); //Compare the expected number of solutions with the equations to the actual //Сравниваем ожидаемое количество решений уравнения и действительное Assert.AreEqual(expectedResult.Length, result.Length); //Compare the expected correct decisions to the actual //Сравниваем ожидаемые правильные решения и действительное for (int index = 0; index < result.Length; index++) { Assert.AreEqual(expectedResult[index], result[index]); } }
public void FunctionalTest() { var rnd = new Random(); for (int i = 0; i < 100; i++) { var a = rnd.NextDouble() * 10; var b = rnd.NextDouble() * 10; var c = rnd.NextDouble() * 10; var result = QuadraticEquationSolver.Solve(a, b, c); for (int j = 0; j < result.Length; j++) { Assert.AreEqual(0, a * result[j] * result[j] + b * result[j] + c, 10e-6); } } }
static void Main(string[] args) { //Accept values of user coefficients //Принимаем значения коэффициентов пользователя var a = double.Parse(Console.ReadLine()); var b = double.Parse(Console.ReadLine()); var c = double.Parse(Console.ReadLine()); //Quadratic Equation Solver //Решение квадратного уравнения var result = QuadraticEquationSolver.Solve(a, b, c); //Showing the solution on the console //Выводим решение на консоль for (int i = 0; i < result.Length; i++) { Console.WriteLine(result[i]); } }
static void Main() { //Quadratic Expression solver //Asuming that the user inputs the correct Values... while (true) { Console.Write("Enter the the values of the quadratic equation\n"); Console.Write("a : "); string a = Console.ReadLine(); Console.Write("b : "); string b = Console.ReadLine(); Console.Write("c : "); string c = Console.ReadLine(); double temp = 0.0; if (Double.TryParse(a, out temp) && Double.TryParse(b, out temp) && Double.TryParse(c, out temp)) { double na, nb, nc; na = Double.Parse(a); nb = Double.Parse(b); nc = Double.Parse(c); double ans1 = QuadraticEquationSolver.positiveX(na, nb, nc); double ans2 = QuadraticEquationSolver.negativeX(na, nb, nc); Console.Write("x = {0:f4} or x = {1:f4}\n", ans1, ans2); break; } else { Console.WriteLine("Enter Correct Values...\n"); } } }
static public void Main(string[] args) { Console.WriteLine("Автор программы:\nПакало Александр Сергеевич РТ5-31Б"); int a, b, c; // Коэффициенты уравнения. Console.WriteLine("Введите коэффициенты уравнений вида ax^2 + bx + c, ax^4 + bx^2 + c."); a = InitCoef(args[0], "a"); b = InitCoef(args[1], "b"); c = InitCoef(args[2], "c"); Console.WriteLine("Корни квадратного уравнения:"); QuadraticEquationSolver quadEq = new QuadraticEquationSolver(); RootsResult quadRoots = quadEq.CalculateRoots(a, b, c); quadEq.OutputRoots(quadRoots); Console.WriteLine("Корни биквадратного уравнения:"); BiquadraticEquationSolver biquadEq = new BiquadraticEquationSolver(); RootsResult biquadRoots = biquadEq.CalculateRoots(a, b, c); biquadEq.OutputRoots(biquadRoots); }
private static void Main(string[] args) { var quadraticEquationSolver = new QuadraticEquationSolver(); var solutions = quadraticEquationSolver.Solve(1, -4, 1); }
public IQuadraticEquationSolution FindSolutionsInRealNumbers(Delta delta) { return(QuadraticEquationSolver.Solve(this, delta)); }