mirror of
https://github.com/rdkit/rdkit.git
synced 2026-06-04 21:54:27 +08:00
* do not use new on loggers * del pointers in testDistGeom * Update Dict hasNonPOD status on bulk update * delete new Dicts in memtest1.cpp * fixes in MolSuppliers and testFMCS * PeriodicTable singleton as unique_ptr * fix EEM_arrays leak * fix leaks in testPBF * fix ParamCollection leak in test UFF * fix leaks in MMFF * clear prop dict before read in in pickler * fix leaks in testFreeSASA * fix leaks in test3D * modernize Dict.h & SmilesParse.cpp * fix leaks in testQuery * fix leaks in testCrystalFF * fix leaks in cxsmilesTest * fix leaks in Catalog & mol cat test * fix leaks in ShapeUtils & tests * fix leaks in testSubgraphs1 * fix leaks testFingerprintGenerators * fix leaks in Catalog/FilterCatalog * fix leaks in graphmolqueryTest * these changes reduce bison parse leaks * fixed leaks in testChirality.cpp * fix leaks + 2 tests in testMolWriter * fix 4m leaks in substructLibraryTest * small improvements to molTautomerTest; still leaks * fix leaks in testRGroupDecomp * fix leaks in test; parser still leaks * fix leaks in itertest * fix 4m leaks in testDepictor * fixes in smatest; still leaking due to parser * fixes in testSLNParse; still leaking due to parser * flex/bison: always add atoms with ownership; smarts error cleanup * fix leaks in testReaction * fix leaks in testSubstructMatch * fix leaks in resMolSupplierTest * fix leaks in testChemTransforms + bug in ChemTransforms * fix leaks in testPickler * fix leaks in testMolTransform * fix leaks in testFragCatalog * fix leak in testSLNParse. Still leaks due to Smiles * fixed most leaks in testMolSupplier * pre bison fix * fix some atom & bond parse problems; others still fail * bison smiles & smarts, atoms & bonds more or less fixed * fix leaks in molopstest.cpp * fix leaks in testFingerprints, MACCS.cpp & AtomPairs.cpp * fix leaks in moldraw2Dtest1 * fix leaks in testDescriptors * fix leaks in testInchi * fix leaks in testUFFForceFieldHelpers * fix leaks in hanoiTest & new_canon.h * fix leaks in testMMFFForceField * fix leaks in graphmolTest1 * fix leaks in testMMFFForceFieldHelpers * fix leaks in testDistGeomHelpers * fix leaks in testMolAlign * initialize occupancy & temp facto with default values * fix leak in TautomerTransform * updated suppressions * fix testStructChecker * fix logging & py tests * fix TautomerTransform class/struct issue * remove misplaced delete in testSLNParse * deinit in testAvalonLib1 * fix Avalon-triggered(?) bug in StructChecker/Pattern.cpp * fix random testMolWriter/Supplier fails - diversify output file names to avoid clashing. - unify Writers close/destruct behavior. - flushing/closing in tests. * use reset in FFs Params.cpp * comments on testMMFFForceField * unrequired 'if's added to mol suppliers * correct cast in FilterCatalog.h * use unique_ptr in MACCS Patterns * remove unrequred if in new_canon * update & move suppressions
310 lines
7.5 KiB
C++
310 lines
7.5 KiB
C++
// $Id$
|
|
//
|
|
// Copyright (c) 2003-2006 Greg Landrum and Rational Discovery LLC
|
|
//
|
|
// @@ All Rights Reserved @@
|
|
// This file is part of the RDKit.
|
|
// The contents are covered by the terms of the BSD license
|
|
// which is included in the file license.txt, found at the root
|
|
// of the RDKit source tree.
|
|
//
|
|
|
|
#include <RDGeneral/test.h>
|
|
#include "QueryObjects.h"
|
|
#include <iostream>
|
|
#include <math.h>
|
|
#include <boost/lexical_cast.hpp>
|
|
|
|
using namespace std;
|
|
using namespace Queries;
|
|
|
|
void test1() {
|
|
cout << "Float" << endl;
|
|
EqualityQuery<double> q(1.0);
|
|
|
|
CHECK_INVARIANT(!q.Match(0.0), "");
|
|
CHECK_INVARIANT(q.Match(1.0), "");
|
|
CHECK_INVARIANT(!q.Match(1.001), "");
|
|
CHECK_INVARIANT(!q.Match(1.1), "");
|
|
CHECK_INVARIANT(!q.Match(-2), "");
|
|
|
|
cout << "With Tolerance" << endl;
|
|
q.setTol(0.002);
|
|
CHECK_INVARIANT(!q.Match(0.0), "");
|
|
CHECK_INVARIANT(q.Match(1.0), "");
|
|
CHECK_INVARIANT(q.Match(1.001), "");
|
|
CHECK_INVARIANT(!q.Match(1.1), "");
|
|
CHECK_INVARIANT(!q.Match(-2), "");
|
|
|
|
Query<double> *newQ;
|
|
newQ = q.copy();
|
|
CHECK_INVARIANT(!newQ->Match(0.0), "");
|
|
CHECK_INVARIANT(newQ->Match(1.0), "");
|
|
CHECK_INVARIANT(newQ->Match(1.001), "");
|
|
CHECK_INVARIANT(!newQ->Match(1.1), "");
|
|
CHECK_INVARIANT(!newQ->Match(-2), "");
|
|
delete newQ;
|
|
}
|
|
|
|
|
|
void test2() {
|
|
cout << "Set" << endl;
|
|
SetQuery<int> q;
|
|
q.insert(1);
|
|
q.insert(3);
|
|
q.insert(5);
|
|
|
|
CHECK_INVARIANT(!q.Match(0), "");
|
|
CHECK_INVARIANT(q.Match(1), "");
|
|
CHECK_INVARIANT(q.Match(3), "");
|
|
CHECK_INVARIANT(!q.Match(-3), "");
|
|
|
|
Query<int> *newQ;
|
|
newQ = q.copy();
|
|
CHECK_INVARIANT(!newQ->Match(0), "");
|
|
CHECK_INVARIANT(newQ->Match(1), "");
|
|
CHECK_INVARIANT(newQ->Match(3), "");
|
|
CHECK_INVARIANT(!newQ->Match(-3), "");
|
|
delete newQ;
|
|
}
|
|
|
|
void test3() {
|
|
cout << "And" << endl;
|
|
auto *q = new AndQuery<int>;
|
|
auto *l = new LessQuery<int>;
|
|
l->setVal(0);
|
|
auto *g = new GreaterEqualQuery<int>;
|
|
g->setVal(3);
|
|
|
|
q->addChild(Query<int>::CHILD_TYPE(l));
|
|
q->addChild(Query<int>::CHILD_TYPE(g));
|
|
|
|
CHECK_INVARIANT(!q->Match(0), "");
|
|
CHECK_INVARIANT(q->Match(1), "");
|
|
CHECK_INVARIANT(q->Match(3), "");
|
|
CHECK_INVARIANT(!q->Match(-3), "");
|
|
|
|
Query<int> *newQ;
|
|
newQ = q->copy();
|
|
CHECK_INVARIANT(!newQ->Match(0), "");
|
|
CHECK_INVARIANT(newQ->Match(1), "");
|
|
CHECK_INVARIANT(newQ->Match(3), "");
|
|
CHECK_INVARIANT(!newQ->Match(-3), "");
|
|
|
|
delete newQ;
|
|
delete q;
|
|
}
|
|
|
|
void test4() {
|
|
cout << "Or" << endl;
|
|
auto *q = new OrQuery<int>;
|
|
auto *l = new LessQuery<int>;
|
|
l->setVal(0);
|
|
auto *g = new GreaterEqualQuery<int>;
|
|
g->setVal(3);
|
|
|
|
q->addChild(Query<int>::CHILD_TYPE(l));
|
|
q->addChild(Query<int>::CHILD_TYPE(g));
|
|
|
|
CHECK_INVARIANT(q->Match(0), "");
|
|
CHECK_INVARIANT(q->Match(1), "");
|
|
CHECK_INVARIANT(q->Match(3), "");
|
|
CHECK_INVARIANT(q->Match(-3), "");
|
|
|
|
Query<int> *newQ;
|
|
newQ = q->copy();
|
|
CHECK_INVARIANT(newQ->Match(0), "");
|
|
CHECK_INVARIANT(newQ->Match(1), "");
|
|
CHECK_INVARIANT(newQ->Match(3), "");
|
|
CHECK_INVARIANT(newQ->Match(-3), "");
|
|
|
|
delete newQ;
|
|
delete q;
|
|
}
|
|
|
|
void test5() {
|
|
cout << "XOr" << endl;
|
|
auto *q = new XOrQuery<int>;
|
|
auto *l = new LessQuery<int>;
|
|
l->setVal(0);
|
|
auto *g = new GreaterEqualQuery<int>;
|
|
g->setVal(3);
|
|
|
|
q->addChild(Query<int>::CHILD_TYPE(l));
|
|
q->addChild(Query<int>::CHILD_TYPE(g));
|
|
|
|
CHECK_INVARIANT(q->Match(-1), "");
|
|
CHECK_INVARIANT(q->Match(0), "");
|
|
CHECK_INVARIANT(!q->Match(1), "");
|
|
CHECK_INVARIANT(!q->Match(3), "");
|
|
CHECK_INVARIANT(q->Match(-3), "");
|
|
|
|
Query<int> *newQ;
|
|
newQ = q->copy();
|
|
CHECK_INVARIANT(newQ->Match(-1), "");
|
|
CHECK_INVARIANT(newQ->Match(0), "");
|
|
CHECK_INVARIANT(!newQ->Match(1), "");
|
|
CHECK_INVARIANT(!newQ->Match(3), "");
|
|
CHECK_INVARIANT(newQ->Match(-3), "");
|
|
|
|
delete newQ;
|
|
delete q;
|
|
}
|
|
|
|
int foofun(double bar) { return int(floor(bar)); };
|
|
|
|
void test6() {
|
|
cout << "pointer and copy foo" << endl;
|
|
EqualityQuery<int, double, true> q;
|
|
q.setDataFunc(foofun);
|
|
q.setVal(6);
|
|
CHECK_INVARIANT(q.Match(6.0), "");
|
|
CHECK_INVARIANT(q.Match(6.1), "");
|
|
CHECK_INVARIANT(!q.Match(5.0), "");
|
|
|
|
Query<int, double, true> *newQ;
|
|
newQ = q.copy();
|
|
CHECK_INVARIANT(newQ->Match(6.0), "");
|
|
CHECK_INVARIANT(newQ->Match(6.1), "");
|
|
CHECK_INVARIANT(!newQ->Match(5.0), "");
|
|
|
|
Query<int, double, true> *newQ2 = &q;
|
|
CHECK_INVARIANT(newQ2->Match(6.0), "");
|
|
CHECK_INVARIANT(newQ2->Match(6.1), "");
|
|
CHECK_INVARIANT(!newQ2->Match(5.0), "");
|
|
|
|
Query<int, double, true> *newQ3;
|
|
newQ3 = newQ2->copy();
|
|
CHECK_INVARIANT(newQ3->Match(6.0), "");
|
|
CHECK_INVARIANT(newQ3->Match(6.1), "");
|
|
CHECK_INVARIANT(!newQ3->Match(5.0), "");
|
|
|
|
delete newQ;
|
|
delete newQ3;
|
|
}
|
|
|
|
bool matchF(int v) { return v == 3; }
|
|
|
|
int dataF(float v) { return int(floor(v)) * 3; }
|
|
|
|
bool cmp(int v) { return v < 3; }
|
|
|
|
void basics1() {
|
|
cout << "Query" << endl;
|
|
Query<int, float, true> q;
|
|
q.setMatchFunc(matchF);
|
|
q.setDataFunc(dataF);
|
|
|
|
CHECK_INVARIANT(!q.Match(0.0), "");
|
|
CHECK_INVARIANT(q.Match(1.0), "");
|
|
CHECK_INVARIANT(q.Match(1.1), "");
|
|
CHECK_INVARIANT(!q.Match(-2.0), "");
|
|
|
|
TEST_ASSERT(!q.getMatchFunc()(0));
|
|
TEST_ASSERT(q.getMatchFunc()(3));
|
|
TEST_ASSERT(q.getDataFunc()(1.0) == dataF(1.0));
|
|
|
|
cout << "Query2" << endl;
|
|
Query<bool, int, true> q2;
|
|
q2.setDataFunc(cmp);
|
|
CHECK_INVARIANT(q2.Match(0), "");
|
|
CHECK_INVARIANT(q2.Match(1), "");
|
|
CHECK_INVARIANT(!q2.Match(3), "");
|
|
CHECK_INVARIANT(!q2.Match(4), "");
|
|
CHECK_INVARIANT(!q2.Match(4.0), "");
|
|
}
|
|
|
|
void basics2() {
|
|
cout << "Equality" << endl;
|
|
EqualityQuery<int> q2;
|
|
q2.setVal(3);
|
|
CHECK_INVARIANT(!q2.Match(0), "");
|
|
CHECK_INVARIANT(!q2.Match(1), "");
|
|
CHECK_INVARIANT(q2.Match(3), "");
|
|
CHECK_INVARIANT(!q2.Match(-3), "");
|
|
|
|
cout << "Greater" << endl;
|
|
GreaterQuery<int> q3;
|
|
q3.setVal(3);
|
|
CHECK_INVARIANT(q3.Match(0), "");
|
|
CHECK_INVARIANT(q3.Match(1), "");
|
|
CHECK_INVARIANT(!q3.Match(3), "");
|
|
CHECK_INVARIANT(!q3.Match(5), "");
|
|
|
|
cout << "GreaterEqual" << endl;
|
|
GreaterEqualQuery<int> q4(3);
|
|
CHECK_INVARIANT(q4.Match(0), "");
|
|
CHECK_INVARIANT(q4.Match(1), "");
|
|
CHECK_INVARIANT(q4.Match(3), "");
|
|
CHECK_INVARIANT(!q4.Match(5), "");
|
|
|
|
cout << "Less" << endl;
|
|
LessQuery<int> q5;
|
|
q5.setVal(3);
|
|
CHECK_INVARIANT(!q5.Match(0), "");
|
|
CHECK_INVARIANT(!q5.Match(1), "");
|
|
CHECK_INVARIANT(!q5.Match(3), "");
|
|
CHECK_INVARIANT(q5.Match(5), "");
|
|
|
|
cout << "LessEqual" << endl;
|
|
LessEqualQuery<int> q6(3);
|
|
|
|
CHECK_INVARIANT(!q6.Match(0), "");
|
|
CHECK_INVARIANT(!q6.Match(1), "");
|
|
CHECK_INVARIANT(q6.Match(3), "");
|
|
CHECK_INVARIANT(q6.Match(5), "");
|
|
|
|
cout << "Open Range" << endl;
|
|
RangeQuery<int> q7(0, 3);
|
|
CHECK_INVARIANT(!q7.Match(0), "");
|
|
CHECK_INVARIANT(q7.Match(1), "");
|
|
CHECK_INVARIANT(!q7.Match(3), "");
|
|
CHECK_INVARIANT(!q7.Match(5), "");
|
|
|
|
cout << "Closed Range" << endl;
|
|
q7.setEndsOpen(false, false);
|
|
CHECK_INVARIANT(q7.Match(0), "");
|
|
CHECK_INVARIANT(q7.Match(1), "");
|
|
CHECK_INVARIANT(q7.Match(3), "");
|
|
CHECK_INVARIANT(!q7.Match(5), "");
|
|
}
|
|
|
|
int convFunc(const char *arg) { return boost::lexical_cast<int>(arg); };
|
|
|
|
void test7() {
|
|
cout << "Set2" << endl;
|
|
SetQuery<int, const char *, true> q;
|
|
q.setDataFunc(convFunc);
|
|
q.insert(1);
|
|
q.insert(3);
|
|
q.insert(5);
|
|
|
|
CHECK_INVARIANT(!q.Match("0"), "");
|
|
CHECK_INVARIANT(q.Match("1"), "");
|
|
CHECK_INVARIANT(q.Match("3"), "");
|
|
CHECK_INVARIANT(!q.Match("-3"), "");
|
|
|
|
Query<int, const char *, true> *newQ;
|
|
newQ = q.copy();
|
|
CHECK_INVARIANT(!newQ->Match("0"), "");
|
|
CHECK_INVARIANT(newQ->Match("1"), "");
|
|
CHECK_INVARIANT(newQ->Match("3"), "");
|
|
CHECK_INVARIANT(!newQ->Match("-3"), "");
|
|
|
|
delete newQ;
|
|
}
|
|
|
|
int main() {
|
|
basics1();
|
|
basics2();
|
|
|
|
test1();
|
|
test2();
|
|
test3();
|
|
test4();
|
|
test5();
|
|
test6();
|
|
test7();
|
|
return 0;
|
|
}
|