OPAL (Object Oriented Parallel Accelerator Library) 2024.2
OPAL
PythonExprTest.cpp
Go to the documentation of this file.
1//
2// Test PythonExprTest
3//
4// Copyright (c) 2010 - 2013, Yves Ineichen, ETH Zürich
5// All rights reserved
6//
7// Implemented as part of the PhD thesis
8// "Toward massively parallel multi-objective optimization with application to
9// particle accelerators" (https://doi.org/10.3929/ethz-a-009792359)
10//
11// This file is part of OPAL.
12//
13// OPAL is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// You should have received a copy of the GNU General Public License
19// along with OPAL. If not, see <https://www.gnu.org/licenses/>.
20//
21#include <set>
22#include <string>
23#include <tuple>
24#include <variant>
25
26#include "Util/Types.h"
31
32#include "gtest/gtest.h"
33
34
35namespace {
36
37 // The fixture for testing class Foo.
38 class PythonExprTest : public ::testing::Test {
39 protected:
40
41 PythonExprTest() {
42 // You can do set-up work for each test here.
43 }
44
45 virtual ~PythonExprTest() {
46 // You can do clean-up work that doesn't throw exceptions here.
47 }
48
49 // If the constructor and destructor are not enough for setting up
50 // and cleaning up each test, you can define the following methods:
51
52 virtual void SetUp() {
53 // Code here will be called immediately after the constructor (right
54 // before each test).
55 }
56
57 virtual void TearDown() {
58 // Code here will be called immediately after each test (right
59 // before the destructor).
60 }
61 };
62
63
64 TEST_F(PythonExprTest, EvaluatePythonExpr) {
65
67 double expected = 1.0;
68 expected *= 2.0;
69
72 python = PythonExpression();
73 funcs.insert(std::pair<std::string, client::function::type>
74 ("python", python));
75
76 std::string testexpr = "python(\"resources/test.py\", 1.0)";
77 const std::unique_ptr<Expression> e(new Expression(testexpr, funcs));
79 EXPECT_NO_THROW({
80 result = e->evaluate(vars);
81 });
82
83 ASSERT_EQ(expected, std::get<0>(result));
84 ASSERT_TRUE(std::get<1>(result));
85 }
86
87}
88
89int main(int argc, char **argv) {
90 ::testing::InitGoogleTest(&argc, argv);
91 return RUN_ALL_TESTS();
92}
std::map< std::string, client::function::type > functionDictionary_t
Definition Expression.h:55
std::map< std::string, double > variableDictionary_t
Definition Expression.h:54
int main(int argc, char **argv)
std::tuple< double, bool > Result_t
Definition Expression.h:65
constexpr double e
The value of.
Definition Physics.h:39
std::function< std::tuple< double, bool >(arguments_t)> type
Definition function.hpp:16