MAST
Multidisciplinary-design Adaptation and Sensitivity Toolkit (MAST)
mast_function_set_base.cpp
Go to the documentation of this file.
1 /*
2  * MAST: Multidisciplinary-design Adaptation and Sensitivity Toolkit
3  * Copyright (C) 2013-2020 Manav Bhatia and MAST authors
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "catch.hpp"
21 
22 #include "base/parameter.h"
24 #include "base/function_set_base.h"
25 
26 TEST_CASE("function_set_base",
27  "[base][function_set_base]")
28 {
29  MAST::Parameter param("dummy_param", 482.222);
30  MAST::Parameter param2("unused_param", 5.5);
31 
32  MAST::ConstantFieldFunction dummy_f("dummy", param);
33 
35 
36  // Ensure field functions can be added
37  REQUIRE_NOTHROW( f_set.add(dummy_f) );
38 
39  SECTION("function_set_contains")
40  {
41  // Ensure the correct boolean value is return when checking if a function
42  // set depends on a particular field function
43  REQUIRE( f_set.contains("dummy") );
44  REQUIRE_FALSE( f_set.contains("dummy2") );
45  }
46 
47  SECTION("function_set_depends_on")
48  {
49  // Ensure the correct boolean value is returned when checking if a function
50  // set depends on a particular parameter
51  REQUIRE( f_set.depends_on(param) );
52  REQUIRE_FALSE( f_set.depends_on(param2) );
53  }
54 
55  SECTION("function_set_get_existing_field_function")
56  {
57  // Ensure no error is thrown when retrieving a field function from the
58  // function set
59  REQUIRE_NOTHROW( f_set.get<MAST::FieldFunction<Real>>("dummy") );
60  }
61 
62  SECTION("function_set_get_nonexistant_field_function_error")
63  {
64  // Ensure an error is thrown when the requested field function doesn't
65  // exist in the function set
66  REQUIRE_THROWS( f_set.get<MAST::FieldFunction<Real>>("does_not_exist") );
67  }
68 }
This is a scalar function whose value can be changed and one that can be used as a design variable in...
Definition: parameter.h:35
void add(MAST::FunctionBase &f)
adds the function to this card and returns a reference to it.
bool contains(const std::string &nm) const
checks if the card contains the specified property value
provides a methods to store property values
const ValType & get(const std::string &nm) const
returns a constant reference to the specified function
virtual bool depends_on(const MAST::FunctionBase &f) const
returns true if the property card depends on the function f
TEST_CASE("function_set_base", "[base][function_set_base]")