Skip to content

Commit

Permalink
add misc tests covering errors, show(), backtracking, and @debug logs
Browse files Browse the repository at this point in the history
  • Loading branch information
wdebeaum committed Feb 25, 2019
1 parent 8fce0e3 commit 5ffda3a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
35 changes: 35 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
using Choices
using Test

function test_error_handling() # and show()
ary = ["one", "two", "three"]
comp = choose(1,2,5)
@test repr(comp) == "(choose from (1, 2, 5))"
comp =
comp |> the_number_of_the_counting ->
ary[the_number_of_the_counting]
@test repr(comp) == "(choose from (1, 2, 5) and call a nontrivial function)"
@test_throws BoundsError [comp...] # 5 is right out!
cut()
end
test_error_handling()

function test_loads_of_backtracking() # and @debug logs
comp = choose([[0]])
for n 1:5
comp =
comp |> ary ->
choose(false, true) |> atend ->
(atend ? [ary; n] : [n; ary])
end
comp =
comp |> ary -> begin
issorted(ary) || fail()
ary
end
answers = []
@test_logs (:debug, "considering option") (:debug, "got result") (:debug, "recursing...") (:debug, "returning!") (:debug, "iterating to next option") (:debug, "exhausted options") (:debug, "exhausted all options!") (:debug, "backtracking...") match_mode=:any min_level=Base.CoreLogging.Debug (answers = [comp...])
cut()
@test answers == [[0,1,2,3,4,5]]
end
test_loads_of_backtracking()
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ include("razzle-dazzle-root-beer.jl")
include("rosettacode-amb.jl")
include("sudoku.jl")
include("emirp.jl")
include("misc.jl")

0 comments on commit 5ffda3a

Please sign in to comment.