From a17dac529db8d96b853752b36ed9782c50254178 Mon Sep 17 00:00:00 2001 From: Micah Halter Date: Fri, 18 Sep 2020 08:52:53 -0400 Subject: [PATCH] Road to 100% Code Coverage (#19) * Added a couple more tests to make up for missing code coverage * Added test for base iterate * Added some more tests * Added some more tests * last test addition * Version bump --- Project.toml | 2 +- src/Types.jl | 1 - test/types.jl | 38 +++++++++++++++++++++++++++++++++----- 3 files changed, 34 insertions(+), 7 deletions(-) diff --git a/Project.toml b/Project.toml index 0b691a8..c3e7019 100644 --- a/Project.toml +++ b/Project.toml @@ -2,7 +2,7 @@ name = "AlgebraicPetri" uuid = "4f99eebe-17bf-4e98-b6a1-2c4f205a959b" license = "MIT" authors = ["Micah Halter "] -version = "0.4.0" +version = "0.4.1" [deps] AutoHashEquals = "15f4f7f2-30c1-5605-9d31-71845cf9641f" diff --git a/src/Types.jl b/src/Types.jl index d7101ca..f1d148d 100644 --- a/src/Types.jl +++ b/src/Types.jl @@ -213,7 +213,6 @@ sname(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet},s) = subpa tname(p::Union{AbstractLabelledPetriNet, AbstractLabelledReactionNet},t) = subpart(p,t,:tname) vectorfield(pn::Union{AbstractLabelledPetriNet,AbstractLabelledReactionNet}) = begin - println("HELLO") tm = TransitionMatrices(pn) dt_T = transpose(tm.output - tm.input) f(du,u,p,t) = begin diff --git a/test/types.jl b/test/types.jl index 29f0827..73520d4 100644 --- a/test/types.jl +++ b/test/types.jl @@ -1,19 +1,47 @@ sir_petri = PetriNet(3, ((1, 2), (2, 2)), (2, 3)) sir_lpetri = LabelledPetriNet([:S, :I, :R], :inf=>((:S, :I), (:I, :I)), :rec=>(:I, :R)) -sir_rxn = ReactionNet{Number, Int}([990, 10, 0], (.0001)=>((1, 2)=>(2,2)), (.25)=>(2=>3)) -sir_lrxn = LabelledReactionNet{Number, Int}((:S=>990, :I=>10, :R=>0), (:inf, .0001)=>((:S, :I)=>(:I,:I)), (:rec, .25)=>(:I=>:R)) +β(u,t) = 1 / sum(u) +γ = .25 +sir_rxn = ReactionNet{Function, Int}([990, 10, 0], (β)=>((1, 2)=>(2,2)), (t->γ)=>(2=>3)) +sir_lrxn = LabelledReactionNet{Number, Int}((:S=>990, :I=>10, :R=>0), (:inf, .001)=>((:S, :I)=>(:I,:I)), (:rec, .25)=>(:I=>:R)) sir_tpetri= PetriNet(TransitionMatrices(sir_petri)) +next = iterate(PetriCospanOb(5)) +while next !== nothing + (i, state) = next + @test i == state && i <= 5 + global next = iterate(PetriCospanOb(5), state) +end + +pf = id(PetriFunctor) +@test pf.F(FinSet(3))(sir_petri) +@test !(pf.F(FinSet(5))(sir_petri)) + @test sir_tpetri == sir_petri @test Petri.Model(sir_petri) == Petri.Model(sir_rxn) @test Petri.Model(sir_lpetri) == Petri.Model(sir_lrxn) +@test concentration(sir_rxn, 1) == 990 +@test rate(sir_rxn, 1) == β + @test concentrations(sir_rxn) == [990, 10, 0] -@test rates(sir_rxn) == [.0001, .25] +@test typeof(rates(sir_rxn)) <: Array{Function} @test concentrations(sir_lrxn) == LVector(S=990, I=10, R=0) -@test rates(sir_lrxn) == LVector(inf=.0001, rec=.25) +@test rates(sir_lrxn) == LVector(inf=.001, rec=.25) + +du = [0.0, 0.0, 0.0] +out = vectorfield(sir_rxn)(du, concentrations(sir_rxn), rates(sir_rxn), 0.01) +@test out[1] ≈ -9.9 +@test out[2] ≈ 7.4 +@test out[3] ≈ 2.5 + +du = LVector(S=0.0, I=0.0, R=0.0) +out = vectorfield(sir_lrxn)(du, concentrations(sir_lrxn), rates(sir_lrxn), 0.01) +@test out.S ≈ -9.9 +@test out.I ≈ 7.4 +@test out.R ≈ 2.5 @test ns(sir_petri) == 3 add_species!(sir_petri) @@ -31,4 +59,4 @@ add_input!(sir_petri, 4, 4) add_output!(sir_petri, 4, 3) @test ni(sir_petri) == 5 @test no(sir_petri) == 5 -@test sir_petri == PetriNet(4, ((1, 2), (2, 2)), (2, 3), (1, 4), (4, 3)) +@test sir_petri == PetriNet(4, ((1, 2), (2, 2)), (2, 3), (1, 4), (4, 3)) \ No newline at end of file