]> www.ginac.de Git - ginac.git/commitdiff
added test for structure<> template
authorChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 14 Aug 2003 20:26:15 +0000 (20:26 +0000)
committerChristian Bauer <Christian.Bauer@uni-mainz.de>
Thu, 14 Aug 2003 20:26:15 +0000 (20:26 +0000)
check/Makefile.am
check/exam_structure.cpp [new file with mode: 0644]
check/exams.cpp
check/exams.h
check/exams.ref

index 5cc176e1084f864c645b949e22a3bea8fbd799d4..6a1c91cc1f3fe0c92fb79726746865e8064ae658 100644 (file)
@@ -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 \
 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 \
 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 (file)
index 0000000..044de03
--- /dev/null
@@ -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_s, compare_std_less> 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 << "<x|y>-<y|x> erroneously returned " << e << " instead of 0" << endl;
+               ++result;
+       }
+
+       cout << '.' << flush;
+
+       e = make_sprod(x, x) - make_sprod(y, y);
+       if (e.is_zero()) {
+               clog << "<x|x>-<y|y> erroneously returned 0" << endl;
+               ++result;
+       }
+
+       cout << '.' << flush;
+
+       if (!result) {
+               cout << " passed " << endl;
+               clog << "(no output)" << endl;
+       } else {
+               cout << " failed " << endl;
+       }
+
+       return result;
+}
index 73004dc7e43e65699faf2fde88638670d11e4ef9..ed8f814bcdba599808ee9a033da3a993ffacec6a 100644 (file)
@@ -40,6 +40,7 @@ try { \
        EXAM(numeric)
        EXAM(powerlaws)
        EXAM(inifcns)
        EXAM(numeric)
        EXAM(powerlaws)
        EXAM(inifcns)
+       EXAM(inifcns_nstdsums)
        EXAM(differentiation)
        EXAM(polygcd)
        EXAM(normalization)
        EXAM(differentiation)
        EXAM(polygcd)
        EXAM(normalization)
@@ -50,8 +51,8 @@ try { \
        EXAM(color)
        EXAM(clifford)
        EXAM(archive)
        EXAM(color)
        EXAM(clifford)
        EXAM(archive)
+       EXAM(structure)
        EXAM(misc)
        EXAM(misc)
-//  EXAM(inifcns_nstdsums)
        
        if (result) {
                cout << "Error: something went wrong. ";
        
        if (result) {
                cout << "Error: something went wrong. ";
index 2b2c0ac2dcf94b13570dc81ee1b6621fdd07dc1f..635ff0de49ef36b6462975f7e1e7aad57849412f 100644 (file)
@@ -33,6 +33,7 @@ unsigned exam_paranoia();
 unsigned exam_numeric();
 unsigned exam_powerlaws();
 unsigned exam_inifcns();
 unsigned exam_numeric();
 unsigned exam_powerlaws();
 unsigned exam_inifcns();
+unsigned exam_inifcns_nstdsums();
 unsigned exam_differentiation();
 unsigned exam_polygcd();
 unsigned exam_normalization();
 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_color();
 unsigned exam_clifford();
 unsigned exam_archive();
+unsigned exam_structure();
 unsigned exam_misc();
 unsigned exam_misc();
-unsigned exam_inifcns_nstdsums();
 
 #endif // ndef EXAMS_H
 
 #endif // ndef EXAMS_H
index 86a9512d0c22aa67533637c00ecb7df1a540d790..e5423dcbb8ec541b0c98853d6698743b7710acae 100644 (file)
@@ -26,5 +26,7 @@
 (no output)
 ----------archiving system:
 (no output)
 (no output)
 ----------archiving system:
 (no output)
+----------structure template:
+(no output)
 ----------miscellaneous other things:
 (no output)
 ----------miscellaneous other things:
 (no output)