add tests for throttle

This commit is contained in:
ylxdzsw 2017-07-26 09:57:20 +08:00
parent 88fa163c95
commit cce1a2a73e
2 changed files with 50 additions and 0 deletions

View File

@ -18,6 +18,7 @@ include("backend/common.jl")
include("basic.jl")
include("recurrent.jl")
include("optimizer.jl")
include("throttle.jl")
@tfonly include("backend/tensorflow.jl")
@mxonly include("backend/mxnet.jl")

49
test/throttle.jl Normal file
View File

@ -0,0 +1,49 @@
using Flux.throttle
@testset "throttle" begin
@testset "default behaviour" begin
a = []
f = throttle(()->push!(a, now()), 1, leading=true, trailing=false)
f()
f()
f()
sleep(1.01)
@test length(a) == 1
end
@testset "leading behaviour" begin
a = []
f = throttle(()->push!(a, now()), 1, leading=true, trailing=false)
f()
@test length(a) == 1
f()
@test length(a) == 1
sleep(1.01)
f()
@test length(a) == 2
end
@testset "trailing behaviour" begin
a = []
f = throttle(()->push!(a, now()), 1, leading=false, trailing=true)
f()
@test length(a) == 0
f()
@test length(a) == 0
sleep(1.01)
@test length(a) == 1
end
@testset "arguments" begin
a = []
f = throttle((x)->push!(a, x), 1, leading=true, trailing=true)
f(1)
@test a == [1]
f(2)
@test a == [1]
f(3)
@test a == [1]
sleep(1.01)
@test a == [1, 3]
end
end