OverviewFilesCommitsIssuesDocsReleasesPeers

opencog-atomspace / tests / atoms / pattern / SatisfactionLinkUTest.cxxtest

84 lines · cxxtest ref:
/*
 * tests/atoms/pattern/SatisfactionLinkUTest.cxxtest
 *
 * Copyright (C) 2019 Linas Vepstas
 * 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/util/Logger.h>
#include <opencog/atomspace/AtomSpace.h>
#include <opencog/atoms/pattern/SatisfactionLink.h>
#include <opencog/atoms/atom_types/atom_names.h>
#include <opencog/atoms/value/BoolValue.h>

#include <cxxtest/TestSuite.h>

using namespace opencog;

// Test SatisfactionLink
//
class SatisfactionLinkUTest: public CxxTest::TestSuite
{
private:
	AtomSpacePtr _as;

public:
	SatisfactionLinkUTest()
	{
		logger().set_print_to_stdout_flag(true);
		logger().set_level(Logger::INFO);
		logger().set_timestamp_flag(false);
		_as = createAtomSpace();
	}

	void setUp() {}

	void tearDown() {}

	void test_execution();
};

/**
 * Test to make sure the SatsifactionLink is executable.
 * Just a basic test, to make sure it compiles and runs.
 */
void SatisfactionLinkUTest::test_execution()
{
	logger().info("BEGIN TEST: %s", __FUNCTION__);

	Handle have_colors = _as->add_atom(
		Satisfaction(
			Variable ("$color"),
			Inheritance(
				Variable ("$color"),
				Concept ("Color"))));

	TS_ASSERT(have_colors->is_executable());
	ValuePtr vp = have_colors->execute();
	BoolValuePtr bvp = BoolValueCast(vp);
	TS_ASSERT(not bvp->get_bit(0));

	_as->add_atom(Inheritance(Concept("red"), Concept("Color")));
	_as->add_atom(Inheritance(Concept("green"), Concept("Color")));
	_as->add_atom(Inheritance(Concept("blue"), Concept("Color")));

	vp = have_colors->execute();
	bvp = BoolValueCast(vp);
	TS_ASSERT(bvp->get_bit(0));
}