1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
|
//
// Copyright (C) 2004-2025 Greg Landrum and other RDKit contributors
//
// @@ 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 <catch2/catch_all.hpp>
#include <iostream>
#include <RDGeneral/Invariant.h>
#include <RDGeneral/utils.h>
#include <Geometry/point.h>
#include <Features/Feature.h>
using namespace RDKit;
using namespace RDGeom;
using namespace RDFeatures;
typedef enum {
fooType,
barType,
bazType,
grnType,
} TypeMarker;
TEST_CASE("Basics for ExplicitFeatures") {
ExplicitFeature<TypeMarker> f1;
f1.setFamily(bazType);
REQUIRE(f1.getFamily() == bazType);
f1.setType(grnType);
REQUIRE(f1.getType() == grnType);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1 = ExplicitFeature<TypeMarker>(barType, fooType);
REQUIRE(f1.getFamily() == barType);
REQUIRE(f1.getType() == fooType);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1 = ExplicitFeature<TypeMarker>(barType, fooType, Point3D(1.0, 2.0, 3.0));
REQUIRE(f1.getFamily() == barType);
REQUIRE(f1.getType() == fooType);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(1.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(2.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(3.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1.setLoc(Point3D(-1.0, -2.0, -3.0));
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(-1.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(-2.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(-3.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
}
TEST_CASE("Basics for ImplicitFeatures") {
ImplicitFeature<TypeMarker> f1;
f1.setType(fooType);
REQUIRE(f1.getType() == fooType);
f1.setType(grnType);
REQUIRE(f1.getType() == grnType);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1 = ImplicitFeature<TypeMarker>(barType, fooType);
REQUIRE(f1.getFamily() == barType);
REQUIRE(f1.getType() == fooType);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
Point3D p1(0, 0, 0), p2(1, 0, 0), p3(0, 1, 0);
f1.addPoint(&p1);
f1.addPoint(&p2);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.50, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
f1.addPoint(&p3);
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.3333, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.3333, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
f1.reset();
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().z, Catch::Matchers::WithinAbs(0.0, 1e-4));
}
TEST_CASE("ExplicitFeatures 2D, string type.") {
typedef ExplicitFeature<std::string, std::string, Point2D> LocalFeature;
LocalFeature f1;
f1.setType("foo");
REQUIRE(f1.getType() == "foo");
f1.setFamily("foob");
REQUIRE(f1.getFamily() == "foob");
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1 = LocalFeature("foo", "bar");
REQUIRE(f1.getFamily() == "foo");
REQUIRE(f1.getType() == "bar");
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(0.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1 = LocalFeature("grm", "grn", Point2D(1.0, 2.0));
REQUIRE(f1.getFamily() == "grm");
REQUIRE(f1.getType() == "grn");
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(1.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(2.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
f1.setLoc(Point2D(-1.0, -2.0));
REQUIRE_THAT(f1.getLoc().x, Catch::Matchers::WithinAbs(-1.0, 1e-4));
REQUIRE_THAT(f1.getLoc().y, Catch::Matchers::WithinAbs(-2.0, 1e-4));
REQUIRE(f1.getDirs().size() == 0);
}
|