Skip to content

Commit

Permalink
add parameter for fractional bar length
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Hedström committed Nov 21, 2023
1 parent 5b3bd1d commit 49caa8b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 43 deletions.
4 changes: 2 additions & 2 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@deprecate Progress(n::Integer, dt::Real, desc::AbstractString="Progress: ",
barlen=nothing, color::Symbol=:green, output::IO=stderr;
offset::Integer=0) Progress(n; dt=dt, desc=desc, barlen=barlen, color=color, output=output, offset=offset)
barlen=nothing, barlen_fraction::Float64=1.0, color::Symbol=:green, output::IO=stderr;
offset::Integer=0) Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, color=color, output=output, offset=offset)

@deprecate Progress(n::Integer, desc::AbstractString, offset::Integer=0; kwargs...) Progress(n; desc=desc, offset=offset, kwargs...)

Expand Down
3 changes: 2 additions & 1 deletion test/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ end
println("Testing deprecated Progress building")

@test_deprecated begin
local p = Progress(10, 23, "ABC", 47, :red, stdout)
local p = Progress(10, 23, "ABC", 47, 0.5, :red, stdout)
@test p.n == 10
@test p.dt == 23
@test p.desc == "ABC"
@test p.barlen == 47
@test p.barlen_fraction == 0.5
@test p.color == :red
@test p.output == stdout
end
Expand Down
28 changes: 15 additions & 13 deletions test/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ println("Testing original interface...")
testfunc(107, 0.01, 0.01)


function testfunc2(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc2(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
ProgressMeter.next!(p)
end
end
println("Testing desc and progress bar")
testfunc2(107, 0.01, 0.01, "Computing...", 50)
testfunc2(107, 0.01, 0.01, "Computing...", 50, 0.5)
println("Testing no desc and no progress bar")
testfunc2(107, 0.01, 0.01, "", 0)
testfunc2(107, 0.01, 0.01, "", 0, 1.0)
testfunc2(107, 0.01, 0.01, "", 100, 0.0)


function testfunc3(n, tsleep, desc)
Expand Down Expand Up @@ -52,8 +53,8 @@ end
println("Testing that not even 1% required...")
testfunc4()

function testfunc5A(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc5A(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:round(Int, floor(n/2))
sleep(tsleep)
ProgressMeter.next!(p)
Expand All @@ -65,10 +66,10 @@ function testfunc5A(n, dt, tsleep, desc, barlen)
end

println("\nTesting changing the bar color")
testfunc5A(107, 0.01, 0.01, "Computing...", 50)
testfunc5A(107, 0.01, 0.01, "Computing...", 50, 1.0)

function testfunc5B(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc5B(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
ProgressMeter.next!(p)
Expand All @@ -80,7 +81,8 @@ function testfunc5B(n, dt, tsleep, desc, barlen)
end

println("\nTesting changing the description")
testfunc5B(107, 0.01, 0.02, "Step 1...", 50)
testfunc5B(107, 0.01, 0.02, "Step 1...", 50, 1.0)
testfunc5B(107, 0.01, 0.02, "Step 1...", 50, 0.5)


function testfunc6(n, dt, tsleep)
Expand Down Expand Up @@ -214,7 +216,7 @@ function testfunc13a()
end
# full keyword arguments
start = 15
p = ProgressMeter.Progress(n; dt=0.01, desc="", color=:red, output=stderr, barlen=40, start = start)
p = ProgressMeter.Progress(n; dt=0.01, desc="", color=:red, output=stderr, barlen=40, barlen_fraction=0.8, start = start)
for i in 1:n-start
sleep(0.05)
ProgressMeter.next!(p)
Expand All @@ -223,7 +225,7 @@ end

function testfunc13b()
# same with keyword arguments only
@showprogress dt=0.01 color=:red output=stderr barlen=40 for i=1:15
@showprogress dt=0.01 color=:red output=stderr barlen=40 barlen_fraction=0.8 for i=1:15
sleep(0.1)
end
end
Expand All @@ -248,7 +250,7 @@ function testfunc14(barglyphs)
ProgressMeter.next!(p)
end
p = ProgressMeter.Progress(n, dt=0.01, desc="",
color=:red, output=stderr, barlen=40,
color=:red, output=stderr, barlen=40, barlen_fraction=0.5,
barglyphs=ProgressMeter.BarGlyphs(barglyphs))
for i in 1:n
sleep(0.05)
Expand Down
22 changes: 11 additions & 11 deletions test/test_float.jl
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
println("Testing floating normal progress bar (offset 4)")
function testfunc1(n, dt, tsleep, desc, barlen, offset)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, offset=offset)
function testfunc1(n, dt, tsleep, desc, barlen, barlen_fraction, offset)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, offset=offset)
for i = 1:n
sleep(tsleep)
ProgressMeter.next!(p)
end
print("\n" ^ 5)
end
testfunc1(30, 0.1, 0.1, "progress ", 70, 4)
testfunc1(30, 0.1, 0.1, "progress ", 70, 0.8, 4)

println("Testing floating normal progress bars with values and keep (2 levels)")
function testfunc2(n, dt, tsleep, desc, barlen)
p1 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, offset=0)
p2 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, offset=5)
function testfunc2(n, dt, tsleep, desc, barlen, barlen_fraction)
p1 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, offset=0)
p2 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, offset=5)
for i = 1:n
sleep(tsleep)
ProgressMeter.next!(p1; showvalues = [(:i, i),
Expand All @@ -22,12 +22,12 @@ function testfunc2(n, dt, tsleep, desc, barlen)
end
print("\n" ^ 10)
end
testfunc2(50, 0.2, 0.2, "progress ", 70)
testfunc2(50, 0.2, 0.2, "progress ", 70, 0.8)

println("Testing floating normal progress bars with changing offset")
function testfunc3(n, dt, tsleep, desc, barlen)
p1 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, offset=0)
p2 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen,offset=1)
function testfunc3(n, dt, tsleep, desc, barlen, barlen_fraction)
p1 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, offset=0)
p2 = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction, offset=1)
for i = 1:n
sleep(tsleep)
ProgressMeter.next!(p1; showvalues = [(:i, i) for _ in 1:i], keep=false)
Expand All @@ -36,7 +36,7 @@ function testfunc3(n, dt, tsleep, desc, barlen)
end
print("\n" ^ (10 + 5))
end
testfunc3(10, 0.2, 0.5, "progress ", 70)
testfunc3(10, 0.2, 0.5, "progress ", 70, 0.8)

println("Testing floating thresh progress bar (offset 2)")
function testfunc4(thresh, dt, tsleep, desc, offset)
Expand Down
32 changes: 16 additions & 16 deletions test/test_showvalues.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,42 @@ ProgressMeter.ijulia_behavior(ijulia_behavior)
lazy_no_lazy(values) = (rand() < 0.5) ? values : () -> values

println("Testing showvalues with a Dict (2 values)")
function testfunc1(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc1(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
values = Dict(:i => i, :halfdone => (i >= n/2))
ProgressMeter.next!(p; showvalues = lazy_no_lazy(values))
end
end
testfunc1(50, 1, 0.2, "progress ", 70)
testfunc1(50, 1, 0.2, "progress ", 70, 0.8)

println("Testing showvalues with an Array of tuples (4 values)")
function testfunc2(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc2(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction)
for i = 1:n
sleep(tsleep)
values = [(:i, i), (:constant, "foo"), (:isq, i^2), (:large, 2^i)]
ProgressMeter.next!(p; showvalues = lazy_no_lazy(values))
end
end
testfunc2(30, 1, 0.2, "progress ", 60)
testfunc2(30, 1, 0.2, "progress ", 60, 0.8)

println("Testing showvalues when types of names differ (3 values)")
function testfunc3(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc3(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
values = [(:i, i*10), ("constant", "foo"),
("foobar", round(i*tsleep, digits=4))]
ProgressMeter.next!(p; showvalues = lazy_no_lazy(values))
end
end
testfunc3(30, 1, 0.2, "progress ", 70)
testfunc3(30, 1, 0.2, "progress ", 70, 0.8)

println("Testing progress with showing values when num values to print changes between iterations")
function testfunc4(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc4(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
values_pool = [(:i, i*10), ("constant", "foo"),
Expand All @@ -50,7 +50,7 @@ function testfunc4(n, dt, tsleep, desc, barlen)
ProgressMeter.next!(p; showvalues = lazy_no_lazy(values))
end
end
testfunc4(30, 1, 0.2, "opt steps ", 70)
testfunc4(30, 1, 0.2, "opt steps ", 70, 0.8)

println("Testing showvalues with changing number of lines")
prog = ProgressMeter.Progress(50)
Expand All @@ -63,16 +63,16 @@ for i in 1:50
end

println("Testing showvalues with a different color (1 value)")
function testfunc5(n, dt, tsleep, desc, barlen)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen)
function testfunc5(n, dt, tsleep, desc, barlen, barlen_fraction)
p = ProgressMeter.Progress(n; dt=dt, desc=desc, barlen=barlen, barlen_fraction=barlen_fraction)
for i = 1:n
sleep(tsleep)
values = [(:large, 2^i)]
ProgressMeter.next!(p; showvalues = lazy_no_lazy(values),
valuecolor = :yellow)
end
end
testfunc5(10, 1, 0.2, "progress ", 40)
testfunc5(10, 1, 0.2, "progress ", 40, 0.8)

println("Testing showvalues with threshold-based progress")
prog = ProgressMeter.ProgressThresh(1e-5; desc="Minimizing:")
Expand All @@ -93,7 +93,7 @@ ProgressMeter.finish!(prog)


println("Testing showvalues with early cancel")
prog = ProgressMeter.Progress(100; dt=1, desc="progress: ", barlen=70)
prog = ProgressMeter.Progress(100; dt=1, desc="progress: ", barlen=70, barlen_fraction=0.8)
for i in 1:50
values = Dict(:left => 100 - i)
ProgressMeter.update!(prog, i; showvalues = lazy_no_lazy(values))
Expand Down

0 comments on commit 49caa8b

Please sign in to comment.