Skip to content

Commit 235b599

Browse files
committed
test: add more tests with reaction having only reagents or products
1 parent 8d79a7d commit 235b599

File tree

2 files changed

+248
-1
lines changed

2 files changed

+248
-1
lines changed

__tests__/__snapshots__/reaction.test.ts.snap

Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,167 @@ OCL_RXN_V1.0:!####
152152
0 0
153153
"
154154
`;
155+
156+
exports[`Reaction class > toRXN options keepIdCode one product 1`] = `
157+
"$RXN
158+
159+
160+
161+
0 1
162+
$MOL
163+
164+
Actelion Java MolfileCreator 1.0
165+
166+
3 2 0 0 0 0 0 0 0 0999 V2000
167+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
168+
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
169+
2.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
170+
1 2 2 0 0 0 0
171+
2 3 2 0 0 0 0
172+
M END
173+
"
174+
`;
175+
176+
exports[`Reaction class > toRXN options keepIdCode one product 2`] = `
177+
"$RXN
178+
Hello world!
179+
180+
OCL_RXN_V1.0:!eMDARU@##!R_?y??kH@@@##
181+
0 1
182+
$MOL
183+
184+
Actelion Java MolfileCreator 1.0
185+
186+
3 2 0 0 0 0 0 0 0 0999 V2000
187+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
188+
1.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
189+
2.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
190+
1 2 2 0 0 0 0
191+
2 3 2 0 0 0 0
192+
M END
193+
"
194+
`;
195+
196+
exports[`Reaction class > toRXN options keepIdCode one reagent 1`] = `
197+
"$RXN
198+
199+
200+
201+
1 0
202+
$MOL
203+
204+
Actelion Java MolfileCreator 1.0
205+
206+
1 0 0 0 0 0 0 0 0 0999 V2000
207+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
208+
M END
209+
"
210+
`;
211+
212+
exports[`Reaction class > toRXN options keepIdCode one reagent 2`] = `
213+
"$RXN
214+
Hello world!
215+
216+
OCL_RXN_V1.0:fH@@!##!RGP@@##
217+
1 0
218+
$MOL
219+
220+
Actelion Java MolfileCreator 1.0
221+
222+
1 0 0 0 0 0 0 0 0 0999 V2000
223+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
224+
M END
225+
"
226+
`;
227+
228+
exports[`Reaction class > toRXN options keepIdCode two products 1`] = `
229+
"$RXN
230+
231+
232+
233+
0 2
234+
$MOL
235+
236+
Actelion Java MolfileCreator 1.0
237+
238+
1 0 0 0 0 0 0 0 0 0999 V2000
239+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
240+
M END
241+
$MOL
242+
243+
Actelion Java MolfileCreator 1.0
244+
245+
1 0 0 0 0 0 0 0 0 0999 V2000
246+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
247+
M END
248+
"
249+
`;
250+
251+
exports[`Reaction class > toRXN options keepIdCode two products 2`] = `
252+
"$RXN
253+
Hello world!
254+
255+
OCL_RXN_V1.0:!fH@@ fI@@##!RGP@@ !RGP@@##
256+
0 2
257+
$MOL
258+
259+
Actelion Java MolfileCreator 1.0
260+
261+
1 0 0 0 0 0 0 0 0 0999 V2000
262+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
263+
M END
264+
$MOL
265+
266+
Actelion Java MolfileCreator 1.0
267+
268+
1 0 0 0 0 0 0 0 0 0999 V2000
269+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
270+
M END
271+
"
272+
`;
273+
274+
exports[`Reaction class > toRXN options keepIdCode two reagents 1`] = `
275+
"$RXN
276+
277+
278+
279+
2 0
280+
$MOL
281+
282+
Actelion Java MolfileCreator 1.0
283+
284+
1 0 0 0 0 0 0 0 0 0999 V2000
285+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
286+
M END
287+
$MOL
288+
289+
Actelion Java MolfileCreator 1.0
290+
291+
1 0 0 0 0 0 0 0 0 0999 V2000
292+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
293+
M END
294+
"
295+
`;
296+
297+
exports[`Reaction class > toRXN options keepIdCode two reagents 2`] = `
298+
"$RXN
299+
Hello world!
300+
301+
OCL_RXN_V1.0:fH@@ fI@@!##!RGP@@ !RGP@@##
302+
2 0
303+
$MOL
304+
305+
Actelion Java MolfileCreator 1.0
306+
307+
1 0 0 0 0 0 0 0 0 0999 V2000
308+
0.0000 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0 0 0 0
309+
M END
310+
$MOL
311+
312+
Actelion Java MolfileCreator 1.0
313+
314+
1 0 0 0 0 0 0 0 0 0999 V2000
315+
0.0000 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0 0 0 0
316+
M END
317+
"
318+
`;

__tests__/reaction.test.ts

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,90 @@ describe('Reaction class', () => {
4343
keepIdCode: true,
4444
programName: 'Hello world!',
4545
});
46-
// this test could fail once this bug is fixed: https://github.com/Actelion/openchemlib/issues/158
46+
expect(rxn2).toMatchSnapshot();
47+
});
48+
49+
it('toRXN options keepIdCode one reagent', () => {
50+
const reaction = Reaction.create();
51+
const methane = Molecule.fromSmiles('C');
52+
reaction.addReactant(methane);
53+
expect(reaction.getReactants()).toBe(1);
54+
expect(reaction.getProducts()).toBe(0);
55+
expect(reaction.getCatalysts()).toBe(0);
56+
const rxn = reaction.toRxn();
57+
expect(rxn).toMatchSnapshot();
58+
const reaction2 = Reaction.fromRxn(rxn);
59+
expect(reaction2.getReactants()).toBe(1);
60+
expect(reaction2.getProducts()).toBe(0);
61+
expect(reaction2.getCatalysts()).toBe(0);
62+
const rxn2 = reaction2.toRxn({
63+
keepIdCode: true,
64+
programName: 'Hello world!',
65+
});
66+
expect(rxn2).toMatchSnapshot();
67+
});
68+
69+
it('toRXN options keepIdCode two reagents', () => {
70+
const reaction = Reaction.create();
71+
const methane = Molecule.fromSmiles('C');
72+
const oxygen = Molecule.fromSmiles('O');
73+
reaction.addReactant(methane);
74+
reaction.addReactant(oxygen);
75+
expect(reaction.getReactants()).toBe(2);
76+
expect(reaction.getProducts()).toBe(0);
77+
expect(reaction.getCatalysts()).toBe(0);
78+
const rxn = reaction.toRxn();
79+
expect(rxn).toMatchSnapshot();
80+
const reaction2 = Reaction.fromRxn(rxn);
81+
expect(reaction2.getReactants()).toBe(2);
82+
expect(reaction2.getProducts()).toBe(0);
83+
expect(reaction2.getCatalysts()).toBe(0);
84+
const rxn2 = reaction2.toRxn({
85+
keepIdCode: true,
86+
programName: 'Hello world!',
87+
});
88+
expect(rxn2).toMatchSnapshot();
89+
});
90+
91+
it('toRXN options keepIdCode one product', () => {
92+
const reaction = Reaction.create();
93+
const carbonDioxide = Molecule.fromSmiles('O=C=O');
94+
reaction.addProduct(carbonDioxide);
95+
expect(reaction.getReactants()).toBe(0);
96+
expect(reaction.getProducts()).toBe(1);
97+
expect(reaction.getCatalysts()).toBe(0);
98+
const rxn = reaction.toRxn();
99+
expect(rxn).toMatchSnapshot();
100+
const reaction2 = Reaction.fromRxn(rxn);
101+
expect(reaction2.getReactants()).toBe(0);
102+
expect(reaction2.getProducts()).toBe(1);
103+
expect(reaction2.getCatalysts()).toBe(0);
104+
const rxn2 = reaction2.toRxn({
105+
keepIdCode: true,
106+
programName: 'Hello world!',
107+
});
108+
expect(rxn2).toMatchSnapshot();
109+
});
110+
111+
it('toRXN options keepIdCode two products', () => {
112+
const reaction = Reaction.create();
113+
const carbon = Molecule.fromSmiles('C');
114+
reaction.addProduct(carbon);
115+
const oxygen = Molecule.fromSmiles('O');
116+
reaction.addProduct(oxygen);
117+
expect(reaction.getReactants()).toBe(0);
118+
expect(reaction.getProducts()).toBe(2);
119+
expect(reaction.getCatalysts()).toBe(0);
120+
const rxn = reaction.toRxn();
121+
expect(rxn).toMatchSnapshot();
122+
const reaction2 = Reaction.fromRxn(rxn);
123+
expect(reaction2.getReactants()).toBe(0);
124+
expect(reaction2.getProducts()).toBe(2);
125+
expect(reaction2.getCatalysts()).toBe(0);
126+
const rxn2 = reaction2.toRxn({
127+
keepIdCode: true,
128+
programName: 'Hello world!',
129+
});
47130
expect(rxn2).toMatchSnapshot();
48131
});
49132

0 commit comments

Comments
 (0)