From bfe0a5a2ef4611da45d12b13cd0650c60732f5a7 Mon Sep 17 00:00:00 2001 From: Boyan Bejanov Date: Tue, 11 Jul 2023 11:50:52 -0400 Subject: [PATCH] rename get_main_equation to find_main_equation + doc string --- src/model.jl | 10 ++++++++-- test/runtests.jl | 8 ++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/model.jl b/src/model.jl index 2399092..236983f 100644 --- a/src/model.jl +++ b/src/model.jl @@ -1624,7 +1624,13 @@ function findequations(model::Model, sym::Symbol; verbose=true) return sym_eqs end -function get_main_equation(model::Model, var::Symbol) +""" + find_main_equation(model, var) + +Return the name of the first equation that contains `var[t]`. Return `nothing` +if there's no such equation. +""" +function find_main_equation(model::Model, var::Symbol) for (eqn_name, eqn) in pairs(model.equations) for (t, sym) in eqn.tsrefs if t[1].name == var && t[2] == 0 @@ -1634,7 +1640,7 @@ function get_main_equation(model::Model, var::Symbol) end return nothing end -export get_main_equation +export find_main_equation """ prettyprint_equation(m::Model, eq::Equation; target::Symbol, eq_symbols::Vector{Any}=[]) diff --git a/test/runtests.jl b/test/runtests.jl index 9156199..00e3b04 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1449,13 +1449,13 @@ m2_for_sattelite_tests = nothing @testset "Model find" begin m = E3.newmodel() - findequations(m, :cr) - @test length(findequations(m, :cr)) == 1 - @test length(findequations(m, :pinf)) == 3 + findequations(m, :cr; verbose=false) + @test length(findequations(m, :cr; verbose=false)) == 1 + @test length(findequations(m, :pinf; verbose=false)) == 3 @test get_main_equation(m, :rate) == :_EQ2 - @test findequations(S1.model, :a) == [:_EQ1, :_SSEQ1] + @test findequations(S1.model, :a; verbose=false) == [:_EQ1, :_SSEQ1] end