OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace / tests / query / IsClosedUTest.cxxtest

100 lines · cxxtest ref:
/*
 * tests/query/IsClosedUTest.cxxtest
 *
 * Copyright (C) 2020 SingularityNET Foundation
 * All Rights Reserved
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License v3 as
 * published by the Free Software Foundation and including the exceptions
 * at http://opencog.org/wiki/Licenses
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program; if not, write to:
 * Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

#include <opencog/guile/SchemeEval.h>
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/util/Logger.h>

using namespace opencog;

class IsClosedUTest : public CxxTest::TestSuite
{
private:
	AtomSpacePtr as;
	SchemeEval* eval;

public:
	IsClosedUTest(void)
	{
		logger().set_level(Logger::DEBUG);
		logger().set_print_to_stdout_flag(true);

		as = createAtomSpace();
		eval = SchemeEval::get_scheme_evaluator(as);
		eval->eval("(add-to-load-path \"" PROJECT_SOURCE_DIR "\")");
	}

	~IsClosedUTest()
	{
		// Erase the log file if no assertions failed.
		if (!CxxTest::TestTracker::tracker().suiteFailed())
			std::remove(logger().get_filename().c_str());
	}

	void setUp(void);
	void tearDown(void);

	void test_basic_is_closed(void);
};

void IsClosedUTest::tearDown(void)
{
}

void IsClosedUTest::setUp(void)
{
}

/*
 * Basic IsClosedLink unit test. The atomspace contains 2 atoms, one
 * closed
 *
 * (Inheritance (Concept "A") (Concept "B"))
 *
 * one open
 *
 * (Inheritance (Concept "A") (Variable "$freevar"))
 *
 * querying such atomspace with the condition that the candidates are
 * closed should return only the first atom.
 */
void IsClosedUTest::test_basic_is_closed(void)
{
	logger().debug("BEGIN TEST: %s", __FUNCTION__);

	eval->eval("(load-from-path \"tests/query/is_closed.scm\")");

	Handle query = eval->eval_h("query");
	Handle closed_query = eval->eval_h("closed-query");

	ValuePtr results = query->execute();
	ValuePtr closed_results = closed_query->execute();

	logger().debug() << "results = " << oc_to_string(results);
	logger().debug() << "closed_results = " << oc_to_string(closed_results);

	TS_ASSERT_EQUALS(2, results->size());
	TS_ASSERT_EQUALS(1, closed_results->size());

	logger().debug("END TEST: %s", __FUNCTION__);
}