Skip to content

Commit 0c46af9

Browse files
committed
move add!! test to on testset
1 parent a3e76b1 commit 0c46af9

File tree

1 file changed

+51
-49
lines changed

1 file changed

+51
-49
lines changed

test/accumulation.jl

Lines changed: 51 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,64 @@
11
@testset "accumulation.jl" begin
2-
@testset "scalar" begin
3-
@test 16 == add!!(12, 4)
4-
end
2+
@testset "add!!" begin
3+
@testset "scalar" begin
4+
@test 16 == add!!(12, 4)
5+
end
56

6-
@testset "Differentials" begin
7-
@test 16 == add!!(12, @thunk(2*2))
8-
@test 16 == add!!(16, Zero())
7+
@testset "Differentials" begin
8+
@test 16 == add!!(12, @thunk(2*2))
9+
@test 16 == add!!(16, Zero())
910

10-
@test 16 == add!!(16, DoesNotExist()) # Should this be an error?
11-
end
11+
@test 16 == add!!(16, DoesNotExist()) # Should this be an error?
12+
end
1213

13-
@testset "Array" begin
14-
@testset "Happy Path" begin
15-
@testset "RHS Array" begin
16-
A = [1.0 2.0; 3.0 4.0]
17-
result = -1.0*ones(2,2)
18-
ret = add!!(result, A)
19-
@test ret === result # must be same object
20-
@test result == [0.0 1.0; 2.0 3.0]
21-
end
14+
@testset "Array" begin
15+
@testset "Happy Path" begin
16+
@testset "RHS Array" begin
17+
A = [1.0 2.0; 3.0 4.0]
18+
result = -1.0*ones(2,2)
19+
ret = add!!(result, A)
20+
@test ret === result # must be same object
21+
@test result == [0.0 1.0; 2.0 3.0]
22+
end
2223

23-
@testset "RHS StaticArray" begin
24-
A = @SMatrix[1.0 2.0; 3.0 4.0]
25-
result = -1.0*ones(2,2)
26-
ret = add!!(result, A)
27-
@test ret === result # must be same object
28-
@test result == [0.0 1.0; 2.0 3.0]
24+
@testset "RHS StaticArray" begin
25+
A = @SMatrix[1.0 2.0; 3.0 4.0]
26+
result = -1.0*ones(2,2)
27+
ret = add!!(result, A)
28+
@test ret === result # must be same object
29+
@test result == [0.0 1.0; 2.0 3.0]
30+
end
31+
32+
@testset "RHS Diagonal" begin
33+
A = Diagonal([1.0, 2.0])
34+
result = -1.0*ones(2,2)
35+
ret = add!!(result, A)
36+
@test ret === result # must be same object
37+
@test result == [0.0 -1.0; -1.0 1.0]
38+
end
2939
end
3040

31-
@testset "RHS Diagonal" begin
32-
A = Diagonal([1.0, 2.0])
33-
result = -1.0*ones(2,2)
34-
ret = add!!(result, A)
35-
@test ret === result # must be same object
36-
@test result == [0.0 -1.0; -1.0 1.0]
41+
@testset "Unhappy Path" begin
42+
# wrong length
43+
@test_throws DimensionMismatch add!!(ones(4,4), ones(2,2))
44+
# wrong shape
45+
@test_throws DimensionMismatch add!!(ones(4,4), ones(16))
46+
# wrong type (adding scalar to array)
47+
@test_throws MethodError add!!(ones(4), 21.0)
3748
end
3849
end
3950

40-
@testset "Unhappy Path" begin
41-
# wrong length
42-
@test_throws DimensionMismatch add!!(ones(4,4), ones(2,2))
43-
# wrong shape
44-
@test_throws DimensionMismatch add!!(ones(4,4), ones(16))
45-
# wrong type (adding scalar to array)
46-
@test_throws MethodError add!!(ones(4), 21.0)
47-
end
48-
end
51+
@testset "InplaceableThunk" begin
52+
A=[1.0 2.0; 3.0 4.0]
53+
ithunk = InplaceableThunk(
54+
@thunk(A*B),
55+
x -> x.+=A
56+
)
4957

50-
@testset "InplaceableThunk" begin
51-
A=[1.0 2.0; 3.0 4.0]
52-
ithunk = InplaceableThunk(
53-
@thunk(A*B),
54-
x -> x.+=A
55-
)
56-
57-
result = -1.0*ones(2,2)
58-
ret = add!!(result, ithunk)
59-
@test ret === result # must be same object
60-
@test result == [0.0 1.0; 2.0 3.0]
58+
result = -1.0*ones(2,2)
59+
ret = add!!(result, ithunk)
60+
@test ret === result # must be same object
61+
@test result == [0.0 1.0; 2.0 3.0]
62+
end
6163
end
6264
end

0 commit comments

Comments
 (0)