Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
blegat committed Aug 12, 2017
1 parent 45bbc00 commit fa66e08
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/diff.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function differentiate(ps::AbstractArray{PT, N}, xs) where {N, PT<:ARPL}
end
qs
end
differentiate(ps::AbstractArray{<:ARPL}, v::AbstractVariable) = differentiate.(ps, v)

differentiate(p::ARPL, xs) = [differentiate(p, x) for x in xs]

# differentiate(p, [x, y]) with TypedPolynomials promote x to a Monomial
Expand Down
4 changes: 2 additions & 2 deletions src/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ function (-)(r::RationalPoly, s::RationalPoly)
end
_minus(p, s::RationalPoly) = (p * s.den - s.num) / s.den
_minus(s::RationalPoly, p) = (s.num - p * s.den) / s.den
(-)(p::APL, r::RationalPoly) = _minus(r, p)
(-)(p::APL, r::RationalPoly) = _minus(p, r)
(-)(r::RationalPoly, p::APL) = _minus(r, p)
(-)(r::RationalPoly, α) = _minus(r, α)
(-)(α, r::RationalPoly) = _minus(r, α)
(-)(α, r::RationalPoly) = _minus(α, r)
(-)(r::RationalPoly) = (-r.num) / r.den

(*)(r::RationalPoly, s::RationalPoly) = (r.num*s.num) / (r.den*s.den)
Expand Down
2 changes: 2 additions & 0 deletions test/comp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ MultivariatePolynomials.terms(p::CustomPoly) = terms(p.p)
@test 3 != 4x / 2x
@test 4x / 2x == 2
@test 3 != 4x / 2x
@test 1 - 1/x == (x - 1) / x
@test 1 - 1/x != (1 - x) / x
@test x + x/x == 1 + x^2/x
@test x - x/x == -(1 - x^2/x)
@test (1+x)/x - 1 == 1/x
Expand Down
2 changes: 2 additions & 0 deletions test/diff.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
@testset "Differentiation" begin
Mod.@polyvar x y
@test differentiate(3, y) == 0
@test differentiate([x, y], y) == [0, 1]
@test differentiate(true*x+true*x^2, y) == 0
@inferred differentiate(true*x+true*x^2, y)
@test differentiate(x*y + 3y^2 , [x, y]) == [y, x+6y]
Expand Down
4 changes: 4 additions & 0 deletions test/mono.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,9 @@
@test σ[2] in (1, 3)
@test σ[3] in (2, 5)
@test mergemonovec([[x*y, x, x*y], [x^2*y, x]]) == [x^2*y, x*y, x]
@test_throws ArgumentError monovec([1, 2], [x^2])
σ, X = sortmonovec((y, x))
@test σ == [2, 1]
@test X == [x, y]
end
end

0 comments on commit fa66e08

Please sign in to comment.