Skip to content

Commit

Permalink
improve testing and docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jd-lara committed Nov 29, 2023
1 parent d400498 commit 41fc858
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/InfrastructureSystems.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ Optional interface functions:
- get_uuid()
Subtypes may contain time series. Which requires
- get_time_series_container()
- get_time_series_container()
"""
abstract type InfrastructureSystemsInfo <: InfrastructureSystemsType end

Expand Down
8 changes: 7 additions & 1 deletion src/utils/test.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ mutable struct AdditionalTestComponent <: InfrastructureSystemsComponent
end

function TestComponent(name, val)
return TestComponent(name, val, TimeSeriesContainer(), InfosContainer(), InfrastructureSystemsInternal())
return TestComponent(
name,
val,
TimeSeriesContainer(),
InfosContainer(),
InfrastructureSystemsInternal(),
)
end

function AdditionalTestComponent(name, val)
Expand Down
66 changes: 58 additions & 8 deletions test/test_infos.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,72 @@
@testset "Test add_info" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
IS.add_info!(container, geo_info)
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)
@test length(container.data) == 1
@test length(container.data[IS.InfrastructureSystemsGeo]) == 1
@test IS.get_num_infos(container) == 1
@test_throws ArgumentError IS.add_info!(container, geo_info, component)

container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
@test_throws ArgumentError IS._add_info!(container, geo_info)
end

@testset "Test clear_infos" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)
@test IS.get_num_infos(container) == 1

IS.clear_infos!(component)
@test isempty(IS.get_components_uuid(geo_info))
IS.clear_infos!(container)
infos = IS.get_infos(IS.InfrastructureSystemsGeo, container)
@test length(infos) == 0
end

@testset "Test remove_info" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)
@test IS.get_num_infos(container) == 1

@test_throws ArgumentError IS.add_component!(container, component)
IS.remove_info!(component, geo_info)
@test isempty(IS.get_infos_container(component))
@test isempty(IS.get_components_uuid(geo_info))
end

struct BadComponent
name::AbstractString
val::Int
@testset "Test iterate_Infos" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)

i = 0
for component in IS.iterate_infos(container)
i += 1
end
@test i == 1
end

container = IS.Components(IS.InMemoryTimeSeriesStorage())
component = BadComponent("component1", 5)
@test_throws MethodError IS.add_component!(container, component)
@testset "Summarize Infos" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)
summary(devnull, container)
end

@testset "Test infos serialization" begin
container = IS.Infos(IS.InMemoryTimeSeriesStorage())
geo_info = IS.InfrastructureSystemsGeo()
component = IS.TestComponent("component1", 5)
IS.add_info!(container, geo_info, component)
data = IS.serialize(container)
@test data isa Vector
@test !isempty(data)
@test data[1] isa Dict
end

0 comments on commit 41fc858

Please sign in to comment.