- Main Page
- Namespaces
- Classes
- Files
- Related Pages

# /Users/fpy/titan-1-5-MBARI/Mers/Generators/BFIG/unit-tests/testGenerationOrder1.cpp

    00001
    00002 //
    00003 // Copyright (c) 2004           Model-based Embedded and Robotic Systems Group
    00004 // All Rights Reserved          Massachusetts Institute of Technology
    00005 //
    00006 // This software is provided as is. Model-based Embedded and Robotic Systems
    00007 // (MERS) group does not assume any responsibility.
    00008 //
    00010
    00011 #include "BFIGGeneratorTester.h"
    00012
    00013 #include <tut.h>
    00014
    00015 using Mers::Models::Base::BaseModelVariable;
    00016
    00017 namespace tut
    00018 {
    00023   class GenerationOrder1Data : public BFIGGeneratorTester
    00024   {
    00025         public:
    00029                 GenerationOrder1Data() : BFIGGeneratorTester()
    00030                 {
    00032                         enum Domain {OnOffCommand = 0, OnOffValues = 1, SwitchMode = 2};
    00033
    00035                         const char * d1Vals[] = {"On", "Off", "No-Command", NULL};
    00036                         const char * d2Vals[] = {"On", "Off", NULL};
    00037                         const char * d3Vals[] = {"Broken", "Off", "On", NULL};
    00038
    00040                         const struct BFIGDomainEntry domains[] = {
    00041                                 {"On-Off-Command", d1Vals},
    00042                                 {"On-Off-Values", d2Vals},
    00043                                 {"Switch-Mode", d3Vals}
    00044                         };
    00045
    00047                         const double v1Probs[] = {0.02, 0.80, 0.99};
    00048                         const double v2Probs[] = {0.01, 0.70, 0.90};
    00049
    00051                         const struct BFIGVariableEntry variables[] = {
    00052                                 // Search Variable, Variable Name, Domain Index,
    00053                                 // Variable Type, Probabilities, Costs
    00054                                 {true, {"Switch2.mode", SwitchMode,
    00055                                  BaseModelVariable::State}, v1Probs},
    00056                                 {false, {"Switch2.IndicatorLamp", OnOffValues,
    00057                                  BaseModelVariable::Observable}, NULL},
    00058                                 {false, {"Switch2.CommandIn", OnOffCommand,
    00059                                  BaseModelVariable::Control}, NULL},
    00060                                 {true, {"Switch1.mode", SwitchMode,
    00061                                  BaseModelVariable::State}, v2Probs},
    00062                                 {false, {"Switch1.IndicatorLamp", OnOffValues,
    00063                                  BaseModelVariable::Observable}, NULL},
    00064                                 {false, {"Switch1.CommandIn", OnOffCommand,
    00065                                  BaseModelVariable::Control}, NULL}
    00066                         };
    00067
    00068                         initBFIGGenTest(sizeof(domains) / sizeof(domains[0]), domains, true,
    00069                                          sizeof(variables) / sizeof(variables[0]), variables);
    00070                 }
    00071
    00075                 virtual ~GenerationOrder1Data()
    00076                 {
    00077                 }
    00078   };
    00079
    00080   typedef test_group<GenerationOrder1Data> GenOrder1Factory;
    00081   typedef GenOrder1Factory::object GenOrder1Object;
    00082
    00084   GenOrder1Factory genOrder1Factory("BFIG Generator Test of Order of Generation #1");
    00085
    00089         template<>
    00090   template<>
    00091   void GenOrder1Object::test<1>()
    00092   {
    00093                 // The index of no value
    00094                 unsigned int noVal = (unsigned int)-1;
    00095
    00096                 unsigned int expectedResultsData[][2] =
    00097                         {// Var 0, Var 1
    00098                                 {2, 2},
    00099                                 {1, 2},
    00100                                 {2, 1},
    00101                                 {1, 1},
    00102                                 {0, 2},
    00103                                 {0, 1},
    00104                                 {2, 0},
    00105                                 {1, 0},
    00106                                 {0, 0}
    00107                         };
    00108                 const unsigned int numResults =
    00109                         sizeof(expectedResultsData) / sizeof(expectedResultsData[0]);
    00110
    00111                 bool acceptList[numResults] =
    00112                         { // True if we accept this answer
    00113                                 false,
    00114                                 false,
    00115                                 false,
    00116                                 false,
    00117                                 false,
    00118                                 false,
    00119                                 false,
    00120                                 false,
    00121                                 false
    00122                         };
    00123                 unsigned int runtimeConflictsData[numResults][2] =
    00124                         {// Var 0, Var 1
    00125                                 {noVal, noVal},
    00126                                 {noVal, noVal},
    00127                                 {noVal, noVal},
    00128                                 {noVal, noVal},
    00129                                 {noVal, noVal},
    00130                                 {noVal, noVal},
    00131                                 {noVal, noVal},
    00132                                 {noVal, noVal},
    00133                                 {noVal, noVal}
    00134                         };
    00135
    00136                 unsigned int initialConflictsData[][2] =
    00137                         {// Var 0, Var 1
    00138                         };
    00139                 const unsigned int numConflicts =
    00140                         sizeof(initialConflictsData) / sizeof(initialConflictsData[0]);
    00141
    00142                 bool verifyTermination = true;
    00143
    00144                 testBFIG(numConflicts, initialConflictsData,
    00145                                                  numResults, expectedResultsData, runtimeConflictsData, acceptList,
    00146                                                  verifyTermination);
    00147         }
    00148
    00153         template<>
    00154   template<>
    00155   void GenOrder1Object::test<2>()
    00156   {
    00157                 // The index of no value
    00158                 unsigned int noVal = (unsigned int)-1;
    00159
    00160                 unsigned int expectedResultsData[][2] =
    00161                         {// Var 0, Var 1
    00162                                 {2, 2},
    00163                                 {2, 1},
    00164                                 {0, 2},
    00165                                 {0, 1},
    00166                                 {2, 0},
    00167                                 {0, 0}
    00168                         };
    00169                 const unsigned int numResults =
    00170                         sizeof(expectedResultsData) / sizeof(expectedResultsData[0]);
    00171
    00172                 bool acceptList[numResults] =
    00173                         { // True if we accept this answer
    00174                                 false,
    00175                                 false,
    00176                                 false,
    00177                                 false,
    00178                                 false,
    00179                                 false
    00180                         };
    00181                 unsigned int runtimeConflictsData[numResults][2] =
    00182                         {// Var 0, Var 1
    00183                                 {noVal, noVal},
    00184                                 {noVal, noVal},
    00185                                 {noVal, noVal},
    00186                                 {noVal, noVal},
    00187                                 {noVal, noVal},
    00188                                 {noVal, noVal}
    00189                         };
    00190
    00191                 unsigned int initialConflictsData[][2] =
    00192                         {// Var 0, Var 1
    00193                                 {1, noVal}
    00194                         };
    00195                 const unsigned int numConflicts =
    00196                         sizeof(initialConflictsData) / sizeof(initialConflictsData[0]);
    00197
    00198                 bool verifyTermination = true;
    00199
    00200                 testBFIG(numConflicts, initialConflictsData,
    00201                                                  numResults, expectedResultsData, runtimeConflictsData, acceptList,
    00202                                                  verifyTermination);
    00203         }
    00204
    00209         template<>
    00210   template<>
    00211   void GenOrder1Object::test<3>()
    00212   {
    00213                 // The index of no value
    00214                 unsigned int noVal = (unsigned int)-1;
    00215
    00216                 unsigned int expectedResultsData[][2] =
    00217                         {// Var 0, Var 1
    00218                                 {2, 2},
    00219                                 {2, 1},
    00220                                 {0, 2},
    00221                                 {0, 1},
    00222                                 {2, 0},
    00223                                 {0, 0}
    00224                         };
    00225                 const unsigned int numResults =
    00226                         sizeof(expectedResultsData) / sizeof(expectedResultsData[0]);
    00227
    00228                 bool acceptList[numResults] =
    00229                         { // True if we accept this answer
    00230                                 false,
    00231                                 false,
    00232                                 false,
    00233                                 false,
    00234                                 false,
    00235                                 false
    00236                         };
    00237                 unsigned int runtimeConflictsData[numResults][2] =
    00238                         {// Var 0, Var 1
    00239                                 {    1, noVal},
    00240                                 {noVal, noVal},
    00241                                 {noVal, noVal},
    00242                                 {noVal, noVal},
    00243                                 {noVal, noVal},
    00244                                 {noVal, noVal}
    00245                         };
    00246
    00247                 unsigned int initialConflictsData[][2] =
    00248                         {// Var 0, Var 1
    00249                         };
    00250                 const unsigned int numConflicts =
    00251                         sizeof(initialConflictsData) / sizeof(initialConflictsData[0]);
    00252
    00253                 bool verifyTermination = true;
    00254
    00255                 testBFIG(numConflicts, initialConflictsData,
    00256                                                  numResults, expectedResultsData, runtimeConflictsData, acceptList,
    00257                                                  verifyTermination);
    00258         }
    00259
    00264         template<>
    00265   template<>
    00266   void GenOrder1Object::test<4>()
    00267   {
    00268                 // The index of no value
    00269                 unsigned int noVal = (unsigned int)-1;
    00270
    00271                 unsigned int expectedResultsData[][2] =
    00272                         {// Var 0, Var 1
    00273                                 {2, 2},
    00274                                 {1, 2},
    00275                                 {2, 1},
    00276                                 {0, 2},
    00277                                 {0, 1},
    00278                                 {2, 0},
    00279                                 {0, 0}
    00280                         };
    00281                 const unsigned int numResults =
    00282                         sizeof(expectedResultsData) / sizeof(expectedResultsData[0]);
    00283
    00284                 bool acceptList[numResults] =
    00285                         { // True if we accept this answer
    00286                                 false,
    00287                                 false,
    00288                                 false,
    00289                                 true,
    00290                                 false,
    00291                                 true,
    00292                                 false
    00293                         };
    00294                 unsigned int runtimeConflictsData[numResults][2] =
    00295                         {// Var 0, Var 1
    00296                                 {noVal, noVal},
    00297                                 {    1, noVal},
    00298                                 {noVal, noVal},
    00299                                 {noVal, noVal},
    00300                                 {noVal, noVal},
    00301                                 {noVal, noVal},
    00302                                 {noVal, noVal}
    00303                         };
    00304
    00305                 unsigned int initialConflictsData[][2] =
    00306                         {// Var 0, Var 1
    00307                         };
    00308                 const unsigned int numConflicts =
    00309                         sizeof(initialConflictsData) / sizeof(initialConflictsData[0]);
    00310
    00311                 bool verifyTermination = true;
    00312
    00313                 testBFIG(numConflicts, initialConflictsData,
    00314                                                  numResults, expectedResultsData, runtimeConflictsData, acceptList,
    00315                                                  verifyTermination);
    00316         }
    00317 }
    00318