1 //
2 //  Copyright (C) 2018 Novartis Institutes Of BioMedical Research
3 //
4 //   @@ All Rights Reserved @@
5 //  This file is part of the RDKit.
6 //  The contents are covered by the terms of the BSD license
7 //  which is included in the file license.txt, found at the root
8 //  of the RDKit source tree.
9 //
10 
11 #include <RDGeneral/test.h>
12 #include <GraphMol/RDKitBase.h>
13 #include <GraphMol/MonomerInfo.h>
14 #include <GraphMol/RDKitQueries.h>
15 #include <RDGeneral/types.h>
16 #include <RDGeneral/RDLog.h>
17 #include <GraphMol/FileParsers/FileParsers.h>
18 #include <GraphMol/FileParsers/MolWriters.h>
19 #include <GraphMol/SmilesParse/SmilesParse.h>
20 #include <GraphMol/SmilesParse/SmilesWrite.h>
21 #include <sstream>
22 #include <iostream>
23 
24 using namespace std;
25 using namespace RDKit;
26 
27 // memory tests for valgrind
testRemoveAtomBond(RWMol & m,int atomidx,int bondidx)28 void testRemoveAtomBond(RWMol &m, int atomidx, int bondidx) {
29   const Bond *b = m.getBondWithIdx(bondidx);
30   if (bondidx >= 0) {
31     m.removeBond(b->getBeginAtomIdx(), b->getEndAtomIdx());
32   }
33   if (atomidx >= 0) {
34     m.removeAtom(atomidx);
35   }
36 }
37 
testRemovals(RWMol m)38 void testRemovals(RWMol m) {
39   for (unsigned int i = 0; i < m.getNumAtoms() / 2; i++) {
40     int atomidx = (i % 2 == 0) ? m.getNumAtoms() - 1 : 0;
41     int bondidx = (i % 2 == 0) ? m.getNumBonds() - 1 : 0;
42     testRemoveAtomBond(m, atomidx, bondidx);
43   }
44 }
45 
test1()46 void test1() {
47   std::string smi = "CCC";
48   for (int i = 4; i < 20; ++i) {
49     smi += "C";
50     RWMol *m = SmilesToMol(smi.c_str());
51     testRemovals(*m);
52     delete m;
53   }
54 }
55 
test2()56 void test2() {
57   std::string smi = "CCC";
58   auto m = std::unique_ptr<ROMol>(SmilesToMol(smi));
59   for (const auto at : m->atoms()) {
60     TEST_ASSERT(at->getAtomicNum() == 6);
61   }
62   for (const auto bnd : m->bonds()) {
63     TEST_ASSERT(bnd->getBondType() == Bond::SINGLE);
64   }
65 }
66 
testCopyConstructor()67 void testCopyConstructor() {
68   RDKit::RWMol mol1;
69   RDKit::RWMol mol2(mol1);
70   RDKit::RWMol mol3;
71   mol3 = mol2;
72 }
73 
74 // -------------------------------------------------------------------
main()75 int main() {
76   RDLog::InitLogs();
77   // boost::logging::enable_logs("rdApp.info");
78   test1();
79   testCopyConstructor();
80   return 0;
81 }
82