|
| 1 | +/* |
| 2 | + * tests/query/AnchorUTest.cxxtest |
| 3 | + * |
| 4 | + * Copyright (C) 2020 Linas Vepstas |
| 5 | + * All Rights Reserved |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify |
| 8 | + * it under the terms of the GNU Affero General Public License v3 as |
| 9 | + * published by the Free Software Foundation and including the exceptions |
| 10 | + * at http://opencog.org/wiki/Licenses |
| 11 | + * |
| 12 | + * This program is distributed in the hope that it will be useful, |
| 13 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | + * GNU General Public License for more details. |
| 16 | + * |
| 17 | + * You should have received a copy of the GNU Affero General Public License |
| 18 | + * along with this program; if not, write to: |
| 19 | + * Free Software Foundation, Inc., |
| 20 | + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 21 | + */ |
| 22 | + |
| 23 | +#include <thread> |
| 24 | + |
| 25 | +#include <opencog/guile/SchemeEval.h> |
| 26 | +#include <opencog/atoms/truthvalue/SimpleTruthValue.h> |
| 27 | +#include <opencog/atomspace/AtomSpace.h> |
| 28 | +#include <opencog/util/Logger.h> |
| 29 | +#include <cxxtest/TestSuite.h> |
| 30 | + |
| 31 | +using namespace opencog; |
| 32 | + |
| 33 | +#define al as->add_link |
| 34 | +#define an as->add_node |
| 35 | + |
| 36 | +class AnchorUTest: public CxxTest::TestSuite |
| 37 | +{ |
| 38 | +private: |
| 39 | + AtomSpace* as; |
| 40 | + |
| 41 | +public: |
| 42 | + AnchorUTest(void) |
| 43 | + { |
| 44 | + // logger().set_level(Logger::FINE); |
| 45 | + logger().set_print_to_stdout_flag(true); |
| 46 | + logger().set_timestamp_flag(false); |
| 47 | + |
| 48 | + as = new AtomSpace(); |
| 49 | + SchemeEval* eval = SchemeEval::get_evaluator(as); |
| 50 | + eval->eval("(use-modules (opencog exec))"); |
| 51 | + eval->eval("(add-to-load-path \"" PROJECT_SOURCE_DIR "\")"); |
| 52 | + } |
| 53 | + |
| 54 | + ~AnchorUTest() |
| 55 | + { |
| 56 | + delete as; |
| 57 | + // Erase the log file if no assertions failed. |
| 58 | + if (!CxxTest::TestTracker::tracker().suiteFailed()) |
| 59 | + std::remove(logger().get_filename().c_str()); |
| 60 | + } |
| 61 | + |
| 62 | + void setUp(void); |
| 63 | + void tearDown(void); |
| 64 | + |
| 65 | + void Setter(void); |
| 66 | + void Getter(void); |
| 67 | + |
| 68 | + void test_get(void); |
| 69 | + void test_bind(void); |
| 70 | + void xtest_dual(void); |
| 71 | +}; |
| 72 | + |
| 73 | +void AnchorUTest::tearDown(void) |
| 74 | +{ |
| 75 | +} |
| 76 | + |
| 77 | +void AnchorUTest::setUp(void) |
| 78 | +{ |
| 79 | +} |
| 80 | + |
| 81 | +/* |
| 82 | + * GetLink unit test. |
| 83 | + */ |
| 84 | +void AnchorUTest::test_get(void) |
| 85 | +{ |
| 86 | + logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 87 | + |
| 88 | + SchemeEval* eval = SchemeEval::get_evaluator(as); |
| 89 | + eval->eval("(load-from-path \"tests/query/anchor.scm\")"); |
| 90 | + |
| 91 | + Handle anchor = eval->eval_h("(cog-execute! getli)"); |
| 92 | + |
| 93 | + IncomingSet results = anchor->getIncomingSetByType(MEMBER_LINK); |
| 94 | + |
| 95 | + TSM_ASSERT_EQUALS("Expecting three answers", results.size(), 3); |
| 96 | + |
| 97 | + logger().debug("END TEST: %s", __FUNCTION__); |
| 98 | +} |
| 99 | + |
| 100 | +/* |
| 101 | + * BindLink unit test. |
| 102 | + */ |
| 103 | +void AnchorUTest::test_bind(void) |
| 104 | +{ |
| 105 | + logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 106 | + |
| 107 | + SchemeEval* eval = SchemeEval::get_evaluator(as); |
| 108 | + eval->eval("(load-from-path \"tests/query/anchor.scm\")"); |
| 109 | + |
| 110 | + Handle anchor = eval->eval_h("(cog-execute! bindli)"); |
| 111 | + |
| 112 | + IncomingSet results = anchor->getIncomingSetByType(MEMBER_LINK); |
| 113 | + |
| 114 | + TSM_ASSERT_EQUALS("Expecting three answers", results.size(), 3); |
| 115 | + |
| 116 | + logger().debug("END TEST: %s", __FUNCTION__); |
| 117 | +} |
| 118 | + |
| 119 | +/* |
| 120 | + * DualLink unit test. |
| 121 | + * XXX FIXME -- there is currently no documented way of squeezing |
| 122 | + * an AnchorNode into an SRAI search, and so the unit test below |
| 123 | + * canot possibly pass until that design issue is fixed... |
| 124 | + */ |
| 125 | +void AnchorUTest::xtest_dual(void) |
| 126 | +{ |
| 127 | + logger().debug("BEGIN TEST: %s", __FUNCTION__); |
| 128 | + |
| 129 | + SchemeEval* eval = SchemeEval::get_evaluator(as); |
| 130 | + eval->eval("(load-from-path \"tests/query/anchor.scm\")"); |
| 131 | + |
| 132 | + Handle anchor = eval->eval_h("(cog-execute! (Dual srai))"); |
| 133 | + |
| 134 | + IncomingSet results = anchor->getIncomingSetByType(MEMBER_LINK); |
| 135 | + |
| 136 | + TSM_ASSERT_EQUALS("Expecting two answers", results.size(), 2); |
| 137 | + |
| 138 | + logger().debug("END TEST: %s", __FUNCTION__); |
| 139 | +} |
0 commit comments