Skip to content

Commit 5ffda3a

Browse files
committed
add misc tests covering errors, show(), backtracking, and @debug logs
1 parent 8fce0e3 commit 5ffda3a

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

Diff for: test/misc.jl

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using Choices
2+
using Test
3+
4+
function test_error_handling() # and show()
5+
ary = ["one", "two", "three"]
6+
comp = choose(1,2,5)
7+
@test repr(comp) == "(choose from (1, 2, 5))"
8+
comp =
9+
comp |> the_number_of_the_counting ->
10+
ary[the_number_of_the_counting]
11+
@test repr(comp) == "(choose from (1, 2, 5) and call a nontrivial function)"
12+
@test_throws BoundsError [comp...] # 5 is right out!
13+
cut()
14+
end
15+
test_error_handling()
16+
17+
function test_loads_of_backtracking() # and @debug logs
18+
comp = choose([[0]])
19+
for n 1:5
20+
comp =
21+
comp |> ary ->
22+
choose(false, true) |> atend ->
23+
(atend ? [ary; n] : [n; ary])
24+
end
25+
comp =
26+
comp |> ary -> begin
27+
issorted(ary) || fail()
28+
ary
29+
end
30+
answers = []
31+
@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...])
32+
cut()
33+
@test answers == [[0,1,2,3,4,5]]
34+
end
35+
test_loads_of_backtracking()

Diff for: test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ include("razzle-dazzle-root-beer.jl")
22
include("rosettacode-amb.jl")
33
include("sudoku.jl")
44
include("emirp.jl")
5+
include("misc.jl")

0 commit comments

Comments
 (0)