Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isempty for EmptySet #741

Merged
merged 2 commits into from
Oct 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/src/lib/representations.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ dim(::EmptySet)
σ(::AbstractVector{Real}, ::EmptySet{Real})
∈(::AbstractVector{Real}, ::EmptySet{Real})
an_element(::EmptySet)
isempty(::EmptySet)
norm(::EmptySet, ::Real)
radius(::EmptySet, ::Real)
diameter(::EmptySet, ::Real)
Expand Down
19 changes: 18 additions & 1 deletion src/EmptySet.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import Base.∈
import Base: ∈, isempty

export EmptySet, ∅,
an_element
Expand Down Expand Up @@ -96,6 +96,23 @@ function an_element(∅::EmptySet)
error("an empty set does not have any element")
end

"""
isempty(∅::EmptySet)

Return if the empty set is empty or not.

### Input

- `∅` -- empty set

### Output

`true`.
"""
function isempty(∅::EmptySet)
return true
end

"""
norm(S::EmptySet, [p]::Real=Inf)

Expand Down
3 changes: 3 additions & 0 deletions test/unit_EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ for N in [Float64, Rational{Int}, Float32]
@test !∈(N[0], E)
@test !∈(N[0, 0], E)

# emptiness check
@test isempty(E)

# an_element/norm/radius/diameter functions
@test_throws ErrorException an_element(E)
@test_throws ErrorException norm(E)
Expand Down