Skip to content

Commit

Permalink
Fix bug 407, test that
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Oct 28, 2024
1 parent 627c8dd commit 9fa405c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 26 deletions.
36 changes: 10 additions & 26 deletions src/utils/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ _fetch_match_fn(::Nothing) = isequivalent
# Whether to stop recursing and apply the match_fn
_is_compare_directly(::DataType, ::DataType) = true
_is_compare_directly(::T, ::U) where {T, U} = true
# As of 1.11, Arrays have fields we don't want to touch
_is_compare_directly(::T, ::T) where {T <: AbstractArray} = true

Check warning on line 130 in src/utils/utils.jl

View check run for this annotation

Codecov / codecov/patch

src/utils/utils.jl#L130

Added line #L130 was not covered by tests
_is_compare_directly(::T, ::T) where {T} = isempty(fieldnames(T))

"""
Expand Down Expand Up @@ -161,33 +163,15 @@ function compare_values(match_fn::Union{Function, Nothing}, x::T, y::U;
field_name in exclude && continue
val1 = getproperty(x, field_name)
val2 = getproperty(y, field_name)
if !isempty(fieldnames(typeof(val1)))
if !compare_values(
match_fn,
val1,
val2;
compare_uuids = compare_uuids,
exclude = exclude,
)
@error "values do not match" T field_name val1 val2
match = false
end
elseif val1 isa AbstractArray
if !compare_values(
match_fn,
val1,
val2;
compare_uuids = compare_uuids,
exclude = exclude,
)
@error "values do not match" T field_name val1 val2
match = false
end
sub_result = if _is_compare_directly(val1, val2)
_fetch_match_fn(match_fn)(val1, val2)
else
if !_fetch_match_fn(match_fn)(val1, val2)
@error "values do not match" T field_name val1 val2
match = false
end
compare_values(match_fn, val1, val2;
compare_uuids = compare_uuids, exclude = exclude)
end
if !sub_result
@error "values do not match" T field_name val1 val2
match = false
end
end

Expand Down
3 changes: 3 additions & 0 deletions test/test_system_data.jl
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ end
special1,
))
@test IS.compare_values(==, special1, special1)

# https://github.com/NREL-Sienna/InfrastructureSystems.jl/issues/407
@test InfrastructureSystems.compare_values([0 0], [0 0])
end

@testset "Test compression settings" begin
Expand Down

0 comments on commit 9fa405c

Please sign in to comment.