Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bkamins committed Sep 19, 2023
1 parent 2bdac71 commit 7f504e9
Showing 1 changed file with 53 additions and 2 deletions.
55 changes: 53 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ end
@test Tables.istable(Vector{Dict{String}})
@test Tables.istable(Vector{Dict{SubString}})
@test Tables.istable(Vector{Dict{AbstractString}})

@test Set(Tables.columnnames(Dict(:a=>1, :b=>2))) == Set([:a, :b])
@test Set(Tables.columnnames(Dict("a"=>1, "b"=>2))) == Set([:a, :b])
@test Set(Tables.columnnames(Dict("a"=>1, SubString("b")=>2))) == Set([:a, :b])
Expand All @@ -976,4 +976,55 @@ end
@test Tables.getcolumn(Dict("a"=>1, SubString("b")=>2), Int, 1, :a) == 1
@test Tables.getcolumn(Dict(SubString("a")=>1, SubString("b")=>2), Int, 1, :a) == 1
end


@testset "test nrow and ncol" begin
# AbstractColumns
@test nrow(Tables.CopiedColumns((;))) == 0
@test ncol(Tables.CopiedColumns((;))) == 0
@test nrow(Tables.CopiedColumns((a=1:3, b=2:4))) == 3
@test ncol(Tables.CopiedColumns((a=1:3, b=2:4))) == 2

# ColumnTable
@test nrow((;)) == 0
@test ncol((;)) == 0
@test nrow((a=1:3, b=2:4)) == 3
@test ncol((a=1:3, b=2:4)) == 2

# AbstractRowTable
@test nrow(collect(Tables.rows(Tables.table(ones(0, 0))))) == 0
@test ncol(collect(Tables.rows(Tables.table(ones(0, 0))))) == 0
@test nrow(collect(Tables.rows(Tables.table(ones(2, 3))))) == 2
@test ncol(collect(Tables.rows(Tables.table(ones(2, 3))))) == 3

# RowTable
@test nrow(NamedTuple[]) == 0
@test ncol(NamedTuple[]) == 0
@test nrow([(a=1,b=2), (a=3, b=4), (a=5, b=6)]) == 3
@test ncol([(a=1, b=2), (a=3, b=4), (a=5, b=6)]) == 2

# MatrixTable
@test nrow(Tables.table(ones(0, 0))) == 0
@test ncol(Tables.table(ones(0, 0))) == 0
@test nrow(Tables.table(ones(2, 3))) == 2
@test ncol(Tables.table(ones(2, 3))) == 3
@test nrow(Tables.table([])) == 0
@test ncol(Tables.table([])) == 1
@test nrow(Tables.table([1, 2])) == 2
@test ncol(Tables.table([1, 2])) == 1

# MatrixRowTable
@test nrow(Tables.rows(Tables.table(ones(0, 0)))) == 0
@test ncol(Tables.rows(Tables.table(ones(0, 0)))) == 0
@test nrow(Tables.rows(Tables.table(ones(2, 3)))) == 2
@test ncol(Tables.rows(Tables.table(ones(2, 3)))) == 3
@test nrow(Tables.rows(Tables.table([]))) == 0
@test ncol(Tables.rows(Tables.table([]))) == 1
@test nrow(Tables.rows(Tables.table([1, 2]))) == 2
@test ncol(Tables.rows(Tables.table([1, 2]))) == 1

# DictRowTable
@test nrow(Tables.dictrowtable(NamedTuple[])) == 0
@test ncol(Tables.dictrowtable(NamedTuple[])) == 0
@test nrow(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 3
@test ncol(Tables.dictrowtable([(a=1, b=2), (a=3, b=4), (a=5, b=6)])) == 2
end

0 comments on commit 7f504e9

Please sign in to comment.