Skip to content

Commit

Permalink
make component selector tests pass
Browse files Browse the repository at this point in the history
  • Loading branch information
tengis-nrl committed Mar 24, 2024
1 parent 92bd5e8 commit a72bb5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
16 changes: 12 additions & 4 deletions src/component_selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ function get_components(e::SingleComponentSelector, sys::System)
end

# ListComponentSelector
#Construction
select_components(content::ComponentSelector...; name::Union{String, Nothing} = nothing) =
IS.select_components(content...; name)

#Contents
function get_components(e::ListComponentSelector, sys::System)
sub_components = Iterators.map(x -> get_components(x, sys), e.content)
Expand All @@ -33,6 +37,10 @@ function get_components(e::ListComponentSelector, sys::System)
)
end

function get_subselectors(e::ListComponentSelector)
return IS.get_subselectors(e)
end

# SubtypeComponentSelector
# Construction
"""
Expand All @@ -43,15 +51,15 @@ ComponentSelectorSet.
select_components(
component_subtype::Type{<:Component};
name::Union{String, Nothing} = nothing,
) = IS.select_components(component_subtype, name)
) = IS.select_components(component_subtype; name)

# Contents
function get_subselectors(e::SubtypeComponentSelector, sys::System)
return IS.get_subselectors(e, sys.data)
return Iterators.map(select_components, get_components(e, sys))
end

function get_components(e::SubtypeComponentSelector, sys::System)
return Iterators.filter(get_available, get_components(e.component_subtype, sys.data))
return Iterators.filter(get_available, IS.get_components(e.component_subtype, sys.data))
end

# FilterComponentSelector
Expand All @@ -71,7 +79,7 @@ end

# Contents
function get_subselectors(e::FilterComponentSelector, sys::System)
return IS.get_subselectors(e, sys.data)
return Iterators.map(select_components, get_components(e, sys))
end

function get_components(e::FilterComponentSelector, sys::System)
Expand Down
4 changes: 2 additions & 2 deletions test/test_component_selector.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ end
@test get_component(ThermalStandard, test_sys, "Solitude") in the_components
@test get_component(RenewableDispatch, test_sys, "WindBusA") in the_components

@test collect(get_subselectors(select_components(), test_sys)) ==
@test collect(get_subselectors(select_components())) ==
Vector{ComponentSelector}()
the_subselectors = collect(get_subselectors(test_list_ent, test_sys))
the_subselectors = collect(get_subselectors(test_list_ent))
@test length(the_subselectors) == 2
@test comp_ent_1 in the_subselectors
@test comp_ent_2 in the_subselectors
Expand Down

0 comments on commit a72bb5e

Please sign in to comment.