Flux.jl/test/utils.jl

50 lines
953 B
Julia
Raw Normal View History

2017-08-19 19:20:20 +00:00
using Flux: throttle
2017-07-26 01:57:20 +00:00
2017-08-19 19:20:20 +00:00
@testset "Throttle" begin
2017-07-26 01:57:20 +00:00
@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