Skip to content

Commit

Permalink
EmptySet: redefine norm/radius/diameter
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Dec 16, 2024
1 parent 4c9fe3a commit d659760
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
5 changes: 3 additions & 2 deletions src/Sets/EmptySet/diameter.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function diameter(::EmptySet, ::Real=Inf)
throw(ArgumentError("the diameter of an empty set is undefined"))
function diameter(∅::EmptySet, ::Real=Inf)
N = eltype(∅)
return zero(N)
end
5 changes: 3 additions & 2 deletions src/Sets/EmptySet/norm.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function norm(::EmptySet, ::Real=Inf)
throw(ArgumentError("the norm of an empty set is undefined"))
function norm(∅::EmptySet, ::Real=Inf)
N = eltype(∅)
return zero(N)
end
5 changes: 3 additions & 2 deletions src/Sets/EmptySet/radius.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
function radius(::EmptySet, ::Real=Inf)
throw(ArgumentError("the radius of an empty set is undefined"))
function radius(∅::EmptySet, ::Real=Inf)
N = eltype(∅)
return zero(N)
end
15 changes: 6 additions & 9 deletions test/Sets/EmptySet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ for N in [Float64, Rational{Int}, Float32]
@test E2 isa EmptySet{N} && dim(E2) == 2

# diameter
@test_throws ArgumentError diameter(E) # TODO this should maybe change
# res = diameter(E)
# @test res isa N && res == N(0)
res = diameter(E)
@test res isa N && res == N(0)

# dim
@test dim(E) == 2
Expand Down Expand Up @@ -99,14 +98,12 @@ for N in [Float64, Rational{Int}, Float32]
@test_throws ArgumentError low(E, 1)

# norm
@test_throws ArgumentError norm(E) # TODO this should maybe change
# res = norm(E)
# @test res isa N && res == N(0)
res = norm(E)
@test res isa N && res == N(0)

# radius
@test_throws ArgumentError radius(E) # TODO this should maybe change
# res = radius(E)
# @test res isa N && res == N(0)
res = radius(E)
@test res isa N && res == N(0)

# rand
@test rand(EmptySet; N=N) isa EmptySet{N}
Expand Down

0 comments on commit d659760

Please sign in to comment.