Commit 7848cc5a authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

parse out and test specially marked time math

Closes #54
parent 03e08215
......@@ -24,7 +24,16 @@ pointer to `ASTNode_t`.
"""
function parse_math(ast::VPtr)::Math
if ast_is(ast, :ASTNode_isName)
return MathIdent(get_string(ast, :ASTNode_getName))
if ccall(sbml(:ASTNode_getType), Cint, (VPtr,), ast) == 262
# This is a special case checking for the value of "simulation
# time" as defined by SBML. The constant `262` is the value of the
# enum AST_NAME_TIME in `libsbml/src/sbml/math/ASTNodeType.h`,
# needs to be kept up to date with the library (otherwise this
# breaks).
return MathTime(get_string(ast, :ASTNode_getName))
else
return MathIdent(get_string(ast, :ASTNode_getName))
end
elseif ast_is(ast, :ASTNode_isConstant)
return MathConst(get_string(ast, :ASTNode_getName))
elseif ast_is(ast, :ASTNode_isInteger)
......
......@@ -82,6 +82,14 @@ struct MathConst <: Math
id::String
end
"""
A special value representing the current time of the simulation, with a special
name.
"""
struct MathTime <: Math
id::String
end
"""
Function application ("call by name", no tricks allowed) in mathematical expression
"""
......
......@@ -24,6 +24,14 @@ sbmlfiles = [
2,
6,
),
# a cool model with `time` from SBML testsuite
(
"sbml00852.xml",
"https://raw.githubusercontent.com/sbmlteam/sbml-test-suite/master/cases/semantic/00852/00852-sbml-l3v2.xml",
"d013765aa358d265941420c2e3d81fcbc24b0aa4e9f39a8dc8852debd1addb60",
4,
3,
),
]
@testset "Loading of models from various sources" begin
......@@ -49,3 +57,14 @@ sbmlfiles = [
end
end
end
@testset "Time variables in math" begin
# this test is here mainly for keeping a magical constant that we need for
# parsing time synced with libsbml source
contains_time(x::SBML.MathTime) = true
contains_time(x::SBML.MathApply) = any(contains_time.(x.args))
contains_time(_) = false
m = readSBML("sbml00852.xml")
@test all(contains_time.(r.kinetic_math for (_, r) in m.reactions))
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment