From 856927275e5e527071fa6a00b7eba3a5287b44cd Mon Sep 17 00:00:00 2001 From: Christian Bauer Date: Thu, 14 Aug 2003 20:26:15 +0000 Subject: [PATCH] added test for structure<> template --- check/Makefile.am | 8 ++-- check/exam_structure.cpp | 100 +++++++++++++++++++++++++++++++++++++++ check/exams.cpp | 3 +- check/exams.h | 3 +- check/exams.ref | 2 + 5 files changed, 110 insertions(+), 6 deletions(-) create mode 100644 check/exam_structure.cpp diff --git a/check/Makefile.am b/check/Makefile.am index 5cc176e1..6a1c91cc 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -8,10 +8,10 @@ checks_SOURCES = check_numeric.cpp check_inifcns.cpp check_matrices.cpp \ checks_LDADD = ../ginac/libginac.la exams_SOURCES = exam_paranoia.cpp exam_numeric.cpp exam_powerlaws.cpp \ - exam_inifcns.cpp exam_differentiation.cpp exam_polygcd.cpp \ - exam_normalization.cpp exam_pseries.cpp exam_matrices.cpp exam_lsolve.cpp \ - exam_indexed.cpp exam_color.cpp exam_clifford.cpp exam_archive.cpp \ - exam_misc.cpp exam_inifcns_nstdsums.cpp exams.cpp exams.h + exam_inifcns.cpp exam_inifcns_nstdsums.cpp exam_differentiation.cpp \ + exam_polygcd.cpp exam_normalization.cpp exam_pseries.cpp exam_matrices.cpp \ + exam_lsolve.cpp exam_indexed.cpp exam_color.cpp exam_clifford.cpp \ + exam_archive.cpp exam_structure.cpp exam_misc.cpp exams.cpp exams.h exams_LDADD = ../ginac/libginac.la times_SOURCES = time_dennyfliegner.cpp time_gammaseries.cpp \ diff --git a/check/exam_structure.cpp b/check/exam_structure.cpp new file mode 100644 index 00000000..044de03f --- /dev/null +++ b/check/exam_structure.cpp @@ -0,0 +1,100 @@ +/** @file exam_structure.cpp + * + * Small test for the structure<> template. */ + +/* + * GiNaC Copyright (C) 1999-2003 Johannes Gutenberg University Mainz, Germany + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "exams.h" + + +struct sprod_s { + ex left, right; + + sprod_s() {} + sprod_s(const ex & l, const ex & r) : left(l), right(r) {} +}; + +inline bool operator==(const sprod_s & lhs, const sprod_s & rhs) +{ + return lhs.left.is_equal(rhs.left) && lhs.right.is_equal(rhs.right); +} + +inline bool operator<(const sprod_s & lhs, const sprod_s & rhs) +{ + return lhs.left.compare(rhs.left) < 0 ? true : lhs.right.compare(rhs.right) < 0; +} + +typedef structure sprod; + +inline ex make_sprod(const ex & l, const ex & r) +{ + return sprod(sprod_s(l, r)); +} + +void sprod::print(const print_context & c, unsigned level) const +{ + const sprod_s & sp = get_struct(); + c.s << "<" << sp.left << "|" << sp.right << ">"; +} + +ex sprod::eval(int level) const +{ + // symmetric scalar product + const sprod_s & sp = get_struct(); + if (sp.left.compare(sp.right) <= 0) + return hold(); + else + return make_sprod(sp.right, sp.left); +} + +unsigned exam_structure() +{ + unsigned result = 0; + + cout << "examining structure template" << flush; + clog << "----------structure template:" << endl; + + symbol x("x"), y("y"); + ex e; + + e = make_sprod(x, y) - make_sprod(y, x); + if (!e.is_zero()) { + clog << "- erroneously returned " << e << " instead of 0" << endl; + ++result; + } + + cout << '.' << flush; + + e = make_sprod(x, x) - make_sprod(y, y); + if (e.is_zero()) { + clog << "- erroneously returned 0" << endl; + ++result; + } + + cout << '.' << flush; + + if (!result) { + cout << " passed " << endl; + clog << "(no output)" << endl; + } else { + cout << " failed " << endl; + } + + return result; +} diff --git a/check/exams.cpp b/check/exams.cpp index 73004dc7..ed8f814b 100644 --- a/check/exams.cpp +++ b/check/exams.cpp @@ -40,6 +40,7 @@ try { \ EXAM(numeric) EXAM(powerlaws) EXAM(inifcns) + EXAM(inifcns_nstdsums) EXAM(differentiation) EXAM(polygcd) EXAM(normalization) @@ -50,8 +51,8 @@ try { \ EXAM(color) EXAM(clifford) EXAM(archive) + EXAM(structure) EXAM(misc) -// EXAM(inifcns_nstdsums) if (result) { cout << "Error: something went wrong. "; diff --git a/check/exams.h b/check/exams.h index 2b2c0ac2..635ff0de 100644 --- a/check/exams.h +++ b/check/exams.h @@ -33,6 +33,7 @@ unsigned exam_paranoia(); unsigned exam_numeric(); unsigned exam_powerlaws(); unsigned exam_inifcns(); +unsigned exam_inifcns_nstdsums(); unsigned exam_differentiation(); unsigned exam_polygcd(); unsigned exam_normalization(); @@ -43,7 +44,7 @@ unsigned exam_indexed(); unsigned exam_color(); unsigned exam_clifford(); unsigned exam_archive(); +unsigned exam_structure(); unsigned exam_misc(); -unsigned exam_inifcns_nstdsums(); #endif // ndef EXAMS_H diff --git a/check/exams.ref b/check/exams.ref index 86a9512d..e5423dcb 100644 --- a/check/exams.ref +++ b/check/exams.ref @@ -26,5 +26,7 @@ (no output) ----------archiving system: (no output) +----------structure template: +(no output) ----------miscellaneous other things: (no output) -- 2.44.0