Skip to content

Commit 5410ab4

Browse files
Add tests for sublibraries
Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com> Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 7a38453 commit 5410ab4

File tree

4 files changed

+75
-0
lines changed

4 files changed

+75
-0
lines changed

lib/RecursiveArrayToolsArrayPartitionAnyAll/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
88
[compat]
99
RecursiveArrayTools = "3.48"
1010
julia = "1.10"
11+
12+
[extras]
13+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14+
15+
[targets]
16+
test = ["Test"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
using RecursiveArrayTools, RecursiveArrayToolsArrayPartitionAnyAll, Test
2+
3+
@testset "Optimized any" begin
4+
ap = ArrayPartition(collect(1:5), collect(6:10), collect(11:15))
5+
@test any(x -> x == 4, ap)
6+
@test any(x -> x == 15, ap)
7+
@test !any(x -> x == 17, ap)
8+
@test any(ap .> 10)
9+
@test !any(ap .> 20)
10+
end
11+
12+
@testset "Optimized all" begin
13+
ap = ArrayPartition(ones(5), ones(5), ones(5))
14+
@test all(x -> x == 1.0, ap)
15+
@test !all(x -> x == 2.0, ap)
16+
@test all(ap .> 0)
17+
18+
ap2 = ArrayPartition(ones(5), [1.0, 1.0, 0.0, 1.0, 1.0], ones(5))
19+
@test !all(x -> x == 1.0, ap2)
20+
end
21+
22+
@testset "Matches AbstractArray default results" begin
23+
ap = ArrayPartition(rand(100), rand(100), rand(100))
24+
f = x -> x > 0.5
25+
26+
# Results must match
27+
@test any(f, ap) == any(f, collect(ap))
28+
@test all(f, ap) == all(f, collect(ap))
29+
30+
# Edge case: empty
31+
ap_empty = ArrayPartition(Float64[], Float64[])
32+
@test !any(x -> true, ap_empty)
33+
@test all(x -> true, ap_empty)
34+
end

lib/RecursiveArrayToolsShorthandConstructors/Project.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,9 @@ RecursiveArrayTools = "731186ca-8d62-57ce-b412-fbd966d074cd"
88
[compat]
99
RecursiveArrayTools = "3.48"
1010
julia = "1.10"
11+
12+
[extras]
13+
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
14+
15+
[targets]
16+
test = ["Test"]
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using RecursiveArrayTools, RecursiveArrayToolsShorthandConstructors, Test
2+
3+
@testset "VA[...] shorthand" begin
4+
recs = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
5+
testva = VA[[1, 2, 3], [4, 5, 6], [7, 8, 9]]
6+
@test testva isa VectorOfArray
7+
@test testva.u == recs
8+
@test Array(testva) == [1 4 7; 2 5 8; 3 6 9]
9+
10+
# Nesting
11+
nested = VA[
12+
fill(1, 2, 3),
13+
VA[3ones(3), zeros(3)],
14+
]
15+
@test nested isa VectorOfArray
16+
@test nested.u[1] == fill(1, 2, 3)
17+
@test nested.u[2] isa VectorOfArray
18+
end
19+
20+
@testset "AP[...] shorthand" begin
21+
x = AP[1:5, 1:6]
22+
@test x isa ArrayPartition
23+
@test length(x) == 11
24+
@test x[1:5] == 1:5
25+
@test x[6:11] == 1:6
26+
27+
@test length(AP[]) == 0
28+
@test isempty(AP[])
29+
end

0 commit comments

Comments
 (0)