Skip to content

Commit c55c3a4

Browse files
committed
Add unit tests
1 parent c15d53f commit c55c3a4

2 files changed

Lines changed: 141 additions & 3 deletions

File tree

INCHI-1-SRC/INCHI_BASE/src/strutil.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,14 @@ extern "C"
114114

115115
/**
116116
* @nnuk
117-
*
117+
*
118118
* @brief Determine whether a metal-ligand bond must always be preserved
119-
* during Molecular Inorganics preprocessing. Some description on
119+
* during Molecular Inorganics preprocessing. The metal ligand
120+
* bond must always be kept when the neighbour is another metal
121+
* atom or the bond is Coordinative bond or the bond type is
122+
* greater than 1.
123+
*
124+
* Some description on
120125
* how InChI sees the bond types:
121126
* Bond type 1 = Single Bond
122127
* Bond type 2 = Double Bond
@@ -138,7 +143,7 @@ extern "C"
138143
int metal_idx,
139144
int neigh_idx,
140145
int bond_pos);
141-
146+
142147
/**
143148
* @brief Set the enhanced stereochemistry for t- and m-layers
144149
*

INCHI-1-TEST/tests/test_unit/test_molecularInorganics.cpp

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,136 @@ M END)";
324324

325325
FreeINCHI(poutput);
326326
}
327+
328+
TEST(test_molecularInorganics, test_MI_Na_H2O_CoordBond)
329+
{
330+
const char* molblock = R"(
331+
ACCLDraw06092610472D
332+
333+
0 0 0 0 0 999 V3000
334+
M V30 BEGIN CTAB
335+
M V30 COUNTS 2 1 0 0 0
336+
M V30 BEGIN ATOM
337+
M V30 1 O 3.3082 -5.8926 0 0 VAL=1
338+
M V30 2 Na 2.2853 -6.4832 0 0
339+
M V30 END ATOM
340+
M V30 BEGIN BOND
341+
M V30 1 9 1 2
342+
M V30 END BOND
343+
M V30 END CTAB
344+
M END
345+
)";
346+
347+
char options[] = "-MolecularInorganics";
348+
inchi_Output output;
349+
inchi_Output* poutput = &output;
350+
memset(poutput, 0, sizeof(*poutput));
351+
352+
const char expected_inchi[] = "InChI=1B/Na.H2O/h;1H2/q+1;/p-1";
353+
354+
EXPECT_EQ(MakeINCHIFromMolfileText(molblock, options, poutput), 1);
355+
EXPECT_STREQ(poutput->szInChI, expected_inchi);
356+
357+
FreeINCHI(poutput);
358+
}
359+
360+
TEST(test_molecularInorganics, test_MI_Na_H2O_CoordBond_Charged)
361+
{
362+
const char* molblock = R"(
363+
ACCLDraw06092610502D
364+
365+
0 0 0 0 0 999 V3000
366+
M V30 BEGIN CTAB
367+
M V30 COUNTS 2 1 0 0 0
368+
M V30 BEGIN ATOM
369+
M V30 1 Na 1.9415 -11.2332 0 0 CHG=1
370+
M V30 2 O 2.9644 -10.6426 0 0 CHG=-1
371+
M V30 END ATOM
372+
M V30 BEGIN BOND
373+
M V30 1 9 2 1
374+
M V30 END BOND
375+
M V30 END CTAB
376+
M END
377+
)";
378+
379+
char options[] = "-MolecularInorganics";
380+
inchi_Output output;
381+
inchi_Output* poutput = &output;
382+
memset(poutput, 0, sizeof(*poutput));
383+
384+
const char expected_inchi[] = "InChI=1B/Na.H2O/h;1H2/q+1;/p-1";
385+
386+
EXPECT_EQ(MakeINCHIFromMolfileText(molblock, options, poutput), 1);
387+
EXPECT_STREQ(poutput->szInChI, expected_inchi);
388+
389+
FreeINCHI(poutput);
390+
}
391+
392+
TEST(test_molecularInorganics, test_MI_Na_Methoxide_Charged)
393+
{
394+
const char molblock[] = R"(
395+
ACCLDraw06092600112D
396+
397+
0 0 0 0 0 999 V3000
398+
M V30 BEGIN CTAB
399+
M V30 COUNTS 3 2 0 0 0
400+
M V30 BEGIN ATOM
401+
M V30 1 Na 3.2848 -9.6749 0 0 CHG=1
402+
M V30 2 O 4.3077 -9.0843 0 0 CHG=-1
403+
M V30 3 C 5.3309 -9.675 0 0
404+
M V30 END ATOM
405+
M V30 BEGIN BOND
406+
M V30 1 9 2 1
407+
M V30 2 1 2 3
408+
M V30 END BOND
409+
M V30 END CTAB
410+
M END
411+
)";
412+
413+
char options[] = "-MolecularInorganics";
414+
inchi_Output output;
415+
inchi_Output* poutput = &output;
416+
memset(poutput, 0, sizeof(*poutput));
417+
418+
const char expected_inchi[] = "InChI=1B/CH3O.Na/c1-2;/h1H3;/q-1;+1";
419+
420+
EXPECT_EQ(MakeINCHIFromMolfileText(molblock, options, poutput), 1);
421+
EXPECT_STREQ(poutput->szInChI, expected_inchi);
422+
423+
FreeINCHI(poutput);
424+
}
425+
426+
TEST(test_molecularInorganics, test_MI_Na_Methoxide_Valence1)
427+
{
428+
const char molblock[] = R"(
429+
ACCLDraw06092600112D
430+
431+
0 0 0 0 0 999 V3000
432+
M V30 BEGIN CTAB
433+
M V30 COUNTS 3 2 0 0 0
434+
M V30 BEGIN ATOM
435+
M V30 1 Na 3.5661 -6.1124 0 0
436+
M V30 2 O 4.589 -5.5218 0 0 VAL=1
437+
M V30 3 C 5.6121 -6.1125 0 0
438+
M V30 END ATOM
439+
M V30 BEGIN BOND
440+
M V30 1 9 2 1
441+
M V30 2 1 2 3
442+
M V30 END BOND
443+
M V30 END CTAB
444+
M END
445+
)";
446+
447+
char options[] = "-MolecularInorganics";
448+
inchi_Output output;
449+
inchi_Output* poutput = &output;
450+
memset(poutput, 0, sizeof(*poutput));
451+
452+
const char expected_inchi[] = "InChI=1B/CH3O.Na/c1-2;/h1H3;/q-1;+1";
453+
454+
EXPECT_EQ(MakeINCHIFromMolfileText(molblock, options, poutput), 1);
455+
EXPECT_STREQ(poutput->szInChI, expected_inchi);
456+
457+
FreeINCHI(poutput);
458+
}
459+

0 commit comments

Comments
 (0)