using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Azimuth.Polynomials; namespace Azimuth.UnitTests.Polynomials { public class RationalTests : UnitTestSharp.TestFixture { public void Basic() { var coefficients = new DenseVector(new Scalar[] { 5, -6, 1, 1, 1 }); var rational = new Rational(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 EvaluateAtZero() { var coefficients = new DenseVector(new Scalar[] { 5, -6, 7, 8, 9, }); var rational = new Rational(coefficients, numeratorTerms: 3); CheckEqual(5.0/8.0, rational.EvaluateAtZero()); } public void EvaluateAtOne() { var coefficients = new DenseVector(new Scalar[] { 5, -6, 7, 8, 9, }); var rational = new Rational(coefficients, numeratorTerms: 3); CheckEqual(6.0/17.0, rational.EvaluateAtOne()); } public void ZeroNumeratorTerms() { var coefficients = new DenseVector(new Scalar[] { 1, 1 }); var rational = new Rational(coefficients, numeratorTerms: 0); CheckEqual(0, rational.Evaluate(1)); } public void ZeroDenominatorTerms() { var coefficients = new DenseVector(new Scalar[] { 1, 1 }); CheckThrow(typeof(ArgumentException)); new Rational(coefficients, numeratorTerms: 2); } public void NegativeNumeratorTerms() { var coefficients = new DenseVector(new Scalar[] { 1, 1 }); CheckThrow(typeof(ArgumentException)); new Rational(coefficients, numeratorTerms: -1); } public void TooManyNumeratorTerms() { var coefficients = new DenseVector(new Scalar[] { 1, 1 }); CheckThrow(typeof(ArgumentException)); new Rational(coefficients, numeratorTerms: 3); } } }