Skip to content

Commit 082a39e

Browse files
committed
typo in make new variable
1 parent 1ab6ccf commit 082a39e

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

src/utils.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ function is_variable(x)
6060
end
6161

6262
"""
63-
new_derived_named_parameter(variable, value, extra::String, suffix = true)
63+
new_derived_named_parameter(variable, value, extra::String, prefix = true)
6464
6565
If `value isa Num` return `value`.
66-
If `value isa `[`LiteralParameter`](@ref), replace it with its literal value.
66+
If `value isa LiteralParameter`, replace it with its literal value.
6767
Otherwise, create a new MTK `@parameter`
68-
whose name is created from `variable` by adding the `extra` string.
69-
If `suffix == true` the extra is added at the end after a `_`. Otherwise
68+
whose name is created from `variable` (which could also be just a `Symbol`) by adding the `extra` string.
69+
If `prefix == false` the `extra` is added at the end after a `_`. Otherwise
7070
it is added at the start, then a `_` and then the variable name.
7171
7272
For example,
@@ -79,9 +79,9 @@ Now `p` will be a parameter with name `:τ_x` and default value `0.5`.
7979
"""
8080
new_derived_named_parameter(v, value::Num, args...) = value
8181
new_derived_named_parameter(v, value::LiteralParameter, args...) = value.p
82-
function new_derived_named_parameter(v, value::Real, extra, suffix = true)
82+
function new_derived_named_parameter(v, value::Real, extra, prefix = true)
8383
n = string(ModelingToolkit.getname(v))
84-
newstring = if suffix
84+
newstring = if !(prefix)
8585
n*"_"*extra
8686
else
8787
extra*"_"*n

test/runtests.jl

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@ end
132132
@testset "derived" begin
133133
@variables x(t) = 0.5
134134
p = new_derived_named_parameter(x, 0.2, "t")
135-
@test ModelingToolkit.getname(p) == :x_t
135+
@test ModelingToolkit.getname(p) == :t_x
136136
@test default_value(p) == 0.2
137+
p = new_derived_named_parameter(x, 0.2, "t", false)
138+
@test ModelingToolkit.getname(p) == :x_t
137139
end
138140

139141
@testset "convert" begin
@@ -158,6 +160,9 @@ end
158160
@test p == 0.5
159161
end
160162

163+
164+
@testset "new named var"
165+
161166
end
162167

163168
@testset "default processes" begin

0 commit comments

Comments
 (0)