1 /** @file exam_structure.cpp
3 * Small test for the structure<> template. */
6 * GiNaC Copyright (C) 1999-2004 Johannes Gutenberg University Mainz, Germany
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 sprod_s(const ex & l, const ex & r) : left(l), right(r) {}
33 inline bool operator==(const sprod_s & lhs, const sprod_s & rhs)
35 return lhs.left.is_equal(rhs.left) && lhs.right.is_equal(rhs.right);
38 inline bool operator<(const sprod_s & lhs, const sprod_s & rhs)
40 return lhs.left.compare(rhs.left) < 0 ? true : lhs.right.compare(rhs.right) < 0;
43 typedef structure<sprod_s, compare_std_less> sprod;
45 inline ex make_sprod(const ex & l, const ex & r)
47 return sprod(sprod_s(l, r));
50 void sprod::print(const print_context & c, unsigned level) const
52 const sprod_s & sp = get_struct();
53 c.s << "<" << sp.left << "|" << sp.right << ">";
56 ex sprod::eval(int level) const
58 // symmetric scalar product
59 const sprod_s & sp = get_struct();
60 if (sp.left.compare(sp.right) <= 0)
63 return make_sprod(sp.right, sp.left);
66 unsigned exam_structure()
70 cout << "examining structure template" << flush;
71 clog << "----------structure template:" << endl;
73 symbol x("x"), y("y");
76 e = make_sprod(x, y) - make_sprod(y, x);
78 clog << "<x|y>-<y|x> erroneously returned " << e << " instead of 0" << endl;
84 e = make_sprod(x, x) - make_sprod(y, y);
86 clog << "<x|x>-<y|y> erroneously returned 0" << endl;
93 cout << " passed " << endl;
94 clog << "(no output)" << endl;
96 cout << " failed " << endl;