using Azimuth.Polynomials; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using UnitTestSharp; namespace Azimuth.UnitTests.Polynomials { public class ComplexRationalTests : TestFixture { public void EmbeddedReal() { var coefficients = new ComplexDenseVector(new Complex[] { 5, -6, 1, 1, 1 }); var rational = new ComplexRational(coefficients, numeratorTerms: 3); CheckEqual(0, rational.Evaluate(1)); CheckEqual(-1, rational.Evaluate(2)); CheckEqual(-1, rational.Evaluate(3)); CheckEqual(-3.0/5, rational.Evaluate(4)); } public void FullyComplexEquation() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), (7, -8), (-9, 10), }); var rational = new ComplexRational(coefficients, numeratorTerms: 3); CheckEqual((13.0/4, -9.0/4), rational.Evaluate(1)); CheckEqual((391.0 / 265, -248.0/265), rational.Evaluate(2)); CheckEqual((665.0 / 442, -242.0/221), rational.Evaluate(3)); CheckEqual((3089.0 / 1865, -2508.0/1865), rational.Evaluate(4)); CheckEqual((119.0/298, 21.0/298), rational.Evaluate((0, 1))); CheckEqual((61.0/65, 18.0/65), rational.Evaluate((0, 2))); CheckEqual((2341.0/1754, 937.0/1754), rational.Evaluate((0, 3))); CheckEqual((463.0 / 275, 216.0/275), rational.Evaluate((0, 4))); } public void EvaluateAtZero() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), (7, -8), (-9, 10), }); var rational = new ComplexRational(coefficients, numeratorTerms: 3); CheckEqual((-11.0/113, 52.0/113), rational.EvaluateAtZero()); } public void EvaluateAtOne() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), (7, -8), (-9, 10), }); var rational = new ComplexRational(coefficients, numeratorTerms: 3); CheckEqual((13.0/4, -9.0/4), rational.EvaluateAtOne()); } public void ZeroNumeratorTerms() { var coefficients = new ComplexDenseVector(new Complex[] { (7, -8), (-9, 10), }); var rational = new ComplexRational(coefficients, numeratorTerms: 0); CheckEqual(0, rational.Evaluate(1)); } public void ZeroDenominatorTerms() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), }); CheckThrow(typeof(ArgumentException)); new ComplexRational(coefficients, numeratorTerms: 3); } public void NegativeNumeratorTerms() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), }); CheckThrow(typeof(ArgumentException)); new ComplexRational(coefficients, numeratorTerms: -1); } public void TooManyNumeratorTerms() { var coefficients = new ComplexDenseVector(new Complex[] { (3, 4), (-6, 2), (1, 5), }); CheckThrow(typeof(ArgumentException)); new ComplexRational(coefficients, numeratorTerms: 4); } } }