Skip to content

Commit

Permalink
test, improve coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
mingsnu committed Sep 15, 2016
1 parent d3570c1 commit 3c3187d
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/List.jl
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ function _List_from_associative(dnames, d::Associative)
for j in 1:p
name = dnames[j]
col = d[name]
columns[j] = DataArray(col)
columns[j] = DataArray(col) ## Does not work when col is a number or List

This comment has been minimized.

Copy link
@panlanfeng

panlanfeng Sep 15, 2016

Owner

this should just be
columns[j]=col

colnames[j] = Symbol(name)
end
return List(columns, Index(colnames))
Expand Down
2 changes: 1 addition & 1 deletion src/RFlavor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ using Compat
import StatsBase, DataFrames
import StatsBase:IntegerVector, RealVector, IntegerMatrix, RealMatrix
import DataArrays:DataArray, PooledDataArray
import DataFrames:pool, DataFrame, Index, DataVector, add_names, ColumnIndex, gennames, nrow, ncol, names!, rename!, rename,index
import DataFrames:pool, DataFrame, Index, DataVector, add_names, ColumnIndex, gennames, nrow, ncol, names!, rename!, rename, index
import Base: show, length, isempty


Expand Down
21 changes: 20 additions & 1 deletion test/Listtest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,26 @@ li = list(x=rand(10), y = rand(Int, 2,3), df = DataFrame(rand(5,2)),

li2 = merge(li, list(f1=*, f2=-))
li3 = list(li, list(f1=*, f2=-))
@test length(unlist(li3, true))==6
@test length(unlist(li3, true)) == 6
@test length(unlist(li3, false)) == 2

py=List(Any[rand(i) for i in 1:10])
@test length(unlist(lapply(py, mean)))==10

@test isempty(List())
@test haskey(li, :x)
@test get(li, :x, -1) == li[:x]
names!(li, [:x1, :x2, :x3, :x4])
@test names(li) == [:x1, :x2, :x3, :x4]

# ERROR: dict = Dict("a" => 1, "b" => 2, "c" => 3)
dict = Dict("a" => 1:2, "b" => [:x, :y], "c" => seq(1,2,.1))
@test typeof(List(dict)) == RFlavor.List

mat = rand(5,2)
@test typeof(List(mat)) == RFlavor.List

df = DataFrame(x=rand(10), y=rand(10))
@test typeof(List(df)) == RFlavor.List

## TOTO: push! definition might be problematic
2 changes: 2 additions & 0 deletions test/findintervaltest.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@test RFlavor.findinterval(1, [0.5, 1, 2]) == 2
@test RFlavor.findinterval(1:3, 0:0.5:4) == [3, 5, 7]
@test RFlavor.findinterval([1,4], [2, 3, 3, 5]) == [0, 3]
@test_throws ErrorException RFlavor.findinterval(1, [1, -1, 2])
@test_throws ErrorException RFlavor.findinterval([0, 1], [1, -1, 2])
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ include("rangetest.jl")
include("Listtest.jl")
include("settest.jl")
include("sweeptest.jl")
include("seqtest.jl")
4 changes: 4 additions & 0 deletions test/seqtest.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
x = rand(10)
@test RFlavor.seq(0, 1, by = 0.1) == RFlavor.seq(0, 1, 0.1) == RFlavor.seq(0, 1, length = 11)
@test RFlavor.seq_len(10) == RFlavor.seq_along(x)

1 comment on commit 3c3187d

@panlanfeng
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for the tests, i'll fix this tomorrow

Please sign in to comment.