Skip to content

Commit 6293c61

Browse files
committed
increase coverge
1 parent 61ba92f commit 6293c61

File tree

5 files changed

+90
-71
lines changed

5 files changed

+90
-71
lines changed

src/ContinuumArrays.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import QuasiArrays: cardinality, checkindex, QuasiAdjoint, QuasiTranspose, Inclu
2020
LazyQuasiArray, LazyQuasiVector, LazyQuasiMatrix, LazyLayout, LazyQuasiArrayStyle, _factorize
2121
import InfiniteArrays: Infinity, InfAxes
2222

23-
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative, ℵ₁, Inclusion, Basis, WeightedBasis, grid, transform, affine
23+
export Spline, LinearSpline, HeavisideSpline, DiracDelta, Derivative, ℵ₁, Inclusion, Basis, WeightedBasis, grid, transform, affine, ..
2424

2525
####
2626
# Interval indexing support

src/basisconcat.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ end
2626

2727
PiecewiseBasis{T}(args...) where T = PiecewiseBasis{T,typeof(args)}(args)
2828
PiecewiseBasis(args...) = PiecewiseBasis{mapreduce(eltype,promote_type,args)}(args...)
29+
PiecewiseBasis{T}(args::AbstractVector) where T = PiecewiseBasis{T,typeof(args)}(args)
30+
PiecewiseBasis(args::AbstractVector) = PiecewiseBasis{eltype(eltype(args))}(args)
2931

3032
concatbasis(::PiecewiseBasis, args...) = PiecewiseBasis(args...)
3133

test/runtests.jl

Lines changed: 1 addition & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -44,76 +44,7 @@ end
4444
@test norm(x) sqrt(2/3)
4545
end
4646

47-
@testset "AffineQuasiVector" begin
48-
x = Inclusion(0..1)
49-
y = 2x .- 1
50-
a = affine(-2..3, -1..1)
51-
52-
@testset "algebra" begin
53-
@test 2x isa AffineQuasiVector
54-
@test (2x)[0.1] == 0.2
55-
@test_throws BoundsError (2x)[2]
56-
57-
@test y isa AffineQuasiVector
58-
@test y[0.1] == 2*(0.1)-1
59-
@test y/2 isa AffineQuasiVector
60-
@test 2\y isa AffineQuasiVector
61-
@test (y/2)[0.1] == (2\y)[0.1] == -0.4
62-
@test y .+ 1 isa AffineQuasiVector
63-
@test (y .+ 1)[0.1] == (1 .+ y)[0.1]
64-
@test (y .- 1)[0.1] == y[0.1]-1
65-
@test (1 .- y)[0.1] == 1-y[0.1]
66-
@test y[x] == y[:] == y
67-
@test_throws BoundsError y[Inclusion(0..2)]
68-
end
69-
70-
@testset "find" begin
71-
@test findfirst(isequal(0.1),x) == findlast(isequal(0.1),x) == 0.1
72-
@test findall(isequal(0.1), x) == [0.1]
73-
@test findfirst(isequal(2),x) == findlast(isequal(2),x) == nothing
74-
@test findall(isequal(2), x) == Float64[]
75-
76-
@test findfirst(isequal(0.2),y) == findlast(isequal(0.2),y) == 0.6
77-
@test findfirst(isequal(2.3),y) == findlast(isequal(2.3),y) == nothing
78-
@test findall(isequal(0.2),y) == [0.6]
79-
@test findall(isequal(2),y) == Float64[]
80-
end
81-
82-
@testset "minmax" begin
83-
@test AffineQuasiVector(x)[0.1] == 0.1
84-
@test minimum(y) == -1
85-
@test maximum(y) == 1
86-
@test union(y) == Inclusion(-1..1)
87-
@test ContinuumArrays.inbounds_getindex(y,0.1) == y[0.1]
88-
@test ContinuumArrays.inbounds_getindex(y,2.1) == 2*2.1 - 1
89-
90-
z = 1 .- x
91-
@test minimum(z) == 0.0
92-
@test maximum(z) == 1.0
93-
@test union(z) == Inclusion(0..1)
94-
95-
@test !isempty(z)
96-
@test z == z
97-
end
98-
99-
@testset "AffineMap" begin
100-
@test a[0.1] == -0.16
101-
@test_throws BoundsError a[-3]
102-
@test a[-2] == first(a) == -1
103-
@test a[3] == last(a) == 1
104-
@test invmap(a)[-0.16] 0.1
105-
@test invmap(a)[1] == 3
106-
@test invmap(a)[-1] == -2
107-
@test union(a) == Inclusion(-1..1)
108-
109-
@test affine(0..1, -1..1) == y
110-
end
111-
112-
@testset "show" begin
113-
@test stringmime("text/plain", y) == "2.0 * Inclusion(0..1) .+ (-1.0)"
114-
@test stringmime("text/plain", a) == "0.4 * Inclusion(-2..3) .+ (-0.2)"
115-
end
116-
end
47+
include("test_maps.jl")
11748

11849
@testset "DiracDelta" begin
11950
δ = DiracDelta(-1..3)

test/test_basisconcat.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ContinuumArrays: PiecewiseBasis, VcatBasis, HvcatBasis
77
S2 = LinearSpline(2:3)
88
S = PiecewiseBasis(S1, S2)
99

10+
@test S == S
11+
1012
@test S[0.5,1:4] == [S1[0.5,1:2]; zeros(2)]
1113
@test S[2.5,1:4] == [zeros(2); S2[2.5,1:2]]
1214
@test_throws BoundsError S[1.5,2]
@@ -22,6 +24,12 @@ import ContinuumArrays: PiecewiseBasis, VcatBasis, HvcatBasis
2224
@test_throws BoundsError (D*S)[0.5,5]
2325

2426
@test_throws DimensionMismatch D1*S
27+
28+
@testset "Vec case" begin
29+
Sv = PiecewiseBasis([S1,S2])
30+
@test axes(Sv,2) isa BlockedUnitRange
31+
@test Sv[0.5,1:4] == S[0.5,1:4]
32+
end
2533
end
2634

2735
@testset "VcatBasis" begin
@@ -54,6 +62,8 @@ import ContinuumArrays: PiecewiseBasis, VcatBasis, HvcatBasis
5462
S2 = LinearSpline(0:0.5:1)
5563
S = HvcatBasis(2, S1, S2, S2, S1)
5664

65+
@test S == S
66+
5767
@test S[0.1, 1] == [S1[0.1,1] 0; 0 0]
5868
@test S[0.1,Block(1)] == [[S1[0.1,1] 0; 0 0], [S1[0.1,2] 0; 0 0]]
5969
D = Derivative(axes(S,1))

test/test_maps.jl

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
using ContinuumArrays, Test
2+
import ContinuumArrays: AffineQuasiVector
3+
4+
@testset "AffineQuasiVector" begin
5+
x = Inclusion(0..1)
6+
y = 2x .- 1
7+
a = affine(-2..3, -1..1)
8+
9+
@testset "algebra" begin
10+
@test 2x isa AffineQuasiVector
11+
@test x/2 isa AffineQuasiVector
12+
@test (2x)[0.1] == 0.2
13+
@test_throws BoundsError (2x)[2]
14+
15+
@test y isa AffineQuasiVector
16+
@test y[0.1] == 2*(0.1)-1
17+
@test y/2 isa AffineQuasiVector
18+
@test 2\y isa AffineQuasiVector
19+
@test (y/2)[0.1] == (2\y)[0.1] == -0.4
20+
@test y .+ 1 isa AffineQuasiVector
21+
@test (y .+ 1)[0.1] == (1 .+ y)[0.1]
22+
@test (y .- 1)[0.1] == y[0.1]-1
23+
@test (1 .- y)[0.1] == 1-y[0.1]
24+
@test y[x] == y[:] == y
25+
@test_throws BoundsError y[Inclusion(0..2)]
26+
27+
@test y == y
28+
end
29+
30+
@testset "find" begin
31+
@test findfirst(isequal(0.1),x) == findlast(isequal(0.1),x) == 0.1
32+
@test findall(isequal(0.1), x) == [0.1]
33+
@test findfirst(isequal(2),x) == findlast(isequal(2),x) == nothing
34+
@test findall(isequal(2), x) == Float64[]
35+
36+
@test findfirst(isequal(0.2),y) == findlast(isequal(0.2),y) == 0.6
37+
@test findfirst(isequal(2.3),y) == findlast(isequal(2.3),y) == nothing
38+
@test findall(isequal(0.2),y) == [0.6]
39+
@test findall(isequal(2),y) == Float64[]
40+
end
41+
42+
@testset "minmax" begin
43+
@test AffineQuasiVector(x)[0.1] == 0.1
44+
@test minimum(y) == -1
45+
@test maximum(y) == 1
46+
@test union(y) == Inclusion(-1..1)
47+
@test ContinuumArrays.inbounds_getindex(y,0.1) == y[0.1]
48+
@test ContinuumArrays.inbounds_getindex(y,2.1) == 2*2.1 - 1
49+
50+
z = 1 .- x
51+
@test minimum(z) == 0.0
52+
@test maximum(z) == 1.0
53+
@test union(z) == Inclusion(0..1)
54+
55+
@test !isempty(z)
56+
@test z == z
57+
end
58+
59+
@testset "AffineMap" begin
60+
@test a[0.1] == -0.16
61+
@test_throws BoundsError a[-3]
62+
@test a[-2] == first(a) == -1
63+
@test a[3] == last(a) == 1
64+
@test invmap(a)[-0.16] 0.1
65+
@test invmap(a)[1] == 3
66+
@test invmap(a)[-1] == -2
67+
@test union(a) == Inclusion(-1..1)
68+
69+
@test affine(0..1, -1..1) == y
70+
end
71+
72+
@testset "show" begin
73+
@test stringmime("text/plain", y) == "2.0 * Inclusion(0..1) .+ (-1.0)"
74+
@test stringmime("text/plain", a) == "0.4 * Inclusion(-2..3) .+ (-0.2)"
75+
end
76+
end

0 commit comments

Comments
 (0)