Skip to content

Commit

Permalink
test for apparent bug in Apply altering input array
Browse files Browse the repository at this point in the history
The new test is in list_test.sj. It is the first
entry in section ### Apply
This is described briefly in issue #154.
  • Loading branch information
jlapeyre committed Aug 16, 2018
1 parent bbf18a7 commit e33fc6b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/expressions.jl
Expand Up @@ -37,10 +37,10 @@ m(f(a,b,c))
end

function _apply_plus(mxa::Mxpr)
mx = mxpra(:Plus,margs(mxa))
mx = mxpra(:Plus, margs(mxa))
mx = canonexpr!(mx)
setcanon(mx)
return isa(mx,Mxpr) && isempty(mx) ? 0 : mx
return isa(mx, Mxpr) && isempty(mx) ? 0 : mx
end

@doap Apply(h,mxa::Mxpr) = mxpra(h,margs(mxa))
Expand Down
12 changes: 10 additions & 2 deletions symata_test/list_test.sj
Expand Up @@ -257,13 +257,21 @@ T Map(f,ex,[0,Infinity]) == f([f([f([f([f([f(a)])])])])])
T Map(f,ex,-1) == [f([f([f([f([f(a)])])])])]
T Map(f,ex,-2) == [f([f([f([f([a])])])])]
T Map(f,ex,-3) == [f([f([f([[a]])])])]
T Map(f,ex,[2,-3]) == [[f([f([[a]])])]]
T Map(f,ex,[2,-3]) == [[f([f([[a]])])]]
T Map(f, h0(h1(h2(h3(h4(a))))), [2, -3]) == h0(h1(f(h2(f(h3(h4(a)))))))
T Map(f, a + b + c + d) == f(a) + f(b) + f(c) + f(d)
T Map(f, x^2 + y^2, 2) == f(f(x)^f(2)) + f(f(y)^f(2))

ClearAll(a,f,ex)

### Apply

ClearAll(t)
t = Range(10)
Apply(Plus, t)
T t == Range(10)
ClearAll(t)

### Nothing

T Nothing() == Nothing
Expand Down Expand Up @@ -346,7 +354,7 @@ ClearAll(a,b,c,d,e,f,expr,unflatten,lst,ftest)
# Convert a flat list into an array with dimensions d = [n1,n2,...]
ftest(x_) := IntegerQ(x) && Positive(x)
unflatten(e_, [d__`ftest`]) := Condition(
Fold(Partition, e,
Fold(Partition, e,
Take([d], [-1, 2, -1])), (Length(e) == Times(d)) == True)
lst = [a,b,c,d,e,f]

Expand Down

0 comments on commit e33fc6b

Please sign in to comment.