Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Jul 13, 2024
1 parent bdc60b0 commit b79c723
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/trigonometric.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ Univariate trigonometric basis is
a0 + a1 cos(ωt) + a2 sin(ωt) + a3 cos(2ωt) + a4 sin(2ωt)
```
"""
struct Trigonometric <: AbstractMonomialIndexed end
struct Trigonometric <: AbstractMultipleOrthogonal end

_cos_id(d) = iszero(d) ? 0 : 2d - 1
_sin_id(d) = 2d
_is_cos(d) = isodd(d)
_is_sin(d) = isodd(d)
_is_sin(d) = d > 0 && iseven(d)
_id(d) = div(d + 1, 2)

# https://en.wikipedia.org/wiki/Chebyshev_polynomials#Properties
Expand Down Expand Up @@ -95,3 +95,6 @@ end
function _promote_coef(::Type{T}, ::Type{Trigonometric}) where {T}
return _promote_div(T)
end

# FIXME The cos part is, like Chebysev, maybe the sin part too ? We should do better here, this is just a stopgap
even_odd_separated(::Type{Trigonometric}) = false
15 changes: 15 additions & 0 deletions test/trigonometric.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using Test
using MultivariateBases
using DynamicPolynomials

@testset "StarAlgebras" begin
@polyvar x
a = MB.Polynomial{MB.Trigonometric}(x)
b = a * a
@test b.coeffs == MB.sparse_coefficients(1 // 2 + 1 // 2 * x^3)
c = b * b
@test c.coeffs ==
MB.sparse_coefficients(3 // 8 + 1 // 2 * x^3 + 1 // 8 * x^7)
@test a * MB.Polynomial{MB.Trigonometric}(constant_monomial(typeof(x))) ==
a * MB.Polynomial{MB.Trigonometric}(x^0)
end

0 comments on commit b79c723

Please sign in to comment.