From e15c013f7c9fd9e4b7a478893cc523ebffd118f9 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 1 Jun 2018 15:36:01 +0200 Subject: [PATCH 1/3] changes for 0.7 --- REQUIRE | 2 +- src/Reactive.jl | 2 - src/core.jl | 41 ++++++-- src/deprecation.jl | 12 --- test/REQUIRE | 1 - test/async.jl | 14 +-- test/basics.jl | 214 +++++++++++++++++++------------------- test/call_count.jl | 14 +-- test/flatten.jl | 74 ++++++------- test/node_order.jl | 56 +++++----- test/push_to_non_input.jl | 58 +++++------ test/queue_runner.jl | 46 ++++---- test/runtests.jl | 11 +- test/time.jl | 68 ++++++------ 14 files changed, 309 insertions(+), 304 deletions(-) delete mode 100644 src/deprecation.jl delete mode 100644 test/REQUIRE diff --git a/REQUIRE b/REQUIRE index cee6d88..43e1b56 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ -julia 0.5 +julia 0.6 DataStructures diff --git a/src/Reactive.jl b/src/Reactive.jl index 47d9e72..233e3ae 100644 --- a/src/Reactive.jl +++ b/src/Reactive.jl @@ -7,6 +7,4 @@ include("operators.jl") include("async.jl") include("time.jl") -include("deprecation.jl") - end # module diff --git a/src/core.jl b/src/core.jl index a594285..80751b9 100644 --- a/src/core.jl +++ b/src/core.jl @@ -27,9 +27,14 @@ const edges = Vector{Int}[] #parents to children, useful for plotting graphs const node_count = Dict{String, Int}() #counts of different signals for naming +if VERSION < v"0.7.0-alpha.2" + const wait07 = wait +else + const wait07 = fetch +end if !debug_memory - type Signal{T} + mutable struct Signal{T} id::Int # also its index into `nodes`, and `edges` value::T parents::Tuple @@ -48,7 +53,7 @@ if !debug_memory end end else - type Signal{T} + mutable struct Signal{T} id::Int value::T parents::Tuple @@ -215,15 +220,29 @@ end set_value!(node::Signal, x) = (node.value = x) ##### Messaging ##### - -immutable Message +struct Message node value onerror::Function end - +struct NullException <: Exception +end # Global channel for signal updates -const _messages = Channel{Nullable{Message}}(CHANNEL_SIZE[]) +struct MaybeMessage + isnull::Bool + data::Message + MaybeMessage() = new(true) + MaybeMessage(m::Message) = new(false, m) +end + +Base.get(x::MaybeMessage) = isnull(x) ? throw(NullException()) : x.data +if VERSION < v"0.7.0-alpha.2" + import Base: isnull +end +isnull(x::MaybeMessage) = x.isnull +Base.convert(::Type{MaybeMessage}, x::Message) = MaybeMessage(x) + +const _messages = Channel{MaybeMessage}(CHANNEL_SIZE[]) run_async(async::Bool) = (async_mode[] = async) @@ -265,7 +284,7 @@ function async_push!(n, x, onerror=print_error) end function break_loop() - put!(_messages, Nullable{Message}()) + put!(_messages, MaybeMessage()) end function stop() @@ -274,7 +293,7 @@ function stop() # it seems to take a long time until the runner_task is actually finished # which can be enough to run into maybe_restart_queue with !isdone(runner_task) # see #144 - wait(runner_task[]) + wait07(runner_task[]) end """ @@ -399,14 +418,14 @@ function maybe_restart_queue() # will happen if `add_action!` is called while processing a push! prev_runner = current_task() @async begin - # new runner should wait for current runner to process the + # new runner should wait07 for current runner to process the # break_loop (null) message - wait(prev_runner) + wait07(prev_runner) runner_task[] = current_task() run() end else - wait(runner_task[]) + wait07(runner_task[]) runner_task[] = @async run() end end diff --git a/src/deprecation.jl b/src/deprecation.jl deleted file mode 100644 index a4d0d37..0000000 --- a/src/deprecation.jl +++ /dev/null @@ -1,12 +0,0 @@ -import Base: consume, foldl, @deprecate, @deprecate_binding -export lift, consume, foldl, keepwhen, keepif, dropif, dropwhen - -@deprecate_binding Input Signal - -@deprecate lift(f, s::Signal...; kwargs...) map(f,s...; kwargs...) -@deprecate consume(f::Union{Function, DataType}, s::Signal...;kwargs...) map(f, s...;kwargs...) -@deprecate foldl(f, x, s::Signal...;kwargs...) foldp(f, x, s...;kwargs...) -@deprecate keepwhen filterwhen -@deprecate keepif filter -@deprecate dropif(f, default, signal) filter(x -> !f(x), default, signal) -@deprecate dropwhen(predicate, x, signal) filterwhen(map(!, predicate), x, signal) diff --git a/test/REQUIRE b/test/REQUIRE deleted file mode 100644 index 8397fb0..0000000 --- a/test/REQUIRE +++ /dev/null @@ -1 +0,0 @@ -FactCheck 0.3.0 diff --git a/test/async.jl b/test/async.jl index 7261271..67605f1 100644 --- a/test/async.jl +++ b/test/async.jl @@ -1,19 +1,19 @@ -facts("Async") do +@testset "Async" begin - context("async_map") do + @testset "async_map" begin x = Signal(1; name="x") t, y = async_map(-, 0, x) z = map(yv->2yv, y; name="z") - @fact value(t) --> nothing - @fact value(y) --> 0 - @fact value(z) --> 0 + @test (value(t)) == (nothing) + @test (value(y)) == (0) + @test (value(z)) == (0) push!(x, 2) step() step() - @fact value(y) --> -2 - @fact value(z) --> -4 + @test (value(y)) == (-2) + @test (value(z)) == (-4) end end diff --git a/test/basics.jl b/test/basics.jl index 3ad7cf4..dbba9dd 100644 --- a/test/basics.jl +++ b/test/basics.jl @@ -2,74 +2,74 @@ using Reactive ## Basics -facts("Basic checks") do +@testset "Basic checks" begin x = Signal(Float32) - @fact isa(x, Signal{Type{Float32}}) --> true + @test (isa(x, Signal{Type{Float32}})) == (true) a = Signal(number(); name="a") b = map(x -> x*x, a; name="b") - context("map") do + @testset "map" begin # Lift type - #@fact typeof(b) --> Reactive.Lift{Int} + #@test (typeof(b)) == (Reactive.Lift{Int}) # type conversion push!(a, 1.0) step() - @fact value(b) --> 1 + @test (value(b)) == (1) # InexactError to be precise - push!(a, 2.1, (n,x,error_node,err) -> @fact n --> a) + push!(a, 2.1, (n,x,error_node,err) -> @test (n) == (a)) step() - @fact value(b) --> 1 + @test (value(b)) == (1) push!(a, number()) step() - @fact value(b) --> value(a)^2 + @test (value(b)) == (value(a)^2) push!(a, -number()) step() - @fact value(b) --> value(a)^2 + @test (value(b)) == (value(a)^2) ## Multiple inputs to Lift d = Signal(number()) c = map(+, a, b, d, typ=Int) - @fact value(c) --> value(a) + value(b) + value(d) + @test (value(c)) == (value(a) + value(b) + value(d)) push!(a, number()) step() - @fact value(c) --> value(a) + value(b) + value(d) + @test (value(c)) == (value(a) + value(b) + value(d)) push!(d, number()) step() - @fact value(c) --> value(a) + value(b) + value(d) + @test (value(c)) == (value(a) + value(b) + value(d)) end - context("merge") do + @testset "merge" begin ## Merge d = Signal(number(); name="d") e = merge(b, d, a; name="e") # precedence to d - @fact value(e) --> value(d) + @test (value(e)) == (value(d)) push!(a, number()) step() # precedence to b over a -- a is older. - @fact value(e) --> value(b) + @test (value(e)) == (value(b)) c = map(identity, a) # Make a younger than b f = merge(d, c, b) push!(a, number()) step() - @fact value(f) --> value(c) + @test (value(f)) == (value(c)) end - context("foldp") do + @testset "foldp" begin ## foldl over time @@ -80,26 +80,26 @@ facts("Basic checks") do nums = round.([Int], rand(100)*1000) map(x -> begin push!(a, x); step() end, nums) - @fact sum(nums) --> value(f) + @test (sum(nums)) == (value(f)) end - context("filter") do + @testset "filter" begin # filter g = Signal(0) pred = x -> x % 2 != 0 h = filter(pred, 1, g) j = filter(x -> x % 2 == 0, 1, g) - @fact value(h) --> 1 - @fact value(j) --> 0 + @test (value(h)) == (1) + @test (value(j)) == (0) push!(g, 2) step() - @fact value(h) --> 1 + @test (value(h)) == (1) push!(g, 3) step() - @fact value(h) --> 3 + @test (value(h)) == (3) g = Signal(0) pred = x -> x % 2 != 0 @@ -107,26 +107,26 @@ facts("Basic checks") do push!(g, 2) step() - @fact value(h) --> 0 + @test (value(h)) == (0) push!(g, 3) step() - @fact value(h) --> 3 + @test (value(h)) == (3) end - context("filter counts") do + @testset "filter counts" begin a = Signal(1; name="a") b = Signal(2; name="b") c = filter(value(a), a; name="c") do aval; aval > 1 end d = map(*,b,c) count = foldp((x, y) -> x+1, 0, d) - @fact value(count) --> 0 + @test (value(count)) == (0) push!(a, 0) step() - @fact value(count) --> 0 + @test (value(count)) == (0) end - context("sampleon") do + @testset "sampleon" begin # sampleon g = Signal(0) nv = number() @@ -136,32 +136,32 @@ facts("Basic checks") do i = Signal(true) j = sampleon(i, g) # default value - @fact value(j) --> value(g) # j == g == nv + @test (value(j)) == (value(g)) # j == g == nv) push!(g, value(g)-1) println("step 2") step() - @fact value(j) --> value(g)+1 # g is nv - 1, j is unchanged on nv + @test (value(j)) == (value(g)+1) # g is nv - 1, j is unchanged on nv) push!(i, true) println("step 3") step() # resample - @fact value(j) --> value(g) + @test (value(j)) == (value(g)) end - context("droprepeats") do + @testset "droprepeats" begin # droprepeats count = s -> foldp((x, y) -> x+1, 0, s) k = Signal(1) l = droprepeats(k) - @fact value(l) --> value(k) + @test (value(l)) == (value(k)) push!(k, 1) step() - @fact value(l) --> value(k) + @test (value(l)) == (value(k)) push!(k, 0) step() #println(l.value, " ", value(k)) - @fact value(l) --> value(k) + @test (value(l)) == (value(k)) m = count(k) n = count(l) @@ -169,129 +169,129 @@ facts("Basic checks") do seq = [1, 1, 1, 0, 1, 0, 1, 0, 0] map(x -> begin push!(k, x); step() end, seq) - @fact value(m) --> length(seq) - @fact value(n) --> 6 + @test (value(m)) == (length(seq)) + @test (value(n)) == (6) end - context("filterwhen") do + @testset "filterwhen" begin # filterwhen b = Signal(false) n = Signal(1) dw = filterwhen(b, 0, n) - @fact value(dw) --> 0 + @test (value(dw)) == (0) push!(n, 2) step() - @fact value(dw) --> 0 + @test (value(dw)) == (0) push!(b, true) step() - @fact value(dw) --> 0 + @test (value(dw)) == (0) push!(n, 1) step() - @fact value(dw) --> 1 + @test (value(dw)) == (1) push!(n, 2) step() - @fact value(dw) --> 2 + @test (value(dw)) == (2) dw = filterwhen(b, 0, n) - @fact value(dw) --> 2 + @test (value(dw)) == (2) end - context("push! inside push!") do + @testset "push! inside push!" begin a = Signal(0) b = Signal(1) Reactive.preserve(map(x -> push!(a, x), b)) - @fact value(a) --> 0 + @test (value(a)) == (0) step() - @fact value(a) --> 1 + @test (value(a)) == (1) push!(a, 2) step() - @fact value(a) --> 2 - @fact value(b) --> 1 + @test (value(a)) == (2) + @test (value(b)) == (1) push!(b, 3) step() - @fact value(b) --> 3 - @fact value(a) --> 2 + @test (value(b)) == (3) + @test (value(a)) == (2) step() - @fact value(a) --> 3 + @test (value(a)) == (3) end - context("previous") do + @testset "previous" begin x = Signal(0) y = previous(x) - @fact value(y) --> 0 + @test (value(y)) == (0) push!(x, 1) step() - @fact value(y) --> 0 + @test (value(y)) == (0) push!(x, 2) step() - @fact value(y) --> 1 + @test (value(y)) == (1) push!(x, 3) step() - @fact value(y) --> 2 - @fact queue_size() --> 0 + @test (value(y)) == (2) + @test (queue_size()) == (0) end - context("delay") do + @testset "delay" begin x = Signal(0) y = delay(x) - @fact value(y) --> 0 + @test (value(y)) == (0) push!(x, 1) step() - @fact queue_size() --> 1 - @fact value(y) --> 0 + @test (queue_size()) == (1) + @test (value(y)) == (0) step() - @fact value(y) --> 1 - @fact queue_size() --> 0 + @test (value(y)) == (1) + @test (queue_size()) == (0) end - context("bind") do + @testset "bind" begin x = Signal(0; name="x") y = Signal(0; name="y") zpre_count = 0 zpost_count = 0 zpre = map(yval->(zpre_count+=1; 2yval), y; name="zpre") # map(...) runs the function once to get the init value on creation - @fact zpre_count --> 1 + @test (zpre_count) == (1) bind!(y, x) - @fact zpre_count --> 2 # initialising the bind should cause zpre to run too + @test (zpre_count) == (2) # initialising the bind should cause zpre to run too) zpost = map(yval->(zpost_count+=1; 2yval), y; name="zpost") - @fact zpre_count --> 2 - @fact zpost_count --> 1 + @test (zpre_count) == (2) + @test (zpost_count) == (1) @show queue_size() push!(x,1000) step() - @fact value(y) --> 1000 - @fact value(zpre) --> 2000 - @fact value(zpost) --> 2000 - @fact zpre_count --> 3 - @fact zpost_count --> 2 - @fact bound_srcs(y) --> [x] - @fact bound_dests(x) --> [y] + @test (value(y)) == (1000) + @test (value(zpre)) == (2000) + @test (value(zpost)) == (2000) + @test (zpre_count) == (3) + @test (zpost_count) == (2) + @test (bound_srcs(y)) == ([x]) + @test (bound_dests(x)) == ([y]) unbind!(y,x) push!(x,0) step() - @fact value(y) --> 1000 - @fact value(zpre) --> 2000 - @fact value(zpost) --> 2000 + @test (value(y)) == (1000) + @test (value(zpre)) == (2000) + @test (value(zpost)) == (2000) # bind where dest is before src in node list a = Signal(1; name="a") @@ -299,21 +299,21 @@ facts("Basic checks") do c = Signal(1; name="c") d = map(x->4x, c; name="d") bind!(a, d) - @fact value(d) --> value(a) + @test (value(d)) == (value(a)) - @fact queue_size() --> 0 + @test (queue_size()) == (0) push!(c, 3) - @fact queue_size() --> 1 + @test (queue_size()) == (1) step() - @fact value(c) --> 3 - @fact value(d) --> 4*3 - @fact value(a) --> 4*3 - @fact value(b) --> 2*4*3 + @test (value(c)) == (3) + @test (value(d)) == (4*3) + @test (value(a)) == (4*3) + @test (value(b)) == (2*4*3) end - context("bindmap") do + @testset "bindmap" begin src2dst(x) = x + 2 dst2src(x) = x - 2 @@ -322,77 +322,77 @@ facts("Basic checks") do src = Signal(3) dst = Signal(0) bindmap!(dst, src2dst, src) - @fact value(dst) --> 5 + @test (value(dst)) == (5) push!(src, 2) step() - @fact value(dst) --> 4 + @test (value(dst)) == (4) push!(dst, 5) step() - @fact value(src) --> 2 + @test (value(src)) == (2) unbind!(dst,src) push!(src,1) step() - @fact value(dst) --> 5 + @test (value(dst)) == (5) # twoway with initiation src = Signal(3) dst = Signal(0) bindmap!(dst, src2dst, src, dst2src) - @fact value(dst) --> 5 + @test (value(dst)) == (5) push!(src, 2) step() - @fact value(dst) --> 4 + @test (value(dst)) == (4) push!(dst, 5) step() - @fact value(src) --> 3 + @test (value(src)) == (3) unbind!(dst,src,false) # test oneway first push!(src,1) step() - @fact value(dst) --> 5 + @test (value(dst)) == (5) push!(dst,1) step() - @fact value(src) --> -1 + @test (value(src)) == (-1) # This should work but I think line 444 in operators.jl shouldn't exit if the twoway unbind! was applied after a oneway unbind!. # unbind!(dst,src) # test other way as well # push!(dst,2) # step() - # @fact value(src) --> -1 + # @test (value(src)) == (-1) # oneway without initiation src = Signal(3) dst = Signal(0) bindmap!(dst, src2dst, src, initial=false) - @fact value(dst) --> 0 + @test (value(dst)) == (0) push!(src, 2) step() - @fact value(dst) --> 4 + @test (value(dst)) == (4) push!(dst, 5) step() - @fact value(src) --> 2 + @test (value(src)) == (2) unbind!(dst,src) push!(src,1) step() - @fact value(dst) --> 5 + @test (value(dst)) == (5) # twoway without initiation src = Signal(3) dst = Signal(0) bindmap!(dst, src2dst, src, dst2src, initial=false) - @fact value(dst) --> 0 + @test (value(dst)) == (0) push!(src, 2) step() - @fact value(dst) --> 4 + @test (value(dst)) == (4) push!(dst, 5) step() - @fact value(src) --> 3 + @test (value(src)) == (3) unbind!(dst,src) push!(src,1) step() - @fact value(dst) --> 5 + @test (value(dst)) == (5) push!(dst,2) step() - @fact value(src) --> 1 + @test (value(src)) == (1) end diff --git a/test/call_count.jl b/test/call_count.jl index 2c61159..801d5fe 100644 --- a/test/call_count.jl +++ b/test/call_count.jl @@ -3,7 +3,7 @@ if !isdefined(:number) number() = rand(0:100) end -facts("Call counting") do +@testset "Call counting" begin a = Signal(0) b = Signal(0) @@ -27,12 +27,12 @@ facts("Call counting") do push!(b, number()) step() - @fact ca.value --> i - @fact cb.value --> i - @fact cc.value --> 2i - @fact cd.value --> 2i - @fact ce.value --> i - @fact cf.value --> 2i + @test (ca.value) == (i) + @test (cb.value) == (i) + @test (cc.value) == (2i) + @test (cd.value) == (2i) + @test (ce.value) == (i) + @test (cf.value) == (2i) end end diff --git a/test/flatten.jl b/test/flatten.jl index 1512e39..dfbdf8d 100644 --- a/test/flatten.jl +++ b/test/flatten.jl @@ -1,4 +1,4 @@ -facts("Flatten") do +@testset "Flatten" begin a = Signal(0) b = Signal(1) @@ -8,43 +8,43 @@ facts("Flatten") do d = flatten(c) cnt = foldp((x, y) -> x+1, 0, d) - context("Signal{Signal} -> flat Signal") do + @testset "Signal{Signal} -> flat Signal" begin # Flatten implies: - @fact value(c) --> a - @fact value(d) --> value(a) + @test (value(c)) == (a) + @test (value(d)) == (value(a)) end - context("Initial update count") do - @fact value(cnt) --> 0 + @testset "Initial update count" begin + @test (value(cnt)) == (0) end - context("Current signal updates") do + @testset "Current signal updates" begin push!(a, 2) step() - @fact value(cnt) --> 1 - @fact value(d) --> value(a) + @test (value(cnt)) == (1) + @test (value(d)) == (value(a)) end - context("Signal swap") do + @testset "Signal swap" begin push!(c, b) step() - @fact value(cnt) --> 2 - @fact value(d) --> value(b) + @test (value(cnt)) == (2) + @test (value(d)) == (value(b)) push!(a, 3) step() - @fact value(cnt) --> 2 - @fact value(d) --> value(b) + @test (value(cnt)) == (2) + @test (value(d)) == (value(b)) push!(b, 3) step() - @fact value(cnt) --> 3 - @fact value(d) --> value(b) + @test (value(cnt)) == (3) + @test (value(d)) == (value(b)) end - context("Subtle sig swap issue") do + @testset "Subtle sig swap issue" begin # When a node, a map (e) in this case, has a flatten as a parent, but also # a signal that is the flatten parent sigsig's (c's) current value ("a" here) # then when the sigsig gets pushed another value, you want the map to @@ -57,38 +57,38 @@ facts("Flatten") do d = flatten(c) e = map(*, a, d) #e is dependent on "a" directly and through d - @fact value(e) --> 1 + @test (value(e)) == (1) push!(a, 3) step() - @fact value(a) --> 3 - @fact value(d) --> 3 - @fact value(e) --> 9 + @test (value(a)) == (3) + @test (value(d)) == (3) + @test (value(e)) == (9) push!(c, b) - @fact value(e) --> 9 # no change until step + @test (value(e)) == (9) # no change until step) step() - @fact value(d) --> 2 # d now takes b's value - @fact value(e) --> 6 # e == d * a == 2 * 3 == 6 + @test (value(d)) == (2) # d now takes b's value) + @test (value(e)) == (6) # e == d * a == 2 * 3 == 6) # the push!(c, b) should have triggered a "rewiring" of the graph # so that updates to b affect d and e push!(b, 9) step() - @fact value(d) --> 9 # d now takes b's value - @fact value(e) --> 27 # e == d * a == 9 * 3 == 27 + @test (value(d)) == (9) # d now takes b's value) + @test (value(e)) == (27) # e == d * a == 9 * 3 == 27) # changes to a should still affect e (but not d) push!(a, 4) - @fact value(e) --> 27 # no change until step + @test (value(e)) == (27) # no change until step) step() - @fact value(a) --> 4 - @fact value(d) --> 9 # no change to d - @fact value(e) --> 36 # a*d == 4 * 9 + @test (value(a)) == (4) + @test (value(d)) == (9) # no change to d) + @test (value(e)) == (36) # a*d == 4 * 9) - @fact queue_size() --> 0 + @test (queue_size()) == (0) end - context("Sigsig's value created after SigSig") do + @testset "Sigsig's value created after SigSig" begin # This is why we need bind! in flatten implementation rather than just # setting the flatten's parents to (input, current_node) every time # input updates. That won't work if the current_node was created after @@ -104,19 +104,19 @@ facts("Flatten") do d = flatten(c) b_orig = b - @fact d.value --> a.value + @test (d.value) == (a.value) push!(b, number()) step() - @fact d.value --> b.value + @test (d.value) == (b.value) push!(a, number()) step() - @fact d.value --> a.value - @fact b_orig --> not(b) + @test (d.value) == (a.value) + @test (b_orig) != b push!(b, number()) step() - @fact d.value + 1 --> b.value + 1 + @test (d.value + 1) == (b.value + 1) end end diff --git a/test/node_order.jl b/test/node_order.jl index 9e2606b..a0c80e5 100644 --- a/test/node_order.jl +++ b/test/node_order.jl @@ -1,4 +1,4 @@ -facts("multi-path graphs 1") do +@testset "multi-path graphs 1" begin a = Signal(0) b = Signal(0) @@ -7,7 +7,7 @@ facts("multi-path graphs 1") do e = map(+, a, map(x->2x, a)) # Both depend on a f = map(+, a, b, c, e) - @fact queue_size() --> 0 + @test (queue_size()) == (0) for (av,bv) in [(1,2),(1,3),(7,7)] @show av bv @@ -16,10 +16,10 @@ facts("multi-path graphs 1") do Reactive.run_till_now() push!(b, bv) Reactive.run_till_now() - @fact value(c) --> av + bv - @fact value(e) --> 3av - @fact value(d) --> bv - @fact value(f) --> 5av + 2bv + @test (value(c)) == (av + bv) + @test (value(e)) == (3av) + @test (value(d)) == (bv) + @test (value(f)) == (5av + 2bv) end xv = 2 @@ -28,17 +28,17 @@ facts("multi-path graphs 1") do x2 = map(x->2x, x) z = map(+, y, x2) Reactive.run_till_now() - @fact value(y) --> xv - @fact value(x2) --> 2xv - @fact value(z) --> 3xv + @test (value(y)) == (xv) + @test (value(x2)) == (2xv) + @test (value(z)) == (3xv) xv2 = xv + 1 push!(x, xv2) Reactive.run_till_now() - @fact value(z) --> 3xv2 + @test (value(z)) == (3xv2) end -facts("multi-path graphs 2") do +@testset "multi-path graphs 2" begin a = Signal(0) b = Signal(0) @@ -53,10 +53,10 @@ facts("multi-path graphs 2") do Reactive.run_till_now() push!(b, bv) Reactive.run_till_now() - @fact value(c) --> av + bv - @fact value(e) --> 3av - @fact value(d) --> bv - @fact value(f) --> 5av + 2bv + @test (value(c)) == (av + bv) + @test (value(e)) == (3av) + @test (value(d)) == (bv) + @test (value(f)) == (5av + 2bv) end xv = 2 @@ -65,17 +65,17 @@ facts("multi-path graphs 2") do x2 = map(x->2x, x) z = map(+, y, x2) Reactive.run_till_now() - @fact value(y) --> xv - @fact value(x2) --> 2xv - @fact value(z) --> 3xv + @test (value(y)) == (xv) + @test (value(x2)) == (2xv) + @test (value(z)) == (3xv) xv2 = xv + 1 push!(x, xv2) Reactive.run_till_now() - @fact value(z) --> 3xv2 + @test (value(z)) == (3xv2) end -facts("multi-path graphs: dfs good, bfs bad") do +@testset "multi-path graphs: dfs good, bfs bad" begin # DFS good, BFS bad # s4x is initially 8 (4*2), after push!(sx,3), s4x should be 12 (4*3), but is instead 9. # initially: sx is 2, s2x is 4, s3x is 6, s4x is 8 @@ -92,13 +92,13 @@ facts("multi-path graphs: dfs good, bfs bad") do s2x = map(x->2x, sx; name="s2x") s3x = map(x->x + x÷2, s2x; name="s3x") s4x = map(+, sx, s3x; name="s4x") - @fact value.([sx, s2x, s3x, s4x]) --> [2, 4, 6, 8] + @test (value.([sx, s2x, s3x, s4x])) == ([2, 4, 6, 8]) push!(sx, 3) Reactive.run_till_now() - @fact value.([sx, s2x, s3x, s4x]) --> [3, 6, 9, 12] + @test (value.([sx, s2x, s3x, s4x])) == ([3, 6, 9, 12]) end -facts("multi-path graphs: bfs good, dfs bad") do +@testset "multi-path graphs: bfs good, dfs bad" begin #BFS good, DFS bad # s3x is initially 6 (3*2), after push!(sx, 3), s3x should be 9 (3*3), but is instead 7. # initially: sx and s1x1, s1x2 are 2, s2x is 4, s3x is 6 @@ -115,13 +115,13 @@ facts("multi-path graphs: bfs good, dfs bad") do s1x1 = map(identity, sx) s1x2 = map(identity, sx) s3x = map(+, s1x1, s1x2, sx) - @fact value.([sx, s1x1, s1x2, s3x]) --> [2, 2, 2, 6] + @test (value.([sx, s1x1, s1x2, s3x])) == ([2, 2, 2, 6]) push!(sx, 3) Reactive.run_till_now() - @fact value.([sx, s1x1, s1x2, s3x]) --> [3, 3, 3, 9] + @test (value.([sx, s1x1, s1x2, s3x])) == ([3, 3, 3, 9]) end -facts("multi-path graphs: dfs bad, bfs bad") do +@testset "multi-path graphs: dfs bad, bfs bad" begin #BFS bad, dfs bad # s3x is initially 6 (3*2), after push!(sx, 3), s3x should be 9 (3*3), but is instead 7. # what happens in BFS is: @@ -147,8 +147,8 @@ facts("multi-path graphs: dfs bad, bfs bad") do s1x2 = map(identity, sx) s2x = map(+, s1x1, s1x2) s3x = map(+, sx, s2x) - @fact value.([sx, s1x1, s1x2, s2x, s3x]) --> [2, 2, 2, 4, 6] + @test (value.([sx, s1x1, s1x2, s2x, s3x])) == ([2, 2, 2, 4, 6]) push!(sx, 3) Reactive.run_till_now() - @fact value.([sx, s1x1, s1x2, s2x, s3x]) --> [3, 3, 3, 6, 9] + @test (value.([sx, s1x1, s1x2, s2x, s3x])) == ([3, 3, 3, 6, 9]) end diff --git a/test/push_to_non_input.jl b/test/push_to_non_input.jl index f7e2c63..ac43ed4 100644 --- a/test/push_to_non_input.jl +++ b/test/push_to_non_input.jl @@ -6,48 +6,48 @@ function standard_push_test(non_input::Signal) push!(non_input, pval) step() - @fact value(non_input) --> pval - @fact value(m) --> 2pval + @test (value(non_input)) == (pval) + @test (value(m)) == (2pval) end -facts("Push to non-input nodes") do +@testset "Push to non-input nodes" begin a = Signal(number(); name="a") b = map(x -> x*x, a; name="b") - context("push to map") do + @testset "push to map" begin m = map(x->2x, b) push!(b, 10.0) step() - @fact value(b) --> 10.0 - @fact value(m) --> 2value(b) + @test (value(b)) == (10.0) + @test (value(m)) == (2value(b)) push!(a, 2.0) step() - @fact value(b) --> 4.0 - @fact value(m) --> 2value(b) + @test (value(b)) == (4.0) + @test (value(m)) == (2value(b)) push!(b, 3.0) step() - @fact value(b) --> 3.0 - @fact value(m) --> 2value(b) + @test (value(b)) == (3.0) + @test (value(m)) == (2value(b)) end - context("push to merge") do + @testset "push to merge" begin ## Merge d = Signal(number(); name="d") e = merge(b, d, a; name="e") m = map(x->2x, e) # precedence to d - @fact value(e) --> value(d) - @fact value(m) --> 2value(e) + @test (value(e)) == (value(d)) + @test (value(m)) == (2value(e)) standard_push_test(e) end - context("push to foldp") do + @testset "push to foldp" begin gc() x = Signal(number()) f = foldp(+, 0, x) @@ -60,17 +60,17 @@ facts("Push to non-input nodes") do push!(x, sval) step() - @fact value(f) --> pval + sval + @test (value(f)) == (pval + sval) end - context("push to filter") do + @testset "push to filter" begin g = Signal(0) pred = x -> x % 2 != 0 h = filter(pred, 1, g) standard_push_test(h) end - context("push to sampleon") do + @testset "push to sampleon" begin # sampleon g = Signal(0) nv = number() @@ -81,7 +81,7 @@ facts("Push to non-input nodes") do standard_push_test(j) end - context("push to droprepeats") do + @testset "push to droprepeats" begin # droprepeats k = Signal(1) l = droprepeats(k) @@ -89,7 +89,7 @@ facts("Push to non-input nodes") do standard_push_test(l) end - context("push to filterwhen") do + @testset "push to filterwhen" begin # filterwhen b = Signal(false) n = Signal(1) @@ -97,39 +97,39 @@ facts("Push to non-input nodes") do standard_push_test(dw) end - context("push to previous") do + @testset "push to previous" begin x = Signal(0) y = previous(x) standard_push_test(y) end - context("push to delay") do + @testset "push to delay" begin x = Signal(0) y = delay(x) standard_push_test(y) end - context("bind non-input") do + @testset "bind non-input" begin s = Signal(1; name="sig 1") m = map(x->2x, s; name="m") s2 = Signal(3; name="sig 2") push!(m, 10) step() - @fact value(m) --> 10 + @test (value(m)) == (10) bind!(m, s2) #two-way bind - @fact value(m) --> 3 - @fact value(s2) --> 3 + @test (value(m)) == (3) + @test (value(s2)) == (3) push!(m, 6) step() - @fact value(m) --> 6 - @fact value(s2) --> 6 + @test (value(m)) == (6) + @test (value(s2)) == (6) push!(s2, 10) step() - @fact value(m) --> 10 - @fact value(s2) --> 10 + @test (value(m)) == (10) + @test (value(s2)) == (10) end end diff --git a/test/queue_runner.jl b/test/queue_runner.jl index 8e5fbbb..b7c2866 100644 --- a/test/queue_runner.jl +++ b/test/queue_runner.jl @@ -1,9 +1,9 @@ Reactive.__init__() import Reactive: runner_task -facts("Queue runner") do - context("Queue restarts during push!") do - @fact queue_size() --> 0 +@testset "Queue runner" begin + @testset "Queue restarts during push!" begin + @test (queue_size()) == (0) bcount = 0 a = Signal(1) foreach(a; init=nothing) do _ @@ -16,18 +16,18 @@ facts("Queue runner") do end function test_queue(expected_bcount, orig_runner) push!(a, 3) - wait(Reactive.runner_task[]) - @fact queue_size() --> 0 - @fact orig_runner --> not(Reactive.runner_task[]) # we should have a new queue runner - @fact bcount --> expected_bcount + wait07(Reactive.runner_task[]) + @test (queue_size()) == (0) + @test (orig_runner) != (Reactive.runner_task[]) # we should have a new queue runner) + @test (bcount) == (expected_bcount) end - @fact bcount --> 0 + @test (bcount) == (0) test_queue(1, Reactive.runner_task[]) test_queue(2, Reactive.runner_task[]) end - context("Multiple queue restarts during a single action") do - @fact queue_size() --> 0 + @testset "Multiple queue restarts during a single action" begin + @test (queue_size()) == (0) bcount = 0 a = Signal(1) foreach(a; init=nothing) do _ @@ -43,18 +43,18 @@ facts("Queue runner") do end function test_queue(expected_bcount, orig_runner) push!(a, 3) - wait(Reactive.runner_task[]) - @fact queue_size() --> 0 - @fact orig_runner --> not(Reactive.runner_task[]) # we should have a new queue runner - @fact bcount --> expected_bcount + wait07(Reactive.runner_task[]) + @test (queue_size()) == (0) + @test (orig_runner) != Reactive.runner_task[] # we should have a new queue runner) + @test (bcount) == (expected_bcount) end - @fact bcount --> 0 + @test (bcount) == (0) test_queue(1, Reactive.runner_task[]) test_queue(2, Reactive.runner_task[]) end - context("Queue restarts after more than one push!") do - @fact queue_size() --> 0 + @testset "Queue restarts after more than one push!" begin + @test (queue_size()) == (0) bcount = 0 a = Signal(1) foreach(a; init=nothing) do _ @@ -68,12 +68,12 @@ facts("Queue runner") do function test_queue(expected_bcount, orig_runner) push!(a, 3) push!(a, 4) - wait(Reactive.runner_task[]) - @fact queue_size() --> 0 - @fact orig_runner --> not(Reactive.runner_task[]) # we should have a new queue runner - @fact bcount --> expected_bcount*2 + wait07(Reactive.runner_task[]) + @test (queue_size()) == (0) + @test (orig_runner) != (Reactive.runner_task[]) # we should have a new queue runner) + @test (bcount) == (expected_bcount*2) end - @fact bcount --> 0 + @test (bcount) == (0) test_queue(1, Reactive.runner_task[]) test_queue(2, Reactive.runner_task[]) end @@ -82,5 +82,5 @@ end if !istaskdone(Reactive.runner_task[]) Reactive.stop() - wait(Reactive.runner_task[]) + wait07(Reactive.runner_task[]) end diff --git a/test/runtests.jl b/test/runtests.jl index 7b4056b..ce0384c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,13 +1,15 @@ using Reactive -using FactCheck +using Test # Stop the runner task +using Reactive: wait07 -facts("Queue runner") do - @fact istaskdone(Reactive.runner_task[]) --> false + +@testset "Queue runner" begin + @test (istaskdone(Reactive.runner_task[])) == (false) Reactive.stop() - @fact istaskdone(Reactive.runner_task[]) --> true + @test (istaskdone(Reactive.runner_task[])) == (true) end @@ -24,4 +26,3 @@ include("flatten.jl") include("time.jl") include("async.jl") include("queue_runner.jl") -FactCheck.exitstatus() diff --git a/test/time.jl b/test/time.jl index 2e3fe2b..46961ed 100644 --- a/test/time.jl +++ b/test/time.jl @@ -1,30 +1,30 @@ -facts("Timing functions") do +@testset "Timing functions" begin - context("fpswhen") do + @testset "fpswhen" begin b = Signal(false) t = fpswhen(b, 2) acc = foldp((x, y) -> x+1, 0, t) sleep(0.75) - @fact queue_size() --> 0 + @test (queue_size()) == (0) push!(b, true) step() # processing the push to b will start the fpswhen's timer - # then we wait for two pushes from the timer, which should take ~ 1sec + # then we wait07 for two pushes from the timer, which should take ~ 1sec dt = @elapsed Reactive.run(2) push!(b, false) Reactive.run(1) # setting b to false should stop the timer sleep(0.75) # no more updates - @fact queue_size() --> 0 + @test (queue_size()) == (0) @show dt - @fact dt --> roughly(1, atol=0.25) # mac OSX needs a lot of tolerence here - @fact value(acc) --> 2 + @test isapprox(dt, 1, atol = 0.25) # mac OSX needs a lot of tolerence here) + @test (value(acc)) == (2) end - context("every") do + @testset "every" begin num_steps = 4 dt = 0.5 # gets pushed the `time()` every `dt` seconds @@ -41,18 +41,18 @@ facts("Timing functions") do accval = value(acc) @show end_t end_t .- accval - @fact accval[end] --> roughly(end_t, atol=0.01) + @test isapprox(accval[end], end_t, atol=0.01) Reactive.run_till_now() - @fact [0.5, 0.5, 0.5] --> roughly(diff(accval), atol=0.1) + @test isapprox([0.5, 0.5, 0.5], diff(accval), atol=0.1) sleep(0.75) # make sure the `close(t)` above actually also closed the timer - @fact queue_size() --> 0 + @test (queue_size()) == (0) end - context("throttle") do + @testset "throttle" begin gc() x = Signal(0; name="x") ydt = 0.5 @@ -91,11 +91,11 @@ facts("Timing functions") do @show i dt ydt y′dt zcount z′count value(y) value(y′) value(z) value(z′) - @fact value(y) --> i - @fact value(z) --> roughly(zcount, atol=1) - @fact value(y′) --> [y′prev.value[end]+1 : i;] - @fact length(value(y′)) --> less_than(i/(z′count-1)) - @fact value(z′) --> roughly(z′count, atol=1) + @test (value(y)) == (i) + @test isapprox(value(z), zcount, atol=1) + @test (value(y′)) == ([y′prev.value[end]+1 : i;]) + @test (length(value(y′))) < ((i/(z′count-1))) + @test isapprox(value(z′), z′count, atol=1) # type safety s1 = Signal(3) @@ -108,10 +108,10 @@ facts("Timing functions") do sleep(0.5) # Reactive.run(1) Reactive.run_till_now() - @fact value(t) --> r + @test (value(t)) == (r) end - context("debounce") do + @testset "debounce" begin x = Signal(0) y = debounce(0.5, x) y′ = debounce(1, x, push!, Int[], x->Int[]) # collect intermediate updates @@ -128,23 +128,23 @@ facts("Timing functions") do t0=time() step() - @fact value(y) --> 0 - @fact value(z) --> 0 - @fact queue_size() --> 0 + @test (value(y)) == (0) + @test (value(z)) == (0) + @test (queue_size()) == (0) sleep(0.55) - @fact queue_size() --> 1 # y should have been pushed to by now + @test (queue_size()) == (1) # y should have been pushed to by now) step() # run the push to y - @fact value(y) --> 3 - @fact value(z) --> 1 - @fact value(z′) --> 0 + @test (value(y)) == (3) + @test (value(z)) == (1) + @test (value(z′)) == (0) sleep(0.5) - @fact queue_size() --> 1 # y′ should have pushed by now + @test (queue_size()) == (1) # y′ should have pushed by now) step() # run the push to y′ - @fact value(z′) --> 1 - @fact value(y′) --> Int[1,2,3] + @test (value(z′)) == (1) + @test (value(y′)) == (Int[1,2,3]) push!(x, 3) step() @@ -156,12 +156,12 @@ facts("Timing functions") do step() sleep(1.1) - @fact queue_size() --> 2 #both y and y′ should have pushed + @test (queue_size()) == (2) #both y and y′ should have pushed) step() step() - @fact value(y) --> 1 - @fact value(z′) --> 2 - @fact value(y′) --> Int[3,2,1] + @test (value(y)) == (1) + @test (value(z′)) == (2) + @test (value(y′)) == (Int[3,2,1]) # type safety s1 = Signal(3) @@ -173,6 +173,6 @@ facts("Timing functions") do Reactive.run(1) sleep(0.5) Reactive.run(1) - @fact value(t) --> r + @test (value(t)) == (r) end end From a658e076f14960e139dd1f293eb45d8e6d4f80d2 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 1 Jun 2018 15:38:09 +0200 Subject: [PATCH 2/3] test on 0.6 + 0.7 --- appveyor.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index 61b361d..cd2c94d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,7 @@ environment: matrix: - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x86/0.6/julia-0.6-latest-win32.exe" + - JULIA_URL: "https://julialang-s3.julialang.org/bin/winnt/x64/0.6/julia-0.6-latest-win64.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x86/julia-latest-win32.exe" - JULIA_URL: "https://julialangnightlies-s3.julialang.org/bin/winnt/x64/julia-latest-win64.exe" From 1418b263ff5d7e50c5852d9d0eec8af2d6299a98 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 1 Jun 2018 15:42:03 +0200 Subject: [PATCH 3/3] correctly import Base.Test on 0.6 --- test/runtests.jl | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index ce0384c..fc48e92 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,9 @@ using Reactive -using Test - +if VERSION < v"0.7.0-DEV.2005" + using Base.Test +else + using Test +end # Stop the runner task using Reactive: wait07