fact_tests.h

00001 /***************************************************************************
00002  *   clipsmm C++ wrapper for the CLIPS c library                           *
00003  *   Copyright (C) 2006 by Rick L. Vinyard, Jr.                            *
00004  *   rvinyard@cs.nmsu.edu                                                  *
00005  *                                                                         *
00006  *   This program is free software; you can redistribute it and/or modify  *
00007  *   it under the terms of version 2 of the GNU General Public License as  *
00008  *   published by the Free Software Foundation.                            *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU Lesser General Public      *
00016  *   License along with this library; if not, write to the                 *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA              *
00019  ***************************************************************************/
00020 #ifndef FACTSTEST_H
00021 #define FACTSTEST_H
00022 
00023 #include <cppunit/TestFixture.h>
00024 
00025 #include <clipsmm/clipsmm.h>
00026 
00027 using namespace CLIPS;
00028 
00029 class FactsTest : public  CppUnit::TestFixture {
00030   public:
00031 
00032     CPPUNIT_TEST_SUITE( FactsTest );
00033     CPPUNIT_TEST( assert_template_fact );
00034     CPPUNIT_TEST( check_template_fact_slots );
00035     CPPUNIT_TEST( assert_ordered_fact );
00036     CPPUNIT_TEST( check_ordered_fact_slots );
00037     CPPUNIT_TEST( check_template_fact_slot_values );
00038     CPPUNIT_TEST( check_ordered_fact_slot_values );
00039     CPPUNIT_TEST( set_template_fact_slot_values );
00040     CPPUNIT_TEST( template_fact_retraction );
00041     CPPUNIT_TEST( ordered_fact_retraction );
00042     CPPUNIT_TEST_SUITE_END();
00043 
00044   protected:
00045     CLIPS::Environment environment;
00046     CLIPS::Fact::pointer template_fact, ordered_fact;
00047     std::vector<std::string> slot_names;
00048     std::vector<std::string>::iterator iter;
00049 
00050   public:
00051     void setUp() {
00052       environment.load( "strips.clp" );
00053       template_fact = environment.assert_fact("(in (object R2D2) (location X-Wing) )");
00054       ordered_fact = environment.assert_fact("(numbers 1 2 3 4 5 )");
00055     }
00056 
00057     void tearDown() { }
00058 
00059     void assert_template_fact() { CPPUNIT_ASSERT( template_fact ); }
00060 
00061     void check_template_fact_slots() {
00062       slot_names = template_fact->slot_names();
00063       CPPUNIT_ASSERT( slot_names.size() == 2 );
00064       CPPUNIT_ASSERT( slot_names[0] == "object" );
00065       CPPUNIT_ASSERT( slot_names[1] == "location" );
00066     }
00067 
00068     void assert_ordered_fact() { CPPUNIT_ASSERT( ordered_fact ); }
00069 
00070     void check_ordered_fact_slots() {
00071       slot_names = ordered_fact->slot_names();
00072       CPPUNIT_ASSERT( slot_names.size() == 1 );
00073       CPPUNIT_ASSERT( slot_names[0] == "implied" );
00074     }
00075 
00076     void check_template_fact_slot_values() {
00077       Values values;
00078       values = template_fact->slot_value("object");
00079       CPPUNIT_ASSERT( values.size() == 1 );
00080       CPPUNIT_ASSERT( values[0] == "R2D2" );
00081       values = template_fact->slot_value("location");
00082       CPPUNIT_ASSERT( values.size() == 1 );
00083       CPPUNIT_ASSERT( values[0] == "X-Wing" );
00084     }
00085 
00086     void check_ordered_fact_slot_values() {
00087       Values values = ordered_fact->slot_value("");
00088       CPPUNIT_ASSERT( values.size() == 5 );
00089       CPPUNIT_ASSERT( values[0] == 1 );
00090       CPPUNIT_ASSERT( values[1] == 2 );
00091       CPPUNIT_ASSERT( values[2] == 3 );
00092       CPPUNIT_ASSERT( values[3] == 4 );
00093       CPPUNIT_ASSERT( values[4] == 5 );
00094     }
00095 
00096     void set_template_fact_slot_values() {
00097       template_fact->set_slot( "object", "C3PO" );
00098       template_fact->set_slot( "location", "Millenium Falcon" );
00099       Values values;
00100       values = template_fact->slot_value("object");
00101       CPPUNIT_ASSERT( values.size() == 1 );
00102       CPPUNIT_ASSERT( values[0] == "C3PO" );
00103       values = template_fact->slot_value("location");
00104       CPPUNIT_ASSERT( values.size() == 1 );
00105       CPPUNIT_ASSERT( values[0] == "Millenium Falcon" );
00106     }
00107 
00108     void template_fact_retraction() {
00109       CPPUNIT_ASSERT( template_fact->exists() );
00110       template_fact->retract();
00111       CPPUNIT_ASSERT( ! template_fact->exists() );
00112     }
00113 
00114     void ordered_fact_retraction() {
00115       CPPUNIT_ASSERT( ordered_fact->exists() );
00116       ordered_fact->retract();
00117       CPPUNIT_ASSERT( ! ordered_fact->exists() );
00118     }
00119 
00120 };
00121 
00122 #endif

Generated on Sun Nov 12 11:55:35 2006 by  doxygen 1.5.1