Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Dec 29, 2019
1 parent 4fa0a88 commit 3720772
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -297,14 +297,14 @@ tcopy(xf, T, reducible; kwargs...) =
reduce(append!!, xf |> Map(SingletonVector), reducible; init = Empty(T), kwargs...)
tcopy(xf, reducible; kwargs...) = tcopy(xf, _materializer(reducible), reducible; kwargs...)

function tcopy(::Type{T}, itr) where {T}
function tcopy(::Type{T}, itr; kwargs...) where {T}
xf, foldable = induction(eduction(itr))
return tcopy(xf, T, foldable)
return tcopy(xf, T, foldable; kwargs...)
end

function tcopy(itr)
function tcopy(itr; kwargs...)
xf, foldable = induction(eduction(itr))
return tcopy(xf, foldable)
return tcopy(xf, foldable; kwargs...)
end

"""
Expand Down
37 changes: 36 additions & 1 deletion test/test_copy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module TestCopy
include("preamble.jl")
import Tables
using DataFrames: DataFrame, eachrow
using StructArrays: StructVector
using StructArrays: StructVector, StructArray
using TypedTables: Table

@testset "copy [base types]" begin
Expand All @@ -25,8 +25,25 @@ end
continue
end
@test copy(Map(identity), src) ==ₜ src
@test copy(eduction(identity(x) for x in src)) ==ₜ src
if copy in (tcopy, dcopy)
@test copy(Map(identity), src; basesize=1) ==ₜ src
@test copy(identity(x) for x in src) ==ₜ src
@test copy((identity(x) for x in src); basesize=1) ==ₜ src
end
end
@testset "$copy(_, $T, ::$(prettytypeof(src)))" for src in Any[
StructVector(a = [1:4;], b = [5:8;]),
Table(a = [1:4;], b = [5:8;]),
],
T in Any[DataFrame, StructArray, Table]

@test copy(Map(identity), T, src) ==T(src)
@test copy(T, eduction(identity(x) for x in src)) ==T(src)
if copy in (tcopy, dcopy)
@test copy(Map(identity), T, src; basesize = 1) ==T(src)
@test copy(T, identity(x) for x in src) ==T(src)
@test copy(T, (identity(x) for x in src); basesize = 1) ==T(src)
end
end
@testset "$copy(_, eachrow(df))" begin
Expand All @@ -35,13 +52,31 @@ end
# requires https://github.com/JuliaData/DataFrames.jl/pull/2055
if copy in (tcopy, dcopy)
@test copy(Map(identity), eachrow(df); basesize=1) ==ₜ df
@test copy((identity(x) for x in eachrow(df)); basesize=1) ==ₜ df
@test copy(eduction(identity(x) for x in eachrow(df)); basesize=1) ==ₜ df
else
@test copy(Map(identity), eachrow(df)) ==ₜ df
@test copy(eduction(identity(x) for x in eachrow(df))) ==ₜ df
end
else
@test_broken copy(Map(identity), eachrow(df)) ==ₜ df
end
end
end

@testset "$collect" for collect in [collect, tcollect, dcollect]
@testset "$collect(_, ::$(prettytypeof(src)))" for src in Any[
1:64,
StructVector(a=[1:4;], b=[5:8;]),
]
@test collect(Map(identity), src) ==ₜ Base.collect(src)
@test collect(eduction(identity(x) for x in src)) ==ₜ Base.collect(src)
if collect in (tcollect, dcollect)
@test collect(Map(identity), src; basesize=1) ==ₜ Base.collect(src)
@test collect(identity(x) for x in src) ==ₜ Base.collect(src)
@test collect((identity(x) for x in src); basesize=1) ==ₜ Base.collect(src)
end
end
end

end # module

0 comments on commit 3720772

Please sign in to comment.