Skip to content

Commit

Permalink
basemisc: test cases for all and any
Browse files Browse the repository at this point in the history
  • Loading branch information
iblislin committed Jul 23, 2018
1 parent 9d84756 commit 8dc1681
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions test/basemisc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,138 @@ end
end


@testset "Base.any function" begin
let # single column
"""
julia> any(x .== lag(x))
1x1 TimeSeries.TimeArray{Bool,1,Date,BitArray{1}} 2000-01-07 to 2000-01-07
│ │ _ │
├────────────┼───────┤
│ 2000-01-07 │ false │
"""
let
ts = cl.timestamp[1:5]
ta = TimeArray(ts, 1:5)
xs = any(ta .== lag(ta))
@test xs.timestamp[] == ts[end]
@test xs.values[] == false
end

"""
julia> any(x .== lag(x), 2)
4x1 TimeSeries.TimeArray{Bool,1,Date,BitArray{1}} 2000-01-04 to 2000-01-07
│ │ any │
├────────────┼───────┤
│ 2000-01-04 │ false │
│ 2000-01-05 │ true │
│ 2000-01-06 │ false │
│ 2000-01-07 │ false │
"""
let
ts = cl.timestamp[1:5]
ta = TimeArray(ts, [1, 2, 2, 3, 4])
xs = any(ta .== lag(ta), 2)

@test xs.timestamp == ts[2:end]
@test any(xs.values .== [false, true, false, false])
@test xs.colnames == ["any"]
end
end # single column

let # multi column
"""
julia> x .> 3
3x2 TimeSeries.TimeArray{Bool,2,Date,BitArray{2}} 2000-01-03 to 2000-01-05
│ │ A │ B │
├────────────┼───────┼───────┤
│ 2000-01-03 │ false │ false │
│ 2000-01-04 │ false │ true │
│ 2000-01-05 │ true │ true │
julia> any(x .> 3, 2)
3x1 TimeSeries.TimeArray{Bool,2,Date,BitArray{2}} 2000-01-03 to 2000-01-05
│ │ any │
├────────────┼───────┤
│ 2000-01-03 │ false │
│ 2000-01-04 │ true │
│ 2000-01-05 │ true │
"""
ts = cl.timestamp[1:3]
ta = TimeArray(ts, [1 2; 3 4; 5 6])
xs = any(ta .> 3, 2)

@test xs.timestamp == ts
@test any(xs.values .== [false, true, true])
@test xs.colnames == ["any"]
end # multi column
end # @testset "Base.any" function


@testset "Base.all function" begin
let # single column
"""
julia> all(x .== lag(x))
1x1 TimeSeries.TimeArray{Bool,1,Date,BitArray{1}} 2000-01-07 to 2000-01-07
│ │ _ │
├────────────┼───────┤
│ 2000-01-07 │ false │
"""
let
ts = cl.timestamp[1:5]
ta = TimeArray(ts, 1:5)
xs = all(ta .== lag(ta))
@test xs.timestamp[] == ts[end]
@test xs.values[] == false
end

"""
julia> all(x .== lag(x), 2)
4x1 TimeSeries.TimeArray{Bool,1,Date,BitArray{1}} 2000-01-04 to 2000-01-07
│ │ any │
├────────────┼───────┤
│ 2000-01-04 │ false │
│ 2000-01-05 │ true │
│ 2000-01-06 │ false │
│ 2000-01-07 │ false │
"""
let
ts = cl.timestamp[1:5]
ta = TimeArray(ts, [1, 2, 2, 3, 4])
xs = all(ta .== lag(ta), 2)

@test xs.timestamp == ts[2:end]
@test all(xs.values .== [false, true, false, false])
@test xs.colnames == ["all"]
end
end # single column

let # multi column
"""
julia> x .> 3
3x2 TimeSeries.TimeArray{Bool,2,Date,BitArray{2}} 2000-01-03 to 2000-01-05
│ │ A │ B │
├────────────┼───────┼───────┤
│ 2000-01-03 │ false │ false │
│ 2000-01-04 │ false │ true │
│ 2000-01-05 │ true │ true │
julia> all(x .> 3, 2)
3x1 TimeSeries.TimeArray{Bool,2,Date,BitArray{2}} 2000-01-03 to 2000-01-05
│ │ all │
├────────────┼───────┤
│ 2000-01-03 │ false │
│ 2000-01-04 │ false │
│ 2000-01-05 │ true │
"""
ts = cl.timestamp[1:3]
ta = TimeArray(ts, [1 2; 3 4; 5 6])
xs = all(ta .> 3, 2)

@test xs.timestamp == ts
@test all(xs.values .== [false, false, true])
@test xs.colnames == ["all"]
end # multi column
end # @testset "Base.all" function


end # @testset "basemisc"

0 comments on commit 8dc1681

Please sign in to comment.