Commit 591a1ece authored by Miroslav Kratochvil's avatar Miroslav Kratochvil
Browse files

tests now do tests

parent 77b605d4
...@@ -7,4 +7,5 @@ version = "0.1.0" ...@@ -7,4 +7,5 @@ version = "0.1.0"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb" Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
SBML_jll = "bb12108a-f4ef-5f88-8ef3-0b33ff7017f1" SBML_jll = "bb12108a-f4ef-5f88-8ef3-0b33ff7017f1"
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
...@@ -11,13 +11,11 @@ function readSBML(fn::String)::Model ...@@ -11,13 +11,11 @@ function readSBML(fn::String)::Model
try try
n_errs = ccall(sbml(:SBMLDocument_getNumErrors), Cuint, (VPtr,), doc) n_errs = ccall(sbml(:SBMLDocument_getNumErrors), Cuint, (VPtr,), doc)
if n_errs > 0 if n_errs > 0
@error "SBML loading failed" throw(SystemError("Opening SBML document has failed"))
throw(:IOError)
end end
if 0 == ccall(sbml(:SBMLDocument_isSetModel), Cint, (VPtr,), doc) if 0 == ccall(sbml(:SBMLDocument_isSetModel), Cint, (VPtr,), doc)
@error "SBML document does not contain a model" throw(AssertionError("SBML document contains no model"))
throw(:ValueError)
end end
model = ccall(sbml(:SBMLDocument_getModel), VPtr, (VPtr,), doc) model = ccall(sbml(:SBMLDocument_getModel), VPtr, (VPtr,), doc)
......
...@@ -5,15 +5,53 @@ if !isfile(sbmlfile) ...@@ -5,15 +5,53 @@ if !isfile(sbmlfile)
download("https://systemsbiology.ucsd.edu/sites/systemsbiology.ucsd.edu/files/Attachments/Images/InSilicoOrganisms/Ecoli/Ecoli_SBML/Ec_core_flux1.xml", sbmlfile) download("https://systemsbiology.ucsd.edu/sites/systemsbiology.ucsd.edu/files/Attachments/Images/InSilicoOrganisms/Ecoli/Ecoli_SBML/Ec_core_flux1.xml", sbmlfile)
end end
if bytes2hex(sha256(sbmlfile)) != "e3d18499660a0f7fc15a5a44f33f001c7881ac99a2e8a6a461edf1cf3d69a537"
@warn "The downloaded E Coli core flux model seems to be different from the expected one. Tests will likely fail."
end
@testset "SBML model loading" begin @testset "SBML model loading" begin
m = readSBML(sbmlfile) mdl = readSBML(sbmlfile)
@test typeof(mdl) == Model @test typeof(mdl) == Model
@test_throws :IOError readSBML(sbmlfile * ".does.not.really.exist") @test_throws SystemError readSBML(sbmlfile * ".does.not.really.exist")
@test length(mdl.compartments) == 2 @test length(mdl.compartments) == 2
mets, rxns, S = getS(mdl) mets, rxns, S = getS(mdl)
@test length(mets) == 77
@test length(rxns) == 77
@test size(S) == (length(mets),length(rxns))
# totally arbitrary value tests
@test isapprox(sum(S), 42.1479)
@test mets[10:12] == ["M_akg_e", "M_fum_c", "M_pyr_c"]
@test rxns[10:12] == ["R_H2Ot", "R_PGL", "R_EX_glc_e_"]
lbs = getLBs(mdl)
ubs = getUBs(mdl)
ocs = getOCs(mdl)
@test length(ocs) == length(mets)
@test ocs[40] == 1.0
deleteat!(ocs, 40)
@test all(ocs .== 0.0)
@test length(getLBs(mdl)) == length(rxns)
@test length(getUBs(mdl)) == length(rxns)
getunit = (val,unit)::Tuple -> unit
@test all([broadcast(getunit, lbs) broadcast(getunit, ubs)] .== "mmol_per_gDW_per_hr")
getval = (val,unit)::Tuple -> val
lvals = broadcast(getval, lbs)
uvals = broadcast(getval, ubs)
@test isapprox(lvals[27], uvals[27])
@test isapprox(lvals[27], 7.6)
@test isapprox(lvals[12], -10)
@test count(isapprox.(lvals, -999999)) == 40
@test count(isapprox.(lvals, 0)) == 35
@test count(isapprox.(uvals, 999999)) == 76
end end
using Test using Test, SHA
using SBML using SBML
import Pkg import Pkg
include("version.jl") @testset "SBML test suite" begin
include("loadEColi.jl") include("version.jl")
include("loadEColi.jl")
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