Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
putianyi889 committed Nov 16, 2023
1 parent 9226c33 commit f20f015
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1120,12 +1120,17 @@ end
Y = Fill(1.0, 3, 4)
O = Ones(3, 4)

op2(x,y) = x^2 + 3y

@test mapreduce(exp, +, Y) == mapreduce(exp, +, y)
@test mapreduce(exp, op2, Y) == mapreduce(exp, op2, y)
@test mapreduce(exp, +, Y; dims=2) == mapreduce(exp, +, y; dims=2)
@test mapreduce(identity, +, Y) == sum(y) == sum(Y)
@test mapreduce(identity, +, Y, dims=1) == sum(y, dims=1) == sum(Y, dims=1)

@test isapprox(mapreduce(exp, +, Y; dims=(1,), init=5.0), mapreduce(exp, +, y; dims=(1,), init=5.0), rtol=eps())
@test isapprox(mapreduce(exp, op2, Y; dims=(1,), init=5.0), mapreduce(exp, op2, y; dims=(1,), init=5.0), rtol=eps())
@test isapprox(mapreduce(exp, op2, Y; init=5.0), mapreduce(exp, op2, y; init=5.0), rtol=eps())

# Two arrays
@test mapreduce(*, +, x, Y) == mapreduce(*, +, x, y)
Expand All @@ -1134,7 +1139,6 @@ end
@test mapreduce(*, +, Y, O) == mapreduce(*, +, y, y)

f2(x,y) = 1 + x/y
op2(x,y) = x^2 + 3y
@test mapreduce(f2, op2, x, Y) == mapreduce(f2, op2, x, y)

@test mapreduce(f2, op2, x, Y, dims=1, init=5.0) == mapreduce(f2, op2, x, y, dims=1, init=5.0)
Expand Down

0 comments on commit f20f015

Please sign in to comment.