Skip to content

Commit

Permalink
fix: import of vars into SymbolicUnits sybmodule
Browse files Browse the repository at this point in the history
  • Loading branch information
ven-k committed Feb 2, 2024
1 parent 3b6525f commit 192288c
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 15 deletions.
1 change: 0 additions & 1 deletion src/register_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ function update_all_values(name_symbol, unit)
ALL_MAPPING[name_symbol] = INDEX_TYPE(length(ALL_MAPPING) + 1)
end


# Register
macro register_unit(name, value)
return esc(_register_unit(name, value))
Expand Down
20 changes: 8 additions & 12 deletions src/symbolic_dimensions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ end
function SymbolicDimensionsSingleton{R}(s::Symbol) where {R}
i = get(ALL_MAPPING, s, INDEX_TYPE(0))
iszero(i) && error("$s is not available as a symbol in `SymbolicDimensionsSingleton`. Symbols available: $(ALL_SYMBOLS).")
SymbolicDimensionsSingleton{R}(i)
return SymbolicDimensionsSingleton{R}(i)
end

# Traits:
Expand Down Expand Up @@ -367,15 +367,14 @@ to enable pretty-printing of units.
"""
module SymbolicUnits


import ..UNIT_SYMBOLS
import ..CONSTANT_SYMBOLS
import ..SymbolicDimensionsSingleton
import ...constructorof
import ...DEFAULT_SYMBOLIC_QUANTITY_TYPE
import ...DEFAULT_SYMBOLIC_QUANTITY_OUTPUT_TYPE
import ...DEFAULT_VALUE_TYPE
import ...DEFAULT_DIM_BASE_TYPE
import ..DEFAULT_SYMBOLIC_QUANTITY_TYPE
import ..constructorof
import ..DEFAULT_SYMBOLIC_QUANTITY_OUTPUT_TYPE
import ..DEFAULT_VALUE_TYPE
import ..DEFAULT_DIM_BASE_TYPE

# Lazily create unit symbols (since there are so many)
module Constants
Expand All @@ -393,10 +392,7 @@ module SymbolicUnits
@eval begin
const $unit = constructorof(DEFAULT_SYMBOLIC_QUANTITY_TYPE)(
DEFAULT_VALUE_TYPE(1.0),
SymbolicDimensionsSingleton{DEFAULT_DIM_BASE_TYPE}(
$(QuoteNode(disambiguate_symbol(unit))),
),
)
SymbolicDimensionsSingleton{DEFAULT_DIM_BASE_TYPE}($(QuoteNode(disambiguate_symbol(unit)))))
push!(_SYMBOLIC_CONSTANT_VALUES, $unit)
end
end
Expand All @@ -412,7 +408,7 @@ module SymbolicUnits
@eval begin
const $unit = constructorof(DEFAULT_SYMBOLIC_QUANTITY_TYPE)(
DEFAULT_VALUE_TYPE(1.0),
SymbolicDimensionsSingleton{DEFAULT_DIM_BASE_TYPE}($(QuoteNode(unit))),
SymbolicDimensionsSingleton{DEFAULT_DIM_BASE_TYPE}($(QuoteNode(unit)))
)
push!($symbolic_unit_values, $unit)
end
Expand Down
3 changes: 3 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ else
@safetestset "Measurements.jl integration tests" begin
include("test_measurements.jl")
end
@safetestset "Meshes.jl integration tests" begin
include("test_meshes.jl")
end
@safetestset "Unit tests" begin
include("unittests.jl")
end
Expand Down
4 changes: 2 additions & 2 deletions test/unittests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -688,8 +688,8 @@ end
@test !iszero(sym)
end

q = 1.5us"km/s"
@test q == 1.5 * us"km" / us"s"
q = 1.5us"km/s"
@test q == 1.5 * us"km" / us"s"
@test typeof(q) <: with_type_parameters(DEFAULT_QUANTITY_TYPE, Float64, SymbolicDimensions{DEFAULT_DIM_BASE_TYPE})
@test string(dimension(q)) == "s⁻¹ km"
@test uexpand(q) == 1.5u"km/s"
Expand Down

0 comments on commit 192288c

Please sign in to comment.