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 bdf5351 commit c7bec44
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 1 addition & 7 deletions src/substitution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,7 @@ is equivalent to:
subs(polynomial, (x=>1, y=>2))
"""
substitute(st::AST, p::APL, s::MultiSubstitution) = substitute(st, p, pairzip(s))

# inefficient but convenient method to allow subs(p, (x, y)=>[1, 2])
substitute(st::AST, p::APL, s::MultiVectorSubstitution) = substitute(st, p, s.first => Tuple(s.second))
substitute(st::AST, p::APL, s::VectorMultiSubstitution) = substitute(st, p, Tuple(s.first) => s.second)
substitute(st::AST, p::APL, s::VectorMultiVectorSubstitution) = substitute(st, p, Tuple(s.first) => Tuple(s.second))

substitute(st::AST, p::APL, s::AbstractMultiSubstitution) = substitute(st, p, pairzip(s))

# Evaluate the stream
# If I do s2..., then
Expand Down
2 changes: 2 additions & 0 deletions src/zip.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ pairzip(::Tuple{}, ::Tuple) = throw(ArgumentError("args must be equal in length"
pairzip(::Tuple, ::Tuple{}) = throw(ArgumentError("args must be equal in length"))
pairzip(t::Tuple, u::Tuple) = (t[1] => u[1], pairzip(Base.tail(t), Base.tail(u))...)
pairzip(p::Pair{<:Tuple, <:Tuple}) = pairzip(p.first, p.second)
# inefficient but convenient method to allow subs(p, (x, y)=>[1, 2])
pairzip(p::Pair) = pairzip(Tuple(p.first), Tuple(p.second))

tuplezip(::Tuple{}, ::Tuple{}) = ()
tuplezip(::Tuple{}, ::Tuple) = throw(ArgumentError("args must be equal in length"))
Expand Down
4 changes: 4 additions & 0 deletions test/subs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import Base.Test: @inferred
@testset "Substitution" begin
Mod.@polyvar x[1:3]

@test subs(2, x[1]=>3) == 2
@test iszero((x[1]-x[1])(x[1]=>x[2]))
@test subs(CustomPoly(x[1]+x[2]), x[2]=>x[1]) == 2x[1]

a = (x[1])(x[1]=>x[2])
b = x[2]
@test (x[1])(x[1]=>x[2]) == x[2]
Expand Down

0 comments on commit c7bec44

Please sign in to comment.