1function y = testReadFromFile5(silent)
2
3filename = fullfile(pwd,'test-data', 'l2v1-assignment.xml');
4
5m = TranslateSBML(filename);
6
7test = 64;
8Totalfail = 0;
9
10Totalfail = Totalfail + fail_unless(m.SBML_level == 2);
11Totalfail = Totalfail + fail_unless(m.SBML_version == 1);
12
13%   //
14%   // <listOfCompartments>
15%   //   <compartment id="cell"/>
16%   // </listOfCompartments>
17%   //
18  Totalfail = Totalfail + fail_unless( length(m.compartment) == 1);
19
20  Totalfail = Totalfail + fail_unless( strcmp(m.compartment.id, 'cell'));
21
22%   //
23%   // <listOfSpecies>
24%   //   <species id="X0" compartment="cell" initialConcentration="1"/>
25%   //   <species id="X1" compartment="cell" initialConcentration="0"/>
26%   //   <species id="T"  compartment="cell" initialConcentration="0"/>
27%   //   <species id="S1" compartment="cell" initialConcentration="0"/>
28%   //   <species id="S2" compartment="cell" initialConcentration="0"/>
29%   // </listOfSpecies>
30%   //
31
32  Totalfail = Totalfail + fail_unless( length(m.species) == 5);
33
34  Totalfail = Totalfail + fail_unless( strcmp( m.species(1).id, 'X0'             ));
35  Totalfail = Totalfail + fail_unless( strcmp( m.species(1).compartment, 'cell' ));
36  Totalfail = Totalfail + fail_unless( m.species(1).initialConcentration == 1);
37  Totalfail = Totalfail + fail_unless( m.species(1).boundaryCondition == 0);
38
39  Totalfail = Totalfail + fail_unless( strcmp( m.species(2).id, 'X1'             ));
40  Totalfail = Totalfail + fail_unless( strcmp( m.species(2).compartment, 'cell' ));
41  Totalfail = Totalfail + fail_unless( m.species(2).initialConcentration == 0);
42  Totalfail = Totalfail + fail_unless( m.species(2).boundaryCondition == 0);
43
44  Totalfail = Totalfail + fail_unless( strcmp( m.species(3).id, 'T'             ));
45  Totalfail = Totalfail + fail_unless( strcmp( m.species(3).compartment, 'cell' ));
46  Totalfail = Totalfail + fail_unless( m.species(3).initialConcentration == 0);
47  Totalfail = Totalfail + fail_unless( m.species(3).boundaryCondition == 0);
48
49  Totalfail = Totalfail + fail_unless( strcmp( m.species(4).id, 'S1'             ));
50  Totalfail = Totalfail + fail_unless( strcmp( m.species(4).compartment, 'cell' ));
51  Totalfail = Totalfail + fail_unless( m.species(4).initialConcentration == 0);
52  Totalfail = Totalfail + fail_unless( m.species(4).boundaryCondition == 0);
53
54  Totalfail = Totalfail + fail_unless( strcmp( m.species(5).id, 'S2'             ));
55  Totalfail = Totalfail + fail_unless( strcmp( m.species(5).compartment, 'cell' ));
56  Totalfail = Totalfail + fail_unless( m.species(5).initialConcentration == 0);
57  Totalfail = Totalfail + fail_unless( m.species(5).boundaryCondition == 0);
58
59%   //
60%   // <listOfParameters>
61%   //   <parameter id="Keq" value="2.5"/>
62%   // </listOfParameters>
63%   //
64  Totalfail = Totalfail + fail_unless( length(m.parameter) == 1);
65
66  Totalfail = Totalfail + fail_unless( strcmp( m.parameter(1).id, 'Keq'             ));
67  Totalfail = Totalfail + fail_unless( m.parameter(1).value == 2.5);
68
69%   //
70%   // <listOfRules> ... </listOfRules>
71%   //
72
73  Totalfail = Totalfail + fail_unless( length(m.rule) == 2);
74
75%     //
76%   // <assignmentRule variable="S1">
77%   //   <math xmlns="http://www.w3.org/1998/Math/MathML">
78%   //     <apply>
79%   //       <divide/>
80%   //       <ci> T </ci>
81%   //       <apply>
82%   //         <plus/>
83%   //         <cn> 1 </cn>
84%   //         <ci> Keq </ci>
85%   //       </apply>
86%   //     </apply>
87%   //   </math>
88%   // </assignmentRule>
89%   //
90
91  Totalfail = Totalfail + fail_unless( strcmp( m.rule(1).typecode, 'SBML_ASSIGNMENT_RULE'             ));
92  Totalfail = Totalfail + fail_unless( strcmp( m.rule(1).variable, 'S1'             ));
93  Totalfail = Totalfail + fail_unless( strcmp( m.rule(1).formula, 'T/(1+Keq)'             ));
94
95%   //
96%   // <assignmentRule variable="S2">
97%   //   <math xmlns="http://www.w3.org/1998/Math/MathML">
98%   //     <apply>
99%   //       <times/>
100%   //       <ci> Keq </ci>
101%   //       <ci> S1 </ci>
102%   //     </apply>
103%   //   </math>
104%   // </assignmentRule>
105%   //
106  Totalfail = Totalfail + fail_unless( strcmp( m.rule(2).typecode, 'SBML_ASSIGNMENT_RULE'             ));
107  Totalfail = Totalfail + fail_unless( strcmp( m.rule(2).variable, 'S2'             ));
108  Totalfail = Totalfail + fail_unless( strcmp( m.rule(2).formula, 'Keq*S1'             ));
109
110%   //
111%   // <listOfReactions> ... </listOfReactions>
112%   //
113
114  Totalfail = Totalfail + fail_unless( length(m.reaction) == 2);
115
116%   //
117%   // <reaction id="in">
118%   //   <listOfReactants>
119%   //     <speciesReference species="X0"/>
120%   //   </listOfReactants>
121%   //   <listOfProducts>
122%   //     <speciesReference species="T"/>
123%   //   </listOfProducts>
124%   //   <kineticLaw>
125%   //     <math xmlns="http://www.w3.org/1998/Math/MathML">
126%   //       <apply>
127%   //         <times/>
128%   //         <ci> k1 </ci>
129%   //         <ci> X0 </ci>
130%   //       </apply>
131%   //     </math>
132%   //     <listOfParameters>
133%   //       <parameter id="k1" value="0.1"/>
134%   //     </listOfParameters>
135%   //   </kineticLaw>
136%   // </reaction>
137%   //
138  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(1).id, 'in'));
139  Totalfail = Totalfail + fail_unless( m.reaction(1).reversible ~= 0);
140
141  Totalfail = Totalfail + fail_unless( length(m.reaction(1).reactant) == 1);
142  Totalfail = Totalfail + fail_unless( length(m.reaction(1).product)  == 1);
143
144  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(1).reactant.species, 'X0'));
145  Totalfail = Totalfail + fail_unless( m.reaction(1).reactant.stoichiometry == 1);
146  Totalfail = Totalfail + fail_unless( m.reaction(1).reactant.denominator == 1);
147
148  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(1).product.species, 'T'));
149  Totalfail = Totalfail + fail_unless( m.reaction(1).product.stoichiometry == 1);
150  Totalfail = Totalfail + fail_unless( m.reaction(1).product.denominator == 1);
151
152  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(1).kineticLaw.formula, 'k1*X0'));
153  Totalfail = Totalfail + fail_unless(length(m.reaction(1).kineticLaw.parameter) == 1);
154
155  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(1).kineticLaw.parameter.id, 'k1'));
156  Totalfail = Totalfail + fail_unless( m.reaction(1).kineticLaw.parameter.value == 0.1);
157
158%  //
159%   // <reaction id="out">
160%   //   <listOfReactants>
161%   //     <speciesReference species="T"/>
162%   //   </listOfReactants>
163%   //   <listOfProducts>
164%   //     <speciesReference species="X1"/>
165%   //   </listOfProducts>
166%   //   <kineticLaw>
167%   //     <math xmlns="http://www.w3.org/1998/Math/MathML">
168%   //       <apply>
169%   //         <times/>
170%   //         <ci> k2 </ci>
171%   //         <ci> S2 </ci>
172%   //       </apply>
173%   //     </math>
174%   //     <listOfParameters>
175%   //       <parameter id="k2" value="0.15"/>
176%   //     </listOfParameters>
177%   //   </kineticLaw>
178%   // </reaction>
179%   //
180  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(2).id, 'out'));
181  Totalfail = Totalfail + fail_unless( m.reaction(2).reversible ~= 0);
182
183  Totalfail = Totalfail + fail_unless( length(m.reaction(2).reactant) == 1);
184  Totalfail = Totalfail + fail_unless( length(m.reaction(2).product)  == 1);
185
186  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(2).reactant.species, 'T'));
187  Totalfail = Totalfail + fail_unless( m.reaction(2).reactant.stoichiometry == 1);
188  Totalfail = Totalfail + fail_unless( m.reaction(2).reactant.denominator == 1);
189
190  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(2).product.species, 'X1'));
191  Totalfail = Totalfail + fail_unless( m.reaction(2).product.stoichiometry == 1);
192  Totalfail = Totalfail + fail_unless( m.reaction(2).product.denominator == 1);
193
194  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(2).kineticLaw.formula, 'k2*X1'));
195  Totalfail = Totalfail + fail_unless(length(m.reaction(2).kineticLaw.parameter) == 1);
196
197  Totalfail = Totalfail + fail_unless( strcmp(m.reaction(2).kineticLaw.parameter.id, 'k2'));
198  Totalfail = Totalfail + fail_unless( m.reaction(2).kineticLaw.parameter.value == 0.15);
199
200
201if (silent == 0)
202disp('Testing readFromFile5:');
203disp(sprintf('Number tests: %d', test));
204disp(sprintf('Number fails: %d', Totalfail));
205disp(sprintf('Pass rate: %d%%\n', ((test-Totalfail)/test)*100));
206end;
207
208if (Totalfail == 0)
209    y = 0;
210else
211    y = 1;
212end;
213
214function y = fail_unless(arg)
215
216if (~arg)
217    y = 1;
218else
219    y = 0;
220end;
221
222