Skip to content
Snippets Groups Projects
Select Git revision
  • 1fa58da1b3379a8869a5a38ff8dff03943332269
  • master default protected
  • vertical_relations
  • lu_without_semantic_frames
  • hierarchy
  • additional-unification-filters
  • v0.1.1
  • v0.1.0
  • v0.0.9
  • v0.0.8
  • v0.0.7
  • v0.0.6
  • v0.0.5
  • v0.0.4
  • v0.0.3
  • v0.0.2
  • v0.0.1
17 results

util.py

Blame
  • logicalpredicates.cpp 10.29 KiB
    #include <boost/test/unit_test.hpp>
    #include <boost/bind.hpp>
    #include <boost/shared_ptr.hpp>
    #include <libcorpus2/sentence.h>
    
    #include <libwccl/ops/functions/constant.h>
    #include <libwccl/ops/functions/bool/predicates/and.h>
    #include <libwccl/ops/functions/bool/predicates/or.h>
    #include <libwccl/ops/functions/bool/predicates/nor.h>
    #include <libwccl/values/bool.h>
    #include <libwccl/sentencecontext.h>
    
    using namespace Wccl;
    
    BOOST_AUTO_TEST_SUITE(logical_predicates)
    
    struct PredFix
    {
    	PredFix()
    		: sc(boost::make_shared<Corpus2::Sentence>()),
    		  tagset(),
    		  true_value(true),
    		  false_value(false),
    		  true_constant(new Constant<Bool>(true_value)),
    		  false_constant(new Constant<Bool>(false_value)),
    		  cx(sc, boost::make_shared<Variables>())
    	{
    	}
    	SentenceContext sc;
    	Corpus2::Tagset tagset;
    
    	Bool true_value;
    	Bool false_value;
    	LogicalPredicate::BoolFunctionPtr true_constant;
    	LogicalPredicate::BoolFunctionPtr false_constant;
    
    	FunExecContext cx;
    };
    
    BOOST_FIXTURE_TEST_CASE(predicate_constants, PredFix)
    {
    	BOOST_CHECK_EQUAL(true, Predicate::True(cx)->get_value());
    	BOOST_CHECK_EQUAL(false, Predicate::False(cx)->get_value());
    }
    
    BOOST_FIXTURE_TEST_CASE(and_1arg, PredFix)
    {
    	boost::shared_ptr<And::BoolFunctionPtrVector> v(new And::BoolFunctionPtrVector());
    	v->push_back(true_constant);
    	And pred_and(v);
    	BOOST_CHECK_EQUAL(true, pred_and.apply(cx)->get_value());
    	v->clear();
    	v->push_back(false_constant);
    	BOOST_CHECK_EQUAL(false, pred_and.apply(cx)->get_value());
    }
    
    
    BOOST_FIXTURE_TEST_CASE(and_2arg, PredFix)
    {
    	for(int arg1 = 0; arg1 < 2; ++arg1) {
    		for(int arg2 = 0; arg2 < 2; ++arg2) {
    			boost::shared_ptr<And::BoolFunctionPtrVector> v(new And::BoolFunctionPtrVector());
    			v->push_back(arg1 != 0 ? true_constant : false_constant);
    			v->push_back(arg2 != 0 ? true_constant : false_constant);
    			And pred_and(v);
    			BOOST_CHECK_EQUAL((arg1 != 0) && (arg2 != 0), pred_and.apply(cx)->get_value());
    		}
    	}
    }