Skip to content

Commit f312733

Browse files
Split into more testsets
1 parent 03fc9c0 commit f312733

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

test/helper_functions.jl

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
@testset "helper functions" begin
2-
# Hits fallback, since we can't update `Diagonal`s in place
3-
X = Diagonal([1, 1])
4-
Y = copy(X)
5-
@test ChainRules._update!(X, [1 2; 3 4]) == [2 2; 3 5]
6-
@test X == Y # no change to X
2+
@testset "_update! Array" begin
3+
# Hits fallback, since we can't update `Diagonal`s in place
4+
X = Diagonal([1, 1])
5+
Y = copy(X)
6+
@test ChainRules._update!(X, [1 2; 3 4]) == [2 2; 3 5]
7+
@test X == Y # no change to X
78

8-
X = [1 2; 3 4]
9-
Y = copy(X)
10-
@test ChainRules._update!(X, Diagonal([1, 1])) == [2 2; 3 5]
11-
@test X != Y # X has been updated
9+
X = [1 2; 3 4]
10+
Y = copy(X)
11+
@test ChainRules._update!(X, Diagonal([1, 1])) == [2 2; 3 5]
12+
@test X != Y # X has been updated
13+
end
1214

13-
# Reusing above X
14-
@test ChainRules._update!(X, Zero()) === X
15-
@test ChainRules._update!(Zero(), X) === X
16-
@test ChainRules._update!(Zero(), Zero()) === Zero()
15+
@testset "_update! Zero" begin
16+
X = [1 2; 3 4]
17+
@test ChainRules._update!(X, Zero()) === X
18+
@test ChainRules._update!(Zero(), X) === X
19+
@test ChainRules._update!(Zero(), Zero()) === Zero()
1720

18-
X = (A=[1 0; 0 1], B=[2 2; 2 2])
19-
Y = deepcopy(X)
20-
@test ChainRules._update!(X, Y) == (A=[2 0; 0 2], B=[4 4; 4 4])
21-
@test X.A != Y.A
22-
@test X.B != Y.B
21+
X = (A=[1 0; 0 1], B=[2 2; 2 2])
22+
Y = deepcopy(X)
23+
@test ChainRules._update!(X, Y) == (A=[2 0; 0 2], B=[4 4; 4 4])
24+
@test X.A != Y.A
25+
@test X.B != Y.B
26+
end
2327

24-
try
25-
@eval cool(x,y)=x+y
26-
# We defined a 2-arg method for `cool` but no `rrule`
27-
ChainRules._checked_rrule(cool, 1.0, 2.0)
28-
catch e
29-
@test e isa ArgumentError
30-
@test e.msg == "can't differentiate `cool(::Float64, ::Float64)`; no " *
31-
"matching `rrule` is defined"
28+
@testset "_checked_rrule" begin
29+
try
30+
@eval cool(x,y)= x + y
31+
# We defined a 2-arg method for `cool` but no `rrule`
32+
ChainRules._checked_rrule(cool, 1.0, 2.0)
33+
catch e
34+
@test e isa ArgumentError
35+
@test e.msg == "can't differentiate `cool(::Float64, ::Float64)`; no " *
36+
"matching `rrule` is defined"
37+
end
3238
end
3339
end

0 commit comments

Comments
 (0)