TEUCHOS_UNIT_TEST( Rythmos_StepperBuilder, setParameterList ) { RCP<ParameterList> pl = Teuchos::parameterList(); RCP<StepperBuilder<double> > builder = stepperBuilder<double>(); TEST_NOTHROW(builder->setParameterList(pl)); // NOTE (mfh 21 Sep 2015) It turns out that the problem with GCC // 4.8.x mentioned below, is also a problem with GCC 5.2. I changed // the #if condition accordingly and now the test passes for me. // Test that StepperBuilder validates its parameter list #if !( (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ == 8) ) // For some reason, GCC 4.8.x has a problem with catching exeptions when you // set an RCP to null. For for GCC 4.8 we will skip all of these tests // below. pl->set("Hello","World"); // This changes the parameter list inside the builder. TEST_THROW(builder->setParameterList(pl), std::logic_error); #ifdef TEUCHOS_DEBUG // This throws because we changed the internal parameter list to an invalid one. TEST_THROW(builder = Teuchos::null, std::logic_error); #else // TEUCHOS_DEBUG TEST_NOTHROW(builder = Teuchos::null ); #endif // TEUCHOS_DEBUG builder = stepperBuilder<double>(); pl = Teuchos::parameterList(); pl->set("Hello","World"); TEST_THROW(builder->setParameterList(pl), std::logic_error); // invalid parameterlist TEST_NOTHROW(builder = Teuchos::null); // invalid parameter list not stored #endif // __GNUC__ version }
// Tests setObjectName and setObectTypeName // Note: it should throw an exception if the string is "" TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, setNames) { { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>(); TEST_THROW( ob->setObjectName(""), std::logic_error ); TEST_THROW( ob->setObjectTypeName(""), std::logic_error ); } { RCP<ObjectBuilder<Foo> > ob; TEST_THROW( ob = objectBuilder<Foo>("","Foo Type"), std::logic_error ); TEST_THROW( ob = objectBuilder<Foo>("Foo",""), std::logic_error ); TEST_THROW( ob = objectBuilder<Foo>("",""), std::logic_error ); } { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>(); ob->setObjectName("Foo"); ob->setObjectTypeName("Foo Type"); const RCP<const ParameterList> validpl = ob->getValidParameters(); // Now we check that the parameterlist is correct TEST_EQUALITY_CONST( validpl->get<std::string>("Foo Type"), "None" ); const ParameterEntry pe = validpl->getEntry("Foo Type"); TEST_EQUALITY_CONST( pe.docString(), "Determines the type of Foo object that will be built.\nThe parameters for each Foo Type are specified in this sublist" ); } { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo","Foo Type"); const RCP<const ParameterList> validpl = ob->getValidParameters(); // Now we check that the parameterlist is correct TEST_EQUALITY_CONST( validpl->get<std::string>("Foo Type"), "None" ); const ParameterEntry pe = validpl->getEntry("Foo Type"); TEST_EQUALITY_CONST( pe.docString(), "Determines the type of Foo object that will be built.\nThe parameters for each Foo Type are specified in this sublist" ); } }
// Here we're checking: // 1. That we can set a parameter list on it and it uses it and then we can // unset it and it goes back to using the valid parameter list. // 1a. We get back the same parameter list we set // 2. In debug mode, the parameter list is validated when unsetParameterList // is called. TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, unsetParameterList) { RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>(); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); const RCP<ParameterList> pl = parameterList(); pl->set("Object Type","None"); ob->setParameterList(pl); RCP<Foo> foo = ob->create(); TEST_EQUALITY_CONST( is_null(foo), true ); RCP<ParameterList> newPL = ob->unsetParameterList(); TEST_EQUALITY_CONST( pl.get(), newPL.get() ); // 1a. foo = ob->create(); const RCP<FooA> fooA = rcp_dynamic_cast<FooA>(foo,false); TEST_EQUALITY_CONST( is_null(fooA), false ); // 1. ob->setParameterList(pl); pl->set("Hello","World"); newPL = null; #ifdef TEUCHOS_DEBUG TEST_THROW( newPL = ob->unsetParameterList(), std::logic_error ); // 2. TEST_EQUALITY_CONST( is_null(newPL), true ); TEST_THROW( ob = null, std::logic_error ); #else // TEUCHOS_DEBUG TEST_NOTHROW( newPL = ob->unsetParameterList() ); TEST_EQUALITY_CONST( pl.get(), newPL.get() ); // 1a. TEST_NOTHROW( ob = null ); #endif // TEUCHOS_DEBUG }
TEUCHOS_UNIT_TEST(Teuchos_TwoDArray, resizeTest){ TwoDArray<int> simpleArray = getSimpleTestTwoDArray(); simpleArray.resizeRows(4); TEST_EQUALITY_CONST(simpleArray.getNumRows(), 4); TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); TEST_EQUALITY_CONST(simpleArray(3,1), 0); TEST_EQUALITY_CONST(simpleArray(1,1), 4); simpleArray.resizeRows(2); TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK TEST_THROW(simpleArray(3,1), RangeError); #endif TEST_EQUALITY_CONST(simpleArray(1,1), 4); simpleArray.resizeCols(4); TEST_EQUALITY_CONST(simpleArray.getNumCols(), 4); TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); TEST_EQUALITY_CONST(simpleArray(1,3), 0); TEST_EQUALITY_CONST(simpleArray(1,1), 4); simpleArray.resizeCols(2); TEST_EQUALITY_CONST(simpleArray.getNumCols(), 2); TEST_EQUALITY_CONST(simpleArray.getNumRows(), 2); #ifdef HAVE_TEUCHOS_ARRAY_BOUNDSCHECK TEST_THROW(simpleArray(1,3), RangeError); #endif TEST_EQUALITY_CONST(simpleArray(1,1), 4); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, invalidData ) { LinearRegression<double> lr; Array<double> x,y; TEST_THROW(lr.setData(x,y), std::logic_error); x.push_back(0.0); y.push_back(0.0); TEST_THROW(lr.setData(x,y), std::logic_error); x.push_back(1.0); TEST_THROW(lr.setData(x,y), std::logic_error); }
// triangle tests TEUCHOS_UNIT_TEST(tGeometricFieldPattern, test2d) { out << note << std::endl; // basis to build patterns from const int order = 6; RCP<Intrepid2::Basis<PHX::Device,double,double> > basis = rcp(new Intrepid2::Basis_HGRAD_QUAD_Cn_FEM<PHX::Device,double,double>(order)); RCP<const FieldPattern> pattern = rcp(new Intrepid2FieldPattern(basis)); std::vector<RCP<const FieldPattern> > patterns; std::vector<int> indices; { // test unbuilt exceptions GeometricAggFieldPattern gfp; TEST_THROW(gfp.getDimension(),std::logic_error); TEST_THROW(gfp.getSubcellCount(0),std::logic_error); TEST_THROW(gfp.getSubcellIndices(0,0),std::logic_error); TEST_THROW(gfp.getSubcellClosureIndices(0,0,indices),std::logic_error); } { patterns.clear(); patterns.push_back(pattern); GeometricAggFieldPattern gfp; gfp.buildPattern(patterns); TEST_NOTHROW(gfp.getDimension()); TEST_NOTHROW(gfp.getSubcellCount(0)); TEST_NOTHROW(gfp.getSubcellIndices(0,0)); TEST_THROW(gfp.getSubcellClosureIndices(0,0,indices),std::logic_error); TestFieldPattern tfp; tfp.cellTopo = shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >()); tfp.subcellIndices.resize(3); // 3 geometric types: vertex, edge, interior // vertex tfp.subcellIndices[0].resize(4); tfp[0][0].push_back(0); tfp[0][1].push_back(1); tfp[0][2].push_back(2); tfp[0][3].push_back(3); // edge and interior tfp.subcellIndices[1].resize(4); tfp.subcellIndices[2].resize(1); if (order > 1) { tfp[1][0].push_back(4); tfp[1][1].push_back(5); tfp[1][2].push_back(6); tfp[1][3].push_back(7); tfp[2][0].push_back(8); } TEST_ASSERT(gfp.equals(tfp)); } }
// quad tests TEUCHOS_UNIT_TEST(tSquareQuadMeshDOFManager, buildTest_quad_edge_orientations_fail) { // build global (or serial communicator) #ifdef HAVE_MPI stk::ParallelMachine Comm = MPI_COMM_WORLD; #else stk::ParallelMachine Comm = WHAT_TO_DO_COMM; #endif int numProcs = stk::parallel_machine_size(Comm); TEUCHOS_ASSERT(numProcs==2); // build a geometric pattern from a single basis RCP<const panzer::FieldPattern> patternI1 = buildFieldPattern<Intrepid2::Basis_HCURL_QUAD_I1_FEM<PHX::exec_space,double,double> >(); RCP<panzer::ConnManager<int,int> > connManager = buildQuadMesh(Comm,2,2,1,1); RCP<panzer::DOFManagerFEI<int,int> > dofManager = rcp(new panzer::DOFManagerFEI<int,int>()); dofManager->setOrientationsRequired(true); TEST_EQUALITY(dofManager->getOrientationsRequired(),true); TEST_EQUALITY(dofManager->getConnManager(),Teuchos::null); dofManager->setConnManager(connManager,MPI_COMM_WORLD); TEST_EQUALITY(dofManager->getConnManager(),connManager); dofManager->addField("b",patternI1); TEST_THROW(dofManager->buildGlobalUnknowns(patternI1),std::logic_error); }
explicit ThrowsCounted() { ++constructed; if (throw_after > 0 && --throw_after == 0) { TEST_THROW(1); } ++count; }
TEUCHOS_UNIT_TEST_TEMPLATE_3_DECL( DefaultSparseOps, ResubmitMatrix, Ordinal, Scalar, Node ) { RCP<Node> node = getNode<Node>(); typedef typename DefaultKernels<Scalar,Ordinal,Node>::SparseOps DSM; typedef typename DSM::template bind_scalar<Scalar>::other_type OPS; typedef typename OPS::template matrix<Scalar,Ordinal,Node>::matrix_type MAT; typedef typename OPS::template graph<Ordinal,Node>::graph_type GRPH; typedef MultiVector<Scalar,Node> MV; typedef Teuchos::ScalarTraits<Scalar> ST; const Ordinal numRows = 0; Teuchos::ArrayRCP<size_t> ptrs(1); ptrs[0] = 0; RCP<GRPH> G = rcp( new GRPH(numRows,numRows,node,null) ); RCP<MAT> A = rcp( new MAT(G,null) ); G->setStructure(ptrs,null); A->setValues(null); OPS::finalizeGraphAndMatrix(Teuchos::UNDEF_TRI,Teuchos::NON_UNIT_DIAG,*G,*A,null); Teuchos::EDiag diag; Teuchos::EUplo uplo; G->getMatDesc(uplo,diag); TEST_EQUALITY_CONST( uplo, Teuchos::UNDEF_TRI ); TEST_EQUALITY_CONST( diag, Teuchos::NON_UNIT_DIAG ); out << "\n**\n** Can't submit the data twice\n**\n"; OPS dsm(node); dsm.setGraphAndMatrix(G,A); TEST_THROW( dsm.setGraphAndMatrix(G,A), std::runtime_error ); }
B(const B &b) { ++count_; if (count_ == 3) TEST_THROW(1); data_ = b.data_; ++population_; }
constexpr static int check_value(int const& val) { #if TEST_STD_VER < 14 return val == -1 || val == 999 ? (TEST_THROW(42), 0) : val; #else assert(val != -1); assert(val != 999); return val; #endif }
TEUCHOS_UNIT_TEST(evaluator_factory, basic_construction) { PHX::KokkosDeviceSession session; panzer::FieldLayoutLibrary fl; Teuchos::RCP<panzer::IntegrationRule> ir; { Teuchos::RCP<shards::CellTopology> topo = Teuchos::rcp(new shards::CellTopology(shards::getCellTopologyData< shards::Hexahedron<8> >())); const int num_cells = 20; const panzer::CellData cell_data(num_cells,topo); const int cubature_degree = 2; ir = Teuchos::rcp(new panzer::IntegrationRule(cubature_degree, cell_data)); Teuchos::RCP<panzer::BasisIRLayout> basis = Teuchos::rcp(new panzer::BasisIRLayout("Q1",0,*ir)); fl.addFieldAndLayout("Ux",basis); } std::string model_id = "fluid model"; Teuchos::ParameterList eqset_params; Teuchos::ParameterList p("Closure Models"); { p.sublist("fluid model").sublist("Density").set<double>("Value",1.0); p.sublist("fluid model").sublist("Viscosity").set<double>("Value",1.0); p.sublist("fluid model").sublist("Heat Capacity").set<double>("Value",1.0); p.sublist("fluid model").sublist("Thermal Conductivity").set<double>("Value",1.0); } user_app::MyModelFactory<panzer::Traits::Residual> mf; Teuchos::RCP< std::vector< Teuchos::RCP<PHX::Evaluator<panzer::Traits> > > > evaluators; Teuchos::ParameterList user_data("User Data"); Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); PHX::FieldManager<panzer::Traits> fm; evaluators = mf.buildClosureModels(model_id, p, fl, ir, eqset_params, user_data, gd, fm); TEST_EQUALITY(evaluators->size(), 8); user_app::MyModelFactory_TemplateBuilder builder; panzer::ClosureModelFactory_TemplateManager<panzer::Traits> model_factory; model_factory.buildObjects(builder); evaluators = model_factory.getAsObject<panzer::Traits::Residual>()->buildClosureModels(model_id, p, fl, ir, eqset_params, user_data, gd, fm); TEST_EQUALITY(evaluators->size(), 8); // Add an unsupported type p.sublist("fluid model").sublist("garbage").set<std::string>("Value","help!"); TEST_THROW(model_factory.getAsObject<panzer::Traits::Residual>()->buildClosureModels(model_id, p, fl, ir, eqset_params, user_data, gd, fm), std::logic_error); }
// SmootherPrototype test void testApplyNoSetup(SmootherPrototype const & smoother, Teuchos::FancyOStream & out, bool & success) { GO numGlobalElements = 125; RCP<const Map> map = MapFactory::Build(Parameters::getLib(), numGlobalElements, 0, Parameters::getDefaultComm()); RCP<MultiVector> X = MultiVectorFactory::Build(map,1); RCP<MultiVector> RHS = MultiVectorFactory::Build(map,1); TEST_THROW(smoother.Apply(*X,*RHS), MueLu::Exceptions::RuntimeError); }
TEUCHOS_UNIT_TEST(Teuchos_ParameterList, parameterEntryConverterExceptions) { TEST_THROW(RCP<ParameterList> badRootElementList = getParametersFromXmlFile("BadRootElement.xml"), BadXMLParameterListRootElementException); TEST_THROW(RCP<ParameterList> badParameterListElementList = getParametersFromXmlFile("BadParameterListElement.xml"), BadParameterListElementException); TEST_THROW(RCP<ParameterList> noNameAttributeList = getParametersFromXmlFile("NoNameAttribute.xml"), NoNameAttributeExecption); TEST_THROW(RCP<ParameterList> noTypeAttributeList = getParametersFromXmlFile("NoTypeAttribute.xml"), NoTypeAttributeExecption); TEST_THROW(RCP<ParameterList> noValueAttributeList = getParametersFromXmlFile("NoValueAttribute.xml"), NoValueAttributeExecption); TEST_THROW(RCP<ParameterList> badIdsList = getParametersFromXmlFile("DuplicateParameterIDs.xml"), DuplicateParameterIDsException); TEST_THROW(RCP<ParameterList> badParameterEntryConverterList = getParametersFromXmlFile("CantFindParameterEntryConverter.xml"), CantFindParameterEntryConverterException); #ifdef HAVE_TEUCHOS_DEBUG StandardTemplatedParameterConverter<int> intConverter; StandardTemplatedParameterConverter<float> floatConverter; ValidatortoIDMap dummmyValidatorMap; RCP<ParameterEntry> floatParameter = rcp( new ParameterEntry((float)3.0)); TEST_THROW(intConverter.fromParameterEntrytoXML(floatParameter, "blah", 1, dummmyValidatorMap), BadParameterEntryXMLConverterTypeException); XMLObject floatXML = floatConverter.fromParameterEntrytoXML(floatParameter, "float", 1, dummmyValidatorMap); TEST_THROW(intConverter.fromXMLtoParameterEntry(floatXML), BadParameterEntryXMLConverterTypeException); #endif }
constexpr static int check_value(int& val, int val_cp = 0) { #if TEST_STD_VER < 14 return val_cp = val, val = -1, (val_cp == -1 || val_cp == 999 ? (TEST_THROW(42), 0) : val_cp); #else assert(val != -1); assert(val != 999); val_cp = val; val = -1; return val_cp; #endif }
// We shouldn't be able to set two factories with the same name. TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, setObjectFactory_bad ) { { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo","Foo Type"); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); // ObjectBuilder will let you add the object, but will not throw until getValidParameters is called #ifdef TEUCHOS_DEBUG TEST_THROW( ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"), std::logic_error ); #else // TEUCHOS_DEBUG TEST_NOTHROW( ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A") ); TEST_THROW( ob->getValidParameters(), std::logic_error ); #endif // TEUCHOS_DEBUG } { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo","Foo Type"); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); TEST_NOTHROW( ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"New Foo A") ); TEST_NOTHROW( ob->getValidParameters() ); } }
TEUCHOS_UNIT_TEST( XMLParameterListReader, XMLDuplicatedSublistsThrowsError ) { FileInputSource xmlFile(filename); XMLObject xmlParams = xmlFile.getObject(); XMLParameterListReader xmlPLReader; TEST_EQUALITY_CONST( xmlPLReader.getAllowsDuplicateSublists(), true ); out << "Changing policy to disallow duplicate sublists" << std::endl; xmlPLReader.setAllowsDuplicateSublists( false ); TEST_EQUALITY_CONST( xmlPLReader.getAllowsDuplicateSublists(), false ); TEST_THROW( xmlPLReader.toParameterList(xmlParams), DuplicateParameterSublist ); }
TEUCHOS_UNIT_TEST( GlobalMPISession, allGather ) { const int numProcs = GlobalMPISession::getNProc(); const int procRank = GlobalMPISession::getRank(); { Array<int> allInts; ECHO(allInts.resize(numProcs-1)); TEST_THROW(GlobalMPISession::allGather(procRank+1, allInts()), std::out_of_range); ECHO(allInts.resize(numProcs+1)); TEST_THROW(GlobalMPISession::allGather(procRank+1, allInts()), std::out_of_range); } { Array<int> allInts_expected(numProcs); for (int k = 0; k < numProcs; ++k) { allInts_expected[k] = k+1; } Array<int> allInts(numProcs); ECHO(GlobalMPISession::allGather(procRank+1, allInts())); TEST_EQUALITY(allInts, allInts_expected); } }
TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, setDefaultObject_withOneUsePL ) { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo","Foo Type"); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); ob->setObjectFactory(abstractFactoryStd<Foo,FooB>(),"Foo B"); ob->setObjectFactory(abstractFactoryStd<Foo,FooC>(),"Foo C"); { const RCP<ParameterList> pl = parameterList(); ob->setParameterList(pl); const RCP<Foo> foo = ob->create(); RCP<FooC> fooC = Teuchos::rcp_dynamic_cast<FooC>(foo,false); TEST_ASSERT( !is_null(fooC) ); } { const RCP<ParameterList> pl = parameterList(); ob->setParameterList(pl); ob->setDefaultObject("Foo A"); const RCP<Foo> foo = ob->create(); RCP<FooA> fooA = Teuchos::rcp_dynamic_cast<FooA>(foo,false); TEST_ASSERT( !is_null(fooA) ); } { const RCP<ParameterList> pl = parameterList(); ob->setParameterList(pl); ob->setDefaultObject("None"); const RCP<Foo> foo = ob->create(); TEST_ASSERT( is_null(foo) ); } { #ifdef TEUCHOS_DEBUG TEST_THROW(ob->setDefaultObject("Foo D"), std::logic_error); #else ob->setDefaultObject("Foo D"); TEST_THROW(ob->getValidParameters(), std::logic_error); #endif // TEUCHOS_DEBUG } }
// setObjectFactory does four things: // 1. adds a new object name // 1a. if object name is "" it throws an exception // 2. adds a new object factory // 3. sets defaultObject_ // 4. deletes the validParamList_ // // Notes about how to sense the changes: // 1. The new object name is appended to the list of valid names and shows up in the valid parameter list // 2. The new object factory is appended to the list of factories and is only accessible through create // 3. The default Object is accessible through both getObjectName and the valid parameter list. // 4. The validParameterList is deleted and this can only be sensed through calling getValidParameters TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, setObjectFactory) { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo","Foo Type"); TEST_EQUALITY_CONST( ob->getObjectName(), "None" ); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); TEST_EQUALITY_CONST( ob->getObjectName(), "Foo A" ); // 3. RCP<const ParameterList> pl = ob->getValidParameters(); TEST_EQUALITY_CONST( pl->get<std::string>("Foo Type"), "Foo A" ); // 1. TEST_EQUALITY_CONST( pl->sublist("Foo A").get<std::string>("String"), "A" ); // 1. const RCP<Foo> foo = ob->create(); const RCP<FooA> fooA = rcp_dynamic_cast<FooA>(foo,false); TEST_EQUALITY_CONST( is_null(fooA), false ); // 2. ob->setObjectFactory(abstractFactoryStd<Foo,FooB>(),"Foo B"); pl = ob->getValidParameters(); TEST_EQUALITY_CONST( pl->get<std::string>("Foo Type"), "Foo B" ); // 4. TEST_THROW( ob->setObjectFactory(abstractFactoryStd<Foo,FooC>(),""), std::logic_error ); // 1a. }
// create has many cases // 1. It should return a null RCP if no factories are set // 2. It should return a null RCP if "Object Type" is set to "None" in the provided parameterList // 3. It should return the correct object consistent with the "Object Type" setting in the parameterList if no string is passed // 3a. It should return the correct object consistent with the "Object Type" // setting in the valid parameterList if no string is passed and no // parameterList is provided. // 4. It should return the correct object consistent with the input string regardless of the parameterLists // 4a. It should throw an exception if an invalid input string is provided // 5. If no parameter list is provided, then it will use the valid parameter list to set parameters on the object // 5a. If a parameter list is provided, then it will use that parameter list to set parameters on the object // 6. It will throw an exception with a nice message if the factory creates a null RCP // Under what conditions could this happen? // 7. [03/05/09 tscoffe: found bug] create() uses objectValidator_, so // getValidParameters must be valid at the beginning to avoid a null // dereference of the objectValidator_ pointer in the case that we ask for an // object by name and the validParamList_ has not been set up yet. TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, create) { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>("Foo", "Foo Type"); TEST_EQUALITY_CONST( ob->create("None"), null ); // 7. TEST_EQUALITY_CONST( ob->create(), null ); // 1. ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); ob->setObjectFactory(abstractFactoryStd<Foo,FooB>(),"Foo B"); ob->setObjectFactory(abstractFactoryStd<Foo,FooC>(),"Foo C"); out << "op.getValidParamters():\n"; printValidParameters(*ob, out); const RCP<ParameterList> pl = parameterList(); pl->setParameters(*ob->getValidParameters()); pl->set("Foo Type","None"); ob->setParameterList(pl); TEST_EQUALITY_CONST( ob->create(), null ); // 2. pl->set("Foo Type", "Foo B"); pl->sublist("Foo B").set("String","BB"); pl->sublist("Foo C").set("String","CC"); { const RCP<Foo> foo = ob->create(); const RCP<FooB> fooB = rcp_dynamic_cast<FooB>(foo,false); TEST_EQUALITY_CONST( is_null(fooB), false ); // 3. TEST_EQUALITY_CONST( foo->getString(), "BB" ); // 5a. } ob->unsetParameterList(); { const RCP<Foo> foo = ob->create(); const RCP<FooC> fooC = rcp_dynamic_cast<FooC>(foo,false); TEST_EQUALITY_CONST( is_null(fooC), false ); // 3a. TEST_EQUALITY_CONST( foo->getString(), "C" ); // 5. } { const RCP<Foo> foo = ob->create("Foo A"); const RCP<FooA> fooA = rcp_dynamic_cast<FooA>(foo,false); TEST_EQUALITY_CONST( is_null(fooA), false ); // 4. } ob->setParameterList(pl); { const RCP<Foo> foo = ob->create("Foo A"); const RCP<FooA> fooA = rcp_dynamic_cast<FooA>(foo,false); TEST_EQUALITY_CONST( is_null(fooA), false ); // 4. } { RCP<Foo> foo; TEST_THROW( foo = ob->create("Foo D"), std::logic_error ); // 4a. } // 6. ??? }
// This function does several things. // 1. It creates the validParameterList whenever it is deleted [already tested in setObjectFactory] // 2. It creates the objectValidator // 3. It adds a docstring to the "Object Type" parameter in the parameter list [already tested in setNames] // 4. It fills the parameter list out with the valid parameteres for each object it can create TEUCHOS_UNIT_TEST( Teuchos_ObjectBuilder, getValidParameters) { { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>(); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); const RCP<ParameterList> pl = parameterList(); pl->set("Object Type","Foo B"); TEST_THROW( ob->setParameterList(pl), std::logic_error ); // 2. } { const RCP<ObjectBuilder<Foo> > ob = objectBuilder<Foo>(); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo A"); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo B"); ob->setObjectFactory(abstractFactoryStd<Foo,FooA>(),"Foo C"); const RCP<ParameterList> validPL = parameterList(); validPL->set("Object Type","Foo C"); validPL->sublist("Foo A").set("String","A"); validPL->sublist("Foo B").set("String","B"); validPL->sublist("Foo C").set("String","C"); Array<std::string> validObjectNames; validObjectNames.push_back("None"); validObjectNames.push_back("Foo A"); validObjectNames.push_back("Foo B"); validObjectNames.push_back("Foo C"); const RCP<const StringToIntegralParameterEntryValidator<int> > objectValidator = rcp( new StringToIntegralParameterEntryValidator<int>( validObjectNames,"Object Type" ) ); validPL->set( "Object Type","Foo C" ,(std::string("Determines the type of Object object that will be built.\n") + "The parameters for each Object Type are specified in this sublist" ).c_str() ,objectValidator ); const RCP<const ParameterList> pl = ob->getValidParameters(); TEST_NOTHROW( pl->validateParameters(*validPL) ); // 4. validPL->set("Object Type","Foo A"); TEST_NOTHROW( pl->validateParameters(*validPL) ); // 4. validPL->set("Object Type","Foo B"); TEST_NOTHROW( pl->validateParameters(*validPL) ); // 4. validPL->set("Object Type","None"); TEST_NOTHROW( pl->validateParameters(*validPL) ); // 4. } }
TEUCHOS_UNIT_TEST( ParameterList, XMLDuplicatedSublists ) { ParameterList pl; TEST_THROW( updateParametersFromXmlFile(filename, inOutArg(pl) ), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlFile(filename), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlFile(filename,null), DuplicateParameterSublist ); // std::ifstream fin(filename.c_str()); std::string xmlstring( (std::istreambuf_iterator<char>(fin)), std::istreambuf_iterator<char>() ); TEST_THROW( updateParametersFromXmlString(xmlstring,inOutArg(pl) ), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlString(xmlstring), DuplicateParameterSublist ); TEST_THROW( getParametersFromXmlString(xmlstring,null), DuplicateParameterSublist ); }
/** * Test the ArrayLengthDependency. */ TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testArrayLengthDep){ RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); RCP<DependencySheet> depSheet1 = RCP<DependencySheet>(new DependencySheet); ParameterList numberArrayLengthDepList = My_deplist->sublist( "Number Array Length Dependency List", false, "Number Array Length Dependecy testing list."); numberArrayLengthDepList.set("Array Length", 10, "array length setter"); Array<double> variableLengthArray(11,23.0); RCP<EnhancedNumberValidator<double> > varLengthArrayVali = RCP<EnhancedNumberValidator<double> >( new EnhancedNumberValidator<double>(10,50,4) ); numberArrayLengthDepList.set( "Variable Length Array", variableLengthArray, "variable length array", RCP<ArrayNumberValidator<double> >( new ArrayNumberValidator<double>(varLengthArrayVali))); RCP<NumberArrayLengthDependency<int, double> > arrayLengthDep( new NumberArrayLengthDependency<int, double>( numberArrayLengthDepList.getEntryRCP("Array Length"), numberArrayLengthDepList.getEntryRCP("Variable Length Array"), rcp(new AdditionFunction<int>(1)) ) ); depSheet1->addDependency(arrayLengthDep); Array<double> curArray = numberArrayLengthDepList.get<Array<double> >("Variable Length Array"); TEST_ASSERT(curArray.length() ==11); numberArrayLengthDepList.set("Array Length", 12); arrayLengthDep()->evaluate(); curArray = numberArrayLengthDepList.get<Array<double> >("Variable Length Array"); out << curArray.length() << std::endl; TEST_ASSERT(curArray.length() ==13); numberArrayLengthDepList.set("Array Length", -2); TEST_THROW(arrayLengthDep()->evaluate(), Exceptions::InvalidParameterValue); }
/** * Test the TwoDColDependency. */ TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testTwoDColDependency){ RCP<ParameterList> My_deplist = RCP<ParameterList>(new ParameterList); RCP<DependencySheet> depSheet1 = RCP<DependencySheet>(new DependencySheet); ParameterList colNumDepList = My_deplist->sublist( "2D Col Depdency List", false, "2D Col Dependecy testing list."); colNumDepList.set("Num cols", 2, "num cols setter"); TwoDArray<double> variableColsArray(11,3,16.5); RCP<EnhancedNumberValidator<double> > varColArrayVali = RCP<EnhancedNumberValidator<double> >( new EnhancedNumberValidator<double>(10,50,4) ); colNumDepList.set( "Variable Col Array", variableColsArray, "variable col array", RCP<TwoDArrayNumberValidator<double> >( new TwoDArrayNumberValidator<double>(varColArrayVali))); RCP<TwoDColDependency<int, double> > arrayColDep = rcp( new TwoDColDependency<int, double>( colNumDepList.getEntryRCP("Num cols"), colNumDepList.getEntryRCP("Variable Col Array") , rcp(new AdditionFunction<int>(1)) ) ); depSheet1->addDependency(arrayColDep); TwoDArray<double> curArray = colNumDepList.get<TwoDArray<double> >("Variable Col Array"); TEST_EQUALITY_CONST(curArray.getNumCols(),3); colNumDepList.set("Num cols", 4); arrayColDep()->evaluate(); curArray = colNumDepList.get<TwoDArray<double> >("Variable Col Array"); TEST_EQUALITY_CONST(curArray.getNumCols(),5); colNumDepList.set("Num cols", -2); TEST_THROW(arrayColDep()->evaluate(), Exceptions::InvalidParameterValue); }
TEUCHOS_UNIT_TEST( Rythmos_BackwardEulerStepper, checkConsistentState ) { { RCP<SinCosModel> model = sinCosModel(true); Thyra::ModelEvaluatorBase::InArgs<double> model_ic = model->getNominalValues(); RCP<Thyra::NonlinearSolverBase<double> > neSolver = timeStepNonlinearSolver<double>(); RCP<BackwardEulerStepper<double> > stepper = backwardEulerStepper<double>(model,neSolver); stepper->setInitialCondition(model_ic); double dt = 0.1; double dt_taken = stepper->takeStep(dt,STEP_TYPE_FIXED); TEST_ASSERT( dt == dt_taken ); RCP<const MomentoBase<double> > momento = stepper->getMomento(); TEST_THROW(stepper->setMomento(momento.ptr(),Teuchos::null,Teuchos::null), std::logic_error); TEST_THROW(stepper->setMomento(momento.ptr(),model,Teuchos::null), std::logic_error); TEST_THROW(stepper->setMomento(momento.ptr(),Teuchos::null,neSolver), std::logic_error); TEST_NOTHROW(stepper->setMomento(momento.ptr(),model,neSolver)); } { // Initialize a valid non-const momento: RCP<BackwardEulerStepperMomento<double> > momento; { RCP<SinCosModel> model = sinCosModel(true); Thyra::ModelEvaluatorBase::InArgs<double> model_ic = model->getNominalValues(); RCP<Thyra::NonlinearSolverBase<double> > neSolver = timeStepNonlinearSolver<double>(); RCP<BackwardEulerStepper<double> > stepper = backwardEulerStepper<double>(model,neSolver); stepper->setInitialCondition(model_ic); double dt = 0.1; double dt_taken = stepper->takeStep(dt,STEP_TYPE_FIXED); TEST_ASSERT( dt == dt_taken ); RCP<const MomentoBase<double> > m = stepper->getMomento(); RCP<const BackwardEulerStepperMomento<double> > beMomento = Teuchos::rcp_dynamic_cast<const BackwardEulerStepperMomento<double> >(m,true); momento = Teuchos::rcp_dynamic_cast<BackwardEulerStepperMomento<double> >(beMomento->clone(),true); } { // Check if isInitialized_ == true, but // model_ = null or solver = null or haveInitialCondition_ = false or interpolator = null RCP<BackwardEulerStepperMomento<double> > m = Teuchos::rcp_dynamic_cast<BackwardEulerStepperMomento<double> >(momento->clone(),true); RCP<BackwardEulerStepper<double> > stepper = backwardEulerStepper<double>(); RCP<SinCosModel> model = sinCosModel(true); RCP<Thyra::NonlinearSolverBase<double> > neSolver = timeStepNonlinearSolver<double>(); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); TEST_THROW(stepper->setMomento(m.ptr(),Teuchos::null,neSolver),std::logic_error); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); TEST_THROW(stepper->setMomento(m.ptr(),model,Teuchos::null),std::logic_error); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); m->set_haveInitialCondition(false); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_haveInitialCondition(true); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); RCP<InterpolatorBase<double> > interp = m->get_interpolator(); m->set_interpolator(Teuchos::null); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_interpolator(interp); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); } { // Check if haveInitialCondition_ == true, but // t_ == nan or // t_old_ == nan or // scaled_x_old == null or // x_dot_old == null or // x == null or // x_dot == null typedef Teuchos::ScalarTraits<double> ST; RCP<BackwardEulerStepperMomento<double> > m = Teuchos::rcp_dynamic_cast<BackwardEulerStepperMomento<double> >(momento->clone(),true); RCP<BackwardEulerStepper<double> > stepper = backwardEulerStepper<double>(); RCP<SinCosModel> model = sinCosModel(true); RCP<Thyra::NonlinearSolverBase<double> > neSolver = timeStepNonlinearSolver<double>(); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); double t = m->get_t(); m->set_t(ST::nan()); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_t(t); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); double t_old = m->get_t_old(); m->set_t_old(ST::nan()); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_t_old(t_old); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); RCP<VectorBase<double> > scaled_x_old = m->get_scaled_x_old(); m->set_scaled_x_old(Teuchos::null); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_scaled_x_old(scaled_x_old); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); RCP<VectorBase<double> > x_dot_old = m->get_x_dot_old(); m->set_x_dot_old(Teuchos::null); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_x_dot_old(x_dot_old); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); RCP<VectorBase<double> > x = m->get_x(); m->set_x(Teuchos::null); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_x(x); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); RCP<VectorBase<double> > x_dot = m->get_x_dot(); m->set_x_dot(Teuchos::null); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_x_dot(x_dot); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); } { // Check that if numSteps_ > 0 then isInitialized_ == true and haveInitialCondition_ == true RCP<BackwardEulerStepperMomento<double> > m = Teuchos::rcp_dynamic_cast<BackwardEulerStepperMomento<double> >(momento->clone(),true); TEST_ASSERT( m->get_numSteps() == 1 ); RCP<BackwardEulerStepper<double> > stepper = backwardEulerStepper<double>(); RCP<SinCosModel> model = sinCosModel(true); RCP<Thyra::NonlinearSolverBase<double> > neSolver = timeStepNonlinearSolver<double>(); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); m->set_isInitialized(false); TEST_THROW(stepper->setMomento(m.ptr(),model,neSolver),std::logic_error); m->set_isInitialized(true); TEST_NOTHROW(stepper->setMomento(m.ptr(),model,neSolver)); } } }
// quad tests TEUCHOS_UNIT_TEST(tBlockedDOFManagerFactory, basic_test) { // // build global (or serial communicator) // #ifdef HAVE_MPI // stk_classic::ParallelMachine Comm = MPI_COMM_WORLD; // #else // stk_classic::ParallelMachine Comm = WHAT_TO_DO_COMM; // #endif // // int numProcs = stk_classic::parallel_machine_size(Comm); // int myRank = stk_classic::parallel_machine_rank(Comm); typedef panzer::BlockedDOFManagerFactory<int,int> BDFii; bool result = false; result = BDFii::requiresBlocking(""); TEST_ASSERT(!result); result = BDFii::requiresBlocking("UX UY P"); TEST_ASSERT(!result); result = BDFii::requiresBlocking("blocked: UX - UY - P"); TEST_ASSERT(result); result = BDFii::requiresBlocking("blocked: UX UY - P"); TEST_ASSERT(result); result = BDFii::requiresBlocking("blocked: UX - UY P"); TEST_ASSERT(result); result = BDFii::requiresBlocking("blocked: UX UY P"); TEST_ASSERT(result); TEST_THROW(BDFii::requiresBlocking("blocked: - UX"),std::logic_error); TEST_THROW(BDFii::requiresBlocking("blocked: UX - - P"),std::logic_error); { std::vector<std::vector<std::string> > blocks; BDFii::buildBlocking("blocked: UX - UY - P",blocks); TEST_EQUALITY(blocks.size(),1); TEST_EQUALITY(blocks[0].size(),3); TEST_EQUALITY(blocks[0][0],"UX"); TEST_EQUALITY(blocks[0][1],"UY"); TEST_EQUALITY(blocks[0][2],"P"); } { std::vector<std::vector<std::string> > blocks; BDFii::buildBlocking("blocked: UX UY - P",blocks); TEST_EQUALITY(blocks.size(),2); TEST_EQUALITY(blocks[0].size(),1); TEST_EQUALITY(blocks[0][0],"UX"); TEST_EQUALITY(blocks[1].size(),2); TEST_EQUALITY(blocks[1][0],"UY"); TEST_EQUALITY(blocks[1][1],"P"); } { std::vector<std::vector<std::string> > blocks; BDFii::buildBlocking("blocked: UX - UY P",blocks); TEST_EQUALITY(blocks.size(),2); TEST_EQUALITY(blocks[0].size(),2); TEST_EQUALITY(blocks[0][0],"UX"); TEST_EQUALITY(blocks[0][1],"UY"); TEST_EQUALITY(blocks[1].size(),1); TEST_EQUALITY(blocks[1][0],"P"); } { std::vector<std::vector<std::string> > blocks; BDFii::buildBlocking("blocked: UX P UY",blocks); TEST_EQUALITY(blocks.size(),3); TEST_EQUALITY(blocks[0].size(),1); TEST_EQUALITY(blocks[0][0],"UX"); TEST_EQUALITY(blocks[1].size(),1); TEST_EQUALITY(blocks[1][0],"P"); TEST_EQUALITY(blocks[2].size(),1); TEST_EQUALITY(blocks[2][0],"UY"); } }
/** * Tests the excpetions associated with Dependencies */ TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testDepExceptions){ RCP<ParameterList> list1 = RCP<ParameterList>(new ParameterList()); RCP<ParameterList> list2 = RCP<ParameterList>(new ParameterList()); list1->set("int parameter", 4, "int parameter"); list1->set("double parameter", 6.0, "double parameter"); list1->set("string parameter", "hahahaha", "string parameter"); Array<double> doubleArray(10,23.0); list1->set("array parameter", doubleArray, "array parameter"); list1->set("bool parameter", true, "bool parameter"); RCP<AdditionFunction<int> > intFuncTester = rcp(new AdditionFunction<int>(10)); TEST_THROW(RCP<NumberVisualDependency<int> > numValiDep = rcp( new NumberVisualDependency<int>( list1->getEntryRCP("bool parameter"), list1->getEntryRCP("double parameter"), true, intFuncTester)), InvalidDependencyException); /* * Testing StringVisualDepenendcy exceptions. */ RCP<StringVisualDependency> stringVisDep; TEST_THROW(stringVisDep = RCP<StringVisualDependency>( new StringVisualDependency( list1->getEntryRCP("double parameter"), list1->getEntryRCP("int parameter"), "cheese", true)), InvalidDependencyException); /* * Testing BoolVisualDependency exceptions. */ TEST_THROW(RCP<BoolVisualDependency> boolVisDep = RCP<BoolVisualDependency>(new BoolVisualDependency( list1->getEntryRCP("int parameter"), list1->getEntryRCP("double parameter"), false)), InvalidDependencyException); /** * Tesint NumberArrayLengthDependency excpetions */ RCP<NumberArrayLengthDependency<int, double> > numArrayLengthDep; TEST_THROW(numArrayLengthDep = rcp(new NumberArrayLengthDependency<int, double>( list1->getEntryRCP("double parameter"), list1->getEntryRCP("array parameter"))), InvalidDependencyException); TEST_THROW(numArrayLengthDep = rcp(new NumberArrayLengthDependency<int, double>( list1->getEntryRCP("int parameter"), list1->getEntryRCP("double parameter"))), InvalidDependencyException); /* * Testing StringValidatorDependency exceptions. */ RCP<StringToIntegralParameterEntryValidator<int> > cheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Swiss", "American", "Super Awesome Cheese"), "Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > sodaValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ), "Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > chipsValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand"), "Food Selector" ) ); list1->set( "string 2 parameter", "Swiss", "second string parameter", cheeseValidator); StringValidatorDependency::ValueToValidatorMap testValidatorMap1; testValidatorMap1["Cheese"] = cheeseValidator; testValidatorMap1["Soda"] = sodaValidator; testValidatorMap1["Chips"] = chipsValidator; TEST_THROW(RCP<StringValidatorDependency> stringValiDep = RCP<StringValidatorDependency>( new StringValidatorDependency( list1->getEntryRCP("int parameter"), list1->getEntryRCP("string 2 parameter"), testValidatorMap1)), InvalidDependencyException); RCP<EnhancedNumberValidator<int> > intVali = rcp(new EnhancedNumberValidator<int>(0,20)); testValidatorMap1["Candy"] = intVali; TEST_THROW(RCP<StringValidatorDependency> stringValiDep = RCP<StringValidatorDependency>( new StringValidatorDependency( list1->getEntryRCP("string parameter"), list1->getEntryRCP("string 2 parameter"), testValidatorMap1)), InvalidDependencyException); StringValidatorDependency::ValueToValidatorMap emptyMap; TEST_THROW(RCP<StringValidatorDependency> stringValiDep = RCP<StringValidatorDependency>( new StringValidatorDependency( list1->getEntryRCP("string parameter"), list1->getEntryRCP("string 2 parameter"), emptyMap)), InvalidDependencyException); /* * Testing BoolValidatorDependency exceptions. */ RCP<EnhancedNumberValidator<double> > doubleVali1 = rcp(new EnhancedNumberValidator<double>(0.0,20.0)); RCP<EnhancedNumberValidator<double> > doubleVali2 = rcp(new EnhancedNumberValidator<double>(5.0,20.0)); list1->set("double parameter", 6.0, "double parameter", doubleVali1); TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = RCP<BoolValidatorDependency>( new BoolValidatorDependency( list1->getEntryRCP("int parameter"), list1->getEntryRCP("double parameter"), doubleVali1, doubleVali2)), InvalidDependencyException); TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = RCP<BoolValidatorDependency>( new BoolValidatorDependency( list1->getEntryRCP("bool parameter"), list1->getEntryRCP("double parameter"), intVali, doubleVali2)), InvalidDependencyException); TEST_THROW(RCP<BoolValidatorDependency> boolValiDep = RCP<BoolValidatorDependency>( new BoolValidatorDependency( list1->getEntryRCP("bool parameter"), list1->getEntryRCP("double parameter"), doubleVali1, intVali)), InvalidDependencyException); /* * Testing RangeValidatorDependency exceptions. */ list1->set("Cheese to Fondue", "Swiss", "the cheese to fondue"); RCP<StringToIntegralParameterEntryValidator<int> > lowTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "PepperJack", "Swiss", "American" ), "Cheese to Fondue" ) ); RCP<StringToIntegralParameterEntryValidator<int> > highTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>("Munster", "Provalone", "Kurtis Super Awesome Cheese"), "Cheese to Fondue" ) ); list1->set( "Cheese to Fondue", "Swiss", "the cheese to fondue", lowTempCheeseValidator); RangeValidatorDependency<double>::RangeToValidatorMap tempranges; tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator; tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator; TEST_THROW( RCP<RangeValidatorDependency<double> > cheeseTempDep = RCP<RangeValidatorDependency<double> >( new RangeValidatorDependency<double>( list1->getEntryRCP("string parameter"), list1->getEntryRCP("Cheese to Fondue"), tempranges ) ), InvalidDependencyException ); tempranges[std::pair<double,double>(400,800)] = intVali; TEST_THROW( RCP<RangeValidatorDependency<double> > cheeseTempDep = RCP<RangeValidatorDependency<double> >( new RangeValidatorDependency<double>( list1->getEntryRCP("int parameter"), list1->getEntryRCP("Cheese to Fondue"), tempranges ) ), InvalidDependencyException ); RangeValidatorDependency<double>::RangeToValidatorMap emptyMap2; TEST_THROW( RCP<RangeValidatorDependency<double> > emptyMapDep = RCP<RangeValidatorDependency<double> >( new RangeValidatorDependency<double>( list1->getEntryRCP("double parameter"), list1->getEntryRCP("Cheese to Fondue"), emptyMap2 ) ), InvalidDependencyException ); RangeValidatorDependency<int>::RangeToValidatorMap badRanges; tempranges[std::pair<int,int>(200,100)] = lowTempCheeseValidator; TEST_THROW( RCP<RangeValidatorDependency<int> > cheeseTempDep = RCP<RangeValidatorDependency<int> >( new RangeValidatorDependency<int>( list1->getEntryRCP("string parameter"), list1->getEntryRCP("Cheese to Fondue"), badRanges ) ), InvalidDependencyException ); }
/** * Test all the validator dependencies. */ TEUCHOS_UNIT_TEST(Teuchos_Dependencies, testValiDeps){ RCP<ParameterList> My_deplist = rcp(new ParameterList); RCP<DependencySheet> depSheet1 = rcp(new DependencySheet); /* * Testing StringValidatorDependency */ RCP<StringToIntegralParameterEntryValidator<int> > stringFoodTypeValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Cheese", "Soda", "Chips" ) ,"Food Type" ) ); RCP<StringToIntegralParameterEntryValidator<int> > cheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Swiss", "American", "Super Awesome Cheese" ) ,"Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > sodaValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Pepsi", "Coke", "Kurtis Cola", "Bad Cola" ) ,"Food Selector" ) ); RCP<StringToIntegralParameterEntryValidator<int> > chipsValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Lays", "Doritos", "Kurtis Super Awesome Brand" ) ,"Food Selector" ) ); StringValidatorDependency::ValueToValidatorMap testValidatorMap1; testValidatorMap1["Cheese"] = cheeseValidator; testValidatorMap1["Soda"] = sodaValidator; testValidatorMap1["Chips"] = chipsValidator; ParameterList stringValiDepList = My_deplist->sublist( "String Validator Dependency", false, "String Validator Dependency testing list."); stringValiDepList.set( "Food Selector", "Swiss", "select the food you want", cheeseValidator); stringValiDepList.set( "Food Type", "Cheese", "String Validator Dependency Tester", stringFoodTypeValidator); RCP<StringValidatorDependency> stringValiDep = rcp( new StringValidatorDependency( stringValiDepList.getEntryRCP("Food Type"), stringValiDepList.getEntryRCP("Food Selector"), testValidatorMap1, cheeseValidator ) ); depSheet1->addDependency(stringValiDep); TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); TEST_ASSERT(depSheet1->hasDependents( stringValiDepList.getEntryRCP("Food Type"))); RCP<const DependencySheet::DepSet> stringValiDepSet = depSheet1->getDependenciesForParameter( stringValiDepList.getEntryRCP("Food Type")); TEST_ASSERT(stringValiDepSet->size() == 1); stringValiDepList.set("Food Type","Soda"); stringValiDep->evaluate(); TEST_ASSERT(stringValiDepList.getEntry("Food Selector").validator() == sodaValidator); TEST_THROW(stringValiDepList.validateParameters(stringValiDepList), Exceptions::InvalidParameterValue); stringValiDepList.set("Food Selector", "Pepsi"); TEST_NOTHROW(stringValiDepList.validateParameters(stringValiDepList)); /* * Tesing some different aspects of the StringValidatorDependency */ ParameterList stringValiDepList2 = My_deplist->sublist( "String Validator Dependency (other validators)", false, "String validator testing" ); RCP<StringToIntegralParameterEntryValidator<int> > stringRangeValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "1-10", "10-33", "50-60" ), "Range selector" ) ); RCP<EnhancedNumberValidator<int> > range110Vali = rcp(new EnhancedNumberValidator<int>(1,10)); RCP<EnhancedNumberValidator<int> > range1033Vali = rcp(new EnhancedNumberValidator<int>(10,33)); RCP<EnhancedNumberValidator<int> > range5060Vali = rcp(new EnhancedNumberValidator<int>(50,60)); stringValiDepList2.set("Range selector", "1-10", "selects the range to validate", stringRangeValidator); StringValidatorDependency::ValueToValidatorMap rangeValidatorMap1; rangeValidatorMap1["1-10"] = range110Vali; rangeValidatorMap1["10-33"] = range1033Vali; rangeValidatorMap1["50-60"] = range5060Vali; stringValiDepList2.set( "RangeValue", 3, "the value of the range", range110Vali); RCP<StringValidatorDependency> stringValiDep2 = RCP<StringValidatorDependency>( new StringValidatorDependency( stringValiDepList2.getEntryRCP("Range selector"), stringValiDepList2.getEntryRCP("RangeValue"), rangeValidatorMap1, range110Vali ) ); depSheet1->addDependency(stringValiDep2); TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); TEST_ASSERT(depSheet1->hasDependents( stringValiDepList2.getEntryRCP("Range selector"))); RCP<const DependencySheet::DepSet> stringValiDepSet2 = depSheet1->getDependenciesForParameter( stringValiDepList2.getEntryRCP("Range selector")); TEST_ASSERT(stringValiDepSet2->size() == 1); stringValiDepList2.set("Range selector","50-60"); stringValiDep2->evaluate(); TEST_ASSERT(stringValiDepList2.getEntry("RangeValue").validator() == range5060Vali); TEST_THROW(stringValiDepList2.validateParameters(stringValiDepList2), Exceptions::InvalidParameterValue); stringValiDepList2.set("RangeValue", 55); TEST_NOTHROW(stringValiDepList2.validateParameters(stringValiDepList2)); /* * Testing the BoolValidatorDependency. */ ParameterList boolValidatorDepList = My_deplist->sublist( "Bool Validator Dependency List", false, "Bool Validator Dependency testing list." ); boolValidatorDepList.set("Use Validator?", true, "truns the validator on and off"); RCP<EnhancedNumberValidator<int> > basicVali = rcp(new EnhancedNumberValidator<int>(1,10)); RCP<EnhancedNumberValidator<int> > basicVali2 = rcp(new EnhancedNumberValidator<int>()); boolValidatorDepList.set("do I have a validator?", 4, "does it have a validator?", basicVali); RCP<BoolValidatorDependency> boolValiDep = RCP<BoolValidatorDependency>( new BoolValidatorDependency( boolValidatorDepList.getEntryRCP("Use Validator?"), boolValidatorDepList.getEntryRCP("do I have a validator?"), basicVali, basicVali2 ) ); depSheet1->addDependency(boolValiDep); TEST_ASSERT(depSheet1->hasDependents( boolValidatorDepList.getEntryRCP("Use Validator?"))); TEST_ASSERT( boolValidatorDepList.getEntry("do I have a validator?").validator() == basicVali); TEST_NOTHROW( boolValidatorDepList.validateParameters(boolValidatorDepList)); RCP<const DependencySheet::DepSet> boolValiDepSet = depSheet1->getDependenciesForParameter(boolValidatorDepList.getEntryRCP( "Use Validator?")); TEST_ASSERT(boolValiDepSet->size() == 1); boolValidatorDepList.set("Use Validator?",false); boolValiDep->evaluate(); TEST_ASSERT( boolValidatorDepList.getEntry("do I have a validator?").validator() == basicVali2); /* * Testing the RangeValidatorDependency */ RCP<StringToIntegralParameterEntryValidator<int> > lowTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "PepperJack", "Swiss", "American" ), "Cheese to Fondue" ) ); RCP<StringToIntegralParameterEntryValidator<int> > highTempCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Munster", "Provalone", "Kurtis Super Awesome Cheese"), "Cheese to Fondue" ) ); RCP<StringToIntegralParameterEntryValidator<int> > defaultCheeseValidator = rcp( new StringToIntegralParameterEntryValidator<int>( tuple<std::string>( "Other cheese", "other cheese 1", "other cheese 3"), "Cheese to Fondue" ) ); ParameterList& rangeValidatorDepList = My_deplist->sublist( "Range Validator Dependency List", false, "Range Validator Dependency testing list.\nWorking June 27th 2009" ); rangeValidatorDepList.set( "Temperature",101.0, "The temperature of the fondue"); rangeValidatorDepList.set( "Cheese to Fondue", "Swiss", "The cheese we'll be using in our fondue pot.", lowTempCheeseValidator); RangeValidatorDependency<double>::RangeToValidatorMap tempranges; tempranges[std::pair<double,double>(100,200)] = lowTempCheeseValidator; tempranges[std::pair<double,double>(200,300)] = highTempCheeseValidator; RCP<RangeValidatorDependency<double> > cheeseTempDep = RCP<RangeValidatorDependency<double> >( new RangeValidatorDependency<double>( rangeValidatorDepList.getEntryRCP("Temperature"), rangeValidatorDepList.getEntryRCP("Cheese to Fondue"), tempranges, defaultCheeseValidator ) ); depSheet1->addDependency(cheeseTempDep); TEST_ASSERT(depSheet1->hasDependents( rangeValidatorDepList.getEntryRCP("Temperature"))); RCP<const DependencySheet::DepSet> rangeValiDepSet = depSheet1->getDependenciesForParameter( rangeValidatorDepList.getEntryRCP("Temperature")); TEST_ASSERT(rangeValiDepSet->size() == 1); rangeValidatorDepList.set("Temperature",250.0); cheeseTempDep->evaluate(); TEST_ASSERT( rangeValidatorDepList.getEntry("Cheese to Fondue").validator() == highTempCheeseValidator); TEST_THROW( rangeValidatorDepList.validateParameters(rangeValidatorDepList), Exceptions::InvalidParameterValue); rangeValidatorDepList.set("Cheese to Fondue", "Provalone"); TEST_NOTHROW( rangeValidatorDepList.validateParameters(rangeValidatorDepList)); rangeValidatorDepList.set("Temperature", 50.0); cheeseTempDep->evaluate(); TEST_ASSERT( rangeValidatorDepList.getEntry("Cheese to Fondue").validator() == defaultCheeseValidator ); }
TEUCHOS_UNIT_TEST( Rythmos_ConvergenceTestHelpers, create ) { LinearRegression<double> lr; TEST_THROW(lr.getSlope(), std::logic_error); TEST_THROW(lr.getYIntercept(), std::logic_error); }