Skip to content

Commit

Permalink
Merge pull request #2151 from JuliaReach/schillic/doctests
Browse files Browse the repository at this point in the history
Make doctests independent of Julia version
  • Loading branch information
schillic authored May 12, 2020
2 parents 4f9205d + 03b5635 commit bea264f
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 20 deletions.
18 changes: 14 additions & 4 deletions src/Approximations/template_directions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -500,8 +500,12 @@ Cartesian components of each direction are obtained with
The integer passed as an argument is used to discretize ``φ``:
```jldoctest; filter = r"2246[0-9]*e-16"
julia> pd = PolarDirections(2)
PolarDirections{Float64,Array{Float64,1}}(2, Array{Float64,1}[[1.0, 0.0], [-1.0, 1.2246467991473532e-16]])
julia> pd = PolarDirections(2);
julia> pd.stack
2-element Array{Array{Float64,1},1}:
[1.0, 0.0]
[-1.0, 1.2246467991473532e-16]
julia> length(pd)
2
Expand Down Expand Up @@ -685,8 +689,14 @@ passed (in which case the optional argument `n` needs to be specified).
Creating a template with box directions in dimension two:
```jldoctest
julia> dirs = CustomDirections([[1.0, 0.0], [-1.0, 0.0], [0.0, 1.0], [0.0, -1.0]])
CustomDirections{Float64,Array{Float64,1}}(Array{Float64,1}[[1.0, 0.0], [-1.0, 0.0], [0.0, 1.0], [0.0, -1.0]], 2, true, true)
julia> dirs = CustomDirections([[1.0, 0.0], [-1.0, 0.0], [0.0, 1.0], [0.0, -1.0]]);
julia> dirs.directions
4-element Array{Array{Float64,1},1}:
[1.0, 0.0]
[-1.0, 0.0]
[0.0, 1.0]
[0.0, -1.0]
julia> LazySets.Approximations.isbounding(dirs)
true
Expand Down
13 changes: 11 additions & 2 deletions src/LazyOperations/CartesianProductArray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,17 @@ julia> using LazySets: block_to_dimension_indices
julia> cpa = CartesianProductArray([BallInf(zeros(n), 1.0) for n in [1, 3, 2, 3]]);
julia> block_to_dimension_indices(cpa, [2, 4, 8])
(Tuple{Int64,Int64}[(-1, -1), (2, 4), (-1, -1), (7, 9)], 2)
julia> m, k = block_to_dimension_indices(cpa, [2, 4, 8]);
julia> m
4-element Array{Tuple{Int64,Int64},1}:
(-1, -1)
(2, 4)
(-1, -1)
(7, 9)
julia> k
2
```
This vector represents the mapping "second block from dimension 2 to dimension 4,
fourth block from dimension 7 to dimension 9."
Expand Down
18 changes: 14 additions & 4 deletions src/Sets/VPolygon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ A polygon in vertex representation can be constructed by passing the list of
vertices. For example, we can build the right triangle
```jldoctest polygon_vrep
julia> P = VPolygon([[0, 0], [1, 0], [0, 1]])
VPolygon{Int64,Array{Int64,1}}(Array{Int64,1}[[0, 0], [1, 0], [0, 1]])
julia> P = VPolygon([[0, 0], [1, 0], [0, 1]]);
julia> P.vertices
3-element Array{Array{Int64,1},1}:
[0, 0]
[1, 0]
[0, 1]
```
Alternatively, a `VPolygon` can be constructed passing a matrix of vertices,
Expand All @@ -47,8 +52,13 @@ julia> M = [0 1 0; 0 0 1.]
0.0 1.0 0.0
0.0 0.0 1.0
julia> VPolygon(M)
VPolygon{Float64,Array{Float64,1}}(Array{Float64,1}[[0.0, 0.0], [1.0, 0.0], [0.0, 1.0]])
julia> P = VPolygon(M);
julia> P.vertices
3-element Array{Array{Float64,1},1}:
[0.0, 0.0]
[1.0, 0.0]
[0.0, 1.0]
```
"""
struct VPolygon{N<:Real, VN<:AbstractVector{N}} <: AbstractPolygon{N}
Expand Down
36 changes: 26 additions & 10 deletions src/Sets/VPolytope.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,34 @@ Type that represents a convex polytope in V-representation.
A polytope in vertex representation can be constructed by passing the list of
vertices. For example, we can build the tetrahedron:
```jldoctest polytope_vrep
julia> P = VPolytope([0 0 0; 1 0 0; 0 1 0; 0 0 1])
VPolytope{Int64,Array{Int64,1}}(Array{Int64,1}[[0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]])
```jldoctest
julia> P = VPolytope([0 0 0; 1 0 0; 0 1 0; 0 0 1]);
julia> P.vertices
3-element Array{Array{Int64,1},1}:
[0, 1, 0, 0]
[0, 0, 1, 0]
[0, 0, 0, 1]
```
Alternatively, a `VPolytope` can be constructed passing a matrix of vertices,
where each *column* represents a vertex:
```jldoctest polytope_vrep
```jldoctest
julia> M = [0 0 0; 1 0 0; 0 1 0; 0 0 1]'
3×4 LinearAlgebra.Adjoint{Int64,Array{Int64,2}}:
0 1 0 0
0 0 1 0
0 0 0 1
julia> VPolytope(M)
VPolytope{Int64,Array{Int64,1}}(Array{Int64,1}[[0, 0, 0], [1, 0, 0], [0, 1, 0], [0, 0, 1]])
julia> P = VPolytope(M);
julia> P.vertices
4-element Array{Array{Int64,1},1}:
[0, 0, 0]
[1, 0, 0]
[0, 1, 0]
[0, 0, 1]
```
"""
struct VPolytope{N<:Real, VN<:AbstractVector{N}} <: AbstractPolytope{N}
Expand Down Expand Up @@ -91,14 +102,19 @@ If it is empty, the result is ``-1``.
### Examples
```jldoctest
julia> v = VPolytope()
VPolytope{Float64,Array{Float64,1}}(Array{Float64,1}[])
julia> v = VPolytope();
julia> v.vertices
0-element Array{Array{Float64,1},1}
julia> dim(v)
-1
julia> v = VPolytope([ones(3)])
VPolytope{Float64,Array{Float64,1}}(Array{Float64,1}[[1.0, 1.0, 1.0]])
julia> v = VPolytope([ones(3)]);
julia> v.vertices
1-element Array{Array{Float64,1},1}:
[1.0, 1.0, 1.0]
julia> dim(v) == 3
true
Expand Down

0 comments on commit bea264f

Please sign in to comment.