Skip to content

Commit 2a1b189

Browse files
committed
add some tests
1 parent 84e816e commit 2a1b189

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

test/layers/show.jl

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
2+
@testset "layer printing" begin # 2-arg show, defined with layes
3+
4+
@test repr(Dense(2,3)) == "Dense(2, 3)"
5+
@test repr(Chain(Dense(2,3))) == "Chain(Dense(2, 3))"
6+
7+
end
8+
@testset "nested model printing" begin # 3-arg show, defined in show.jl
9+
10+
# Dense -- has parameter count, but not inside a matrix
11+
12+
toplevel_dense = repr("text/plain", Dense(2,3))
13+
@test occursin("Dense(2, 3)", toplevel_dense)
14+
@test occursin("# 9 parameters", toplevel_dense)
15+
16+
@test Meta.isexpr(Meta.parse(toplevel_dense), :call) # comment is ignored
17+
18+
vector_dense = repr("text/plain", [Dense(2,3), Dense(2,3)])
19+
@test occursin("Dense(2, 3)", vector_dense)
20+
@test occursin("# 9 parameters", vector_dense)
21+
22+
matrix_dense = repr("text/plain", fill(Dense(2,3), 3, 3))
23+
@test occursin("Dense(2, 3)", matrix_dense)
24+
@test !occursin("# 9 parameters", matrix_dense)
25+
26+
tuple_dense = repr("text/plain", tuple(Dense(2,3)))
27+
@test occursin("Dense(2, 3)", tuple_dense)
28+
@test !occursin("# 9 parameters", tuple_dense)
29+
30+
# Chain -- gets split over lines at top level only
31+
32+
toplevel_chain = repr("text/plain", Chain(Dense(2,3)))
33+
@test occursin("Chain(\n Dense(2, 3)", toplevel_chain)
34+
@test occursin("# 9 parameters", toplevel_chain)
35+
@test !occursin("# Total:", toplevel_chain)
36+
37+
vector_chain = repr("text/plain", [Chain(Dense(2,3)), Chain(Dense(2,3))])
38+
@test occursin("Chain(Dense(2, 3))", vector_chain)
39+
@test occursin("# 9 parameters", vector_chain)
40+
@test !occursin("# Total:", vector_chain)
41+
42+
matrix_chain = repr("text/plain", fill(Chain(Dense(2,3)), 3,3))
43+
@test occursin("Chain(Dense(2, 3))", matrix_chain)
44+
@test !occursin("# 9 parameters", matrix_chain)
45+
@test !occursin("# Total:", matrix_chain)
46+
47+
# ... and only long enough chains get
48+
49+
longchain = Chain(Dense(2, 3), Dense(3, 4), Dense(4, 5), softmax)
50+
51+
toplevel_longchain = repr("text/plain", longchain)
52+
@test occursin("Chain(\n Dense(2, 3)", toplevel_longchain)
53+
@test occursin("# 9 parameters", toplevel_longchain)
54+
@test occursin("# Total: 6 arrays, 50 parameters", toplevel_longchain)
55+
56+
vector_longchain = repr("text/plain", [longchain, longchain]) # pretty ugly in reality
57+
@test occursin("Chain(Dense(2, 3)", vector_longchain)
58+
@test occursin("# 50 parameters", vector_longchain)
59+
@test !occursin("# 9 parameters", vector_longchain)
60+
@test !occursin("# Total:", vector_longchain)
61+
62+
matrix_longchain = repr("text/plain", fill(longchain, 3,3))
63+
@test occursin("Chain(Dense(2, 3)", matrix_longchain)
64+
@test !occursin("# 9 parameters", matrix_longchain)
65+
@test !occursin("# Total:", matrix_longchain)
66+
67+
@test Meta.isexpr(Meta.parse(toplevel_longchain), :call) # comments are ignored
68+
@test Meta.parse(toplevel_longchain).args[1] == :Chain
69+
70+
end

test/runtests.jl

+1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ end
4949
@warn "CUDA unavailable, not testing GPU support"
5050
end
5151
end
52+
include("layers/show.jl")
5253

5354
@static if VERSION == v"1.5"
5455
using Documenter

0 commit comments

Comments
 (0)