Skip to content

Commit

Permalink
simple updated to make isempty workable for each data structures (#50)
Browse files Browse the repository at this point in the history
* try new base.isempty

* add tests for Base.show

* formatter
  • Loading branch information
alefcastelli authored Aug 28, 2023
1 parent c48e12f commit 966c1c3
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PowerNetworkMatrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ function Base.show_nd(
end
end

function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::PowerNetworkMatrix)
function Base.show(io::IO, array::PowerNetworkMatrix)
summary(io, array)
isempty(array) && return
println(io, ":")
Expand Down
8 changes: 8 additions & 0 deletions src/virtual_lodf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ struct VirtualLODF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64}
tol::Base.RefValue{Float64}
end

function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualLODF)
summary(io, array)
isempty(array) && return
println(io, ":")
Base.print_array(io, array)
return
end

function _get_PTDF_A_diag(
K::KLU.KLUFactorization{Float64, Int},
BA::SparseArrays.SparseMatrixCSC{Float64, Int},
Expand Down
8 changes: 8 additions & 0 deletions src/virtual_ptdf_calculations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,14 @@ struct VirtualPTDF{Ax, L <: NTuple{2, Dict}} <: PowerNetworkMatrix{Float64}
tol::Base.RefValue{Float64}
end

function Base.show(io::IO, ::MIME{Symbol("text/plain")}, array::VirtualPTDF)
summary(io, array)
isempty(array) && return
println(io, ":")
Base.print_array(io, array)
return
end

"""
Builds the PTDF matrix from a group of branches and buses. The return is a
PTDF array indexed with the branch numbers.
Expand Down
21 changes: 21 additions & 0 deletions test/test_BA_ABA_matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,24 @@ end
end
@test test_val
end

@testset "Test show for A, BA and ABA matrix" begin
sys = PSB.build_system(PSB.PSITestSystems, "c_sys5")

a = IncidenceMatrix(sys)
ba = BA_Matrix(sys)
aba = ABA_Matrix(sys)

for mat in [a, ba, aba]
test_value = false
try
show(@eval a)
test_value = true
catch err
if err isa Exception
test_value = false
end
end
@test test_value
end
end
14 changes: 14 additions & 0 deletions test/test_virtual_lodf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,11 @@ end
@testset "Test Virtual LODF auxiliary functions" begin
sys = PSB.build_system(PSB.PSITestSystems, "c_sys5")

# test isempty when VirtualLODF is created (cache must be empty)
vlodf = VirtualLODF(sys)
@test isempty(vlodf) == true

# test eachindex and axes
@test length(eachindex(vlodf)) ==
length(axes(vlodf)[1]) * length(axes(vlodf)[2])

Expand All @@ -119,4 +121,16 @@ end
end
end
@test test_value

# test show
test_value = false
try
show(vlodf)
test_value = true
catch err
if err isa Exception
test_value = false
end
end
@test test_value
end
12 changes: 12 additions & 0 deletions test/test_virtual_ptdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,16 @@ end
@test setdiff(PNM.get_branch_ax(vptdf), PSY.get_name.(PNM.get_ac_branches(sys))) ==
String[]
@test setdiff(PNM.get_bus_ax(vptdf), PSY.get_number.(PNM.get_buses(sys))) == String[]

# test show
test_value = false
try
show(vptdf)
test_value = true
catch err
if err isa Exception
test_value = false
end
end
@test test_value
end

0 comments on commit 966c1c3

Please sign in to comment.