Skip to content

Commit c7bec44

Browse files
committed
Add tests
1 parent bdf5351 commit c7bec44

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/substitution.jl

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ is equivalent to:
2424
2525
subs(polynomial, (x=>1, y=>2))
2626
"""
27-
substitute(st::AST, p::APL, s::MultiSubstitution) = substitute(st, p, pairzip(s))
28-
29-
# inefficient but convenient method to allow subs(p, (x, y)=>[1, 2])
30-
substitute(st::AST, p::APL, s::MultiVectorSubstitution) = substitute(st, p, s.first => Tuple(s.second))
31-
substitute(st::AST, p::APL, s::VectorMultiSubstitution) = substitute(st, p, Tuple(s.first) => s.second)
32-
substitute(st::AST, p::APL, s::VectorMultiVectorSubstitution) = substitute(st, p, Tuple(s.first) => Tuple(s.second))
33-
27+
substitute(st::AST, p::APL, s::AbstractMultiSubstitution) = substitute(st, p, pairzip(s))
3428

3529
# Evaluate the stream
3630
# If I do s2..., then

src/zip.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ pairzip(::Tuple{}, ::Tuple) = throw(ArgumentError("args must be equal in length"
99
pairzip(::Tuple, ::Tuple{}) = throw(ArgumentError("args must be equal in length"))
1010
pairzip(t::Tuple, u::Tuple) = (t[1] => u[1], pairzip(Base.tail(t), Base.tail(u))...)
1111
pairzip(p::Pair{<:Tuple, <:Tuple}) = pairzip(p.first, p.second)
12+
# inefficient but convenient method to allow subs(p, (x, y)=>[1, 2])
13+
pairzip(p::Pair) = pairzip(Tuple(p.first), Tuple(p.second))
1214

1315
tuplezip(::Tuple{}, ::Tuple{}) = ()
1416
tuplezip(::Tuple{}, ::Tuple) = throw(ArgumentError("args must be equal in length"))

test/subs.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import Base.Test: @inferred
33
@testset "Substitution" begin
44
Mod.@polyvar x[1:3]
55

6+
@test subs(2, x[1]=>3) == 2
7+
@test iszero((x[1]-x[1])(x[1]=>x[2]))
8+
@test subs(CustomPoly(x[1]+x[2]), x[2]=>x[1]) == 2x[1]
9+
610
a = (x[1])(x[1]=>x[2])
711
b = x[2]
812
@test (x[1])(x[1]=>x[2]) == x[2]

0 commit comments

Comments
 (0)