Skip to content

Commit

Permalink
Fix downstream test
Browse files Browse the repository at this point in the history
NT.get_unit assumes DynamicQuantities, to use Unitful use
MT.UnitfulUnitCheck.get_unit.
  • Loading branch information
contradict committed Aug 30, 2024
1 parent 0c9cb7b commit 0cdba63
Showing 1 changed file with 37 additions and 13 deletions.
50 changes: 37 additions & 13 deletions test/downstream/modeling_toolkit_utils.jl
Original file line number Diff line number Diff line change
@@ -1,34 +1,58 @@
using Symbolics: diff2term
using ModelingToolkit
using ModelingToolkit: equivalent, get_unit, value, VariableUnit
using Unitful: @u_str
using ModelingToolkit: equivalent, get_unit, value, VariableUnit, UnitfulUnitCheck
using DynamicQuantities: @u_str as @du_str
using Unitful: @u_str as @uu_str
using Test

@variables t [unit = u"s"] k(t)
@variables t [unit = du"s"] k(t)
D = Differential(t)

@test equivalent(
u"1/s",
du"s^-1",
get_unit(
diff2term(
value(D(k)),
Dict(VariableUnit => get_unit(D(k)))
)
value(D(k)),
Dict(VariableUnit => get_unit(D(k)))
)
)
)

@test equivalent(
u"1/s^2",
du"s^-2",
get_unit(
diff2term(
value(D(D(k))),
Dict(VariableUnit => get_unit(D(D(k))))
)
value(D(D(k))),
Dict(VariableUnit => get_unit(D(D(k))))
)
)
)

@variables t [unit = uu"s"] k(t)
D = Differential(t)

@test equivalent(
uu"s^-1",
UnitfulUnitCheck.get_unit(
diff2term(
value(D(k)),
Dict(VariableUnit => UnitfulUnitCheck.get_unit(D(k)))
)
)
)

@test equivalent(
uu"s^-2",
UnitfulUnitCheck.get_unit(
diff2term(
value(D(D(k))),
Dict(VariableUnit => UnitfulUnitCheck.get_unit(D(D(k))))
)
)
)

@variables x y t
D = Differential(t)
Symbolics.diff2term(D(x))
Symbolics.diff2term(D(sqrt(sqrt(sqrt(+(x,y))))))
Symbolics.diff2term(D(x+y))
Symbolics.diff2term(D(sqrt(sqrt(sqrt(+(x, y))))))
Symbolics.diff2term(D(x + y))

0 comments on commit 0cdba63

Please sign in to comment.