4 #include "ginac/ginac.h"
10 using namespace GiNaC;
13 DECLARE_FUNCTION_2P(foobar);
15 static bool eval_called = false;
16 static exvector eval_called_with = {};
17 static bool evalf_called = false;
18 static exvector evalf_called_with = {};
21 eval_called_with.clear();
22 evalf_called_with.clear();
27 static ex foobar_eval(const exvector& args) {
29 for (auto const& v: args)
30 eval_called_with.push_back(v);
32 return foobar(args[0], args[1]).hold();
35 static ex foobar_evalf(const exvector& args) {
37 for (auto const& v: args)
38 evalf_called_with.push_back(v);
39 return foobar(args[0], args[1]).hold();
43 REGISTER_FUNCTION(foobar, eval_func(foobar_eval).
44 evalf_func(foobar_evalf));
46 static int check_exvector_eval() {
47 symbol x("x"), y("y");
53 clog << "*** Error: " << __func__ << ": foobar_eval hasn't been called" << endl;
56 if (eval_called_with.size() != 2) {
57 clog << "*** Error: " << __func__ << ": fobar_eval: expected 2 arguments, got " <<
58 eval_called_with.size() << endl;
61 if (eval_called_with[0] != x) {
62 clog << "*** Error: " << __func__ << ": fobar_eval: wrong 1st argument, "
63 "expected " << x << ", got " << eval_called_with[0] << endl;
66 if (eval_called_with[1] != y) {
67 clog << "*** Error: " << __func__ << ": fobar_eval: wrong 1st argument, "
68 "expected " << y << ", got " << eval_called_with[1] << endl;
74 static int check_exvector_evalf() {
78 ex e = foobar(Pi, Euler);
82 clog << "*** Error: " << __func__ << ": foobar_evalf hasn't been called" << endl;
85 if (evalf_called_with.size() != 2) {
86 clog << __func__ << ": foobar_evalf: expected 2 arguments, got " <<
87 evalf_called_with.size() << endl;
90 if (!is_a<numeric>(evalf_called_with[0])) {
91 clog << "*** Error: " << __func__ << ": wrong 1st argument of foobar_evalf: "
92 "expected a real number, got " << evalf_called_with[0] << endl;
95 if (!is_a<numeric>(evalf_called_with[1])) {
96 clog << "*** Error: " << __func__ << ": wrong 1st argument of foobar_evalf: "
97 "expected a real number, got " << evalf_called_with[0] << endl;
103 int main(int argc, char** argv) {
105 auto err = check_exvector_evalf();
108 clog << "*** Error " << (err + 1) << " (check_exvector_evalf)" << endl;
110 err = check_exvector_eval();
113 clog << "*** Error " << (err + 1) << " (check_exvector_evalf)" << endl;