]> www.ginac.de Git - ginac.git/commitdiff
Add simple exam test for releational objects.
authorRichard Kreckel <kreckel@ginac.de>
Sun, 6 Jun 2021 12:48:00 +0000 (14:48 +0200)
committerRichard Kreckel <kreckel@ginac.de>
Sun, 6 Jun 2021 12:53:38 +0000 (14:53 +0200)
check/.gitignore
check/CMakeLists.txt
check/Makefile.am
check/exam_relational.cpp [new file with mode: 0644]

index 633cf233b8f0a733be1570c15fb87fb1c2702265..6da20c838e6293cf5699281103fff0ec1085e5db 100644 (file)
@@ -8,6 +8,7 @@ exam_collect
 exam_color
 exam_differentiation
 exam_factor
+exam_function_exvector
 exam_heur_gcd
 exam_indexed
 exam_inifcns
@@ -23,6 +24,7 @@ exam_sqrfree
 exam_numeric
 exam_paranoia
 exam_polygcd
+exam_relational
 exam_collect_common_factors
 exam_powerlaws
 exam_pseries
index 663dbbdeb150f4a6ad67c5c0a50e8ee077baaed0..db9491151e1ed3cdc441d4f095f497eb75ea7dc2 100644 (file)
@@ -5,6 +5,7 @@ set(ginac_exams
        exam_match
        exam_parser
        exam_numeric
+       exam_relational
        exam_powerlaws
        exam_collect
        exam_inifcns
index 8fa225f3f4847238b636cd1604bdb9145c601e23..0c119d52c2bfaf1ccea587921bb158a41b0c02ec 100644 (file)
@@ -5,6 +5,7 @@ EXAMS = exam_paranoia \
        exam_match \
        exam_parser \
        exam_numeric \
+       exam_relational \
        exam_powerlaws \
        exam_collect \
        exam_inifcns \
@@ -81,6 +82,9 @@ exam_parser_LDADD = ../ginac/libginac.la
 exam_numeric_SOURCES = exam_numeric.cpp
 exam_numeric_LDADD = ../ginac/libginac.la
 
+exam_relational_SOURCES = exam_relational.cpp
+exam_relational_LDADD = ../ginac/libginac.la
+
 exam_powerlaws_SOURCES = exam_powerlaws.cpp
 exam_powerlaws_LDADD = ../ginac/libginac.la
 
diff --git a/check/exam_relational.cpp b/check/exam_relational.cpp
new file mode 100644 (file)
index 0000000..3b652b0
--- /dev/null
@@ -0,0 +1,135 @@
+/** @file exam_relational.cpp
+ *
+ *  Small test for the relational objects and their conversion to bool. */
+
+/*
+ *  GiNaC Copyright (C) 1999-2021 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "ginac.h"
+using namespace GiNaC;
+
+#include <iostream>
+using namespace std;
+
+// Elementary relations should fall back to numeric comparisons.
+static unsigned exam_relational_elementary()
+{
+       unsigned result = 0;
+       ex one = 1, two = 2;
+
+       if (one == two) {
+               clog << "'" << one << " == " << two << "' was converted to true." << endl;
+               result += 1;
+       }
+       if (!(one != two)) {
+               clog << "'" << one << " != " << two << "' was not converted to true." << endl;
+               result += 1;
+       }
+       if (!(one < two)) {
+               clog << "'" << one << " < " << two << "' was not converted to true." << endl;
+               result += 1;
+       }
+       if (!(one <= two)) {
+               clog << "'" << one << " <= " << two << "' was not converted to true." << endl;
+               result += 1;
+       }
+       if (one > two) {
+               clog << "'" << one << " > " << two << "' was converted to true." << endl;
+               result += 1;
+       }
+       if (one >= two) {
+               clog << "'" << one << " >= " << two << "' was converted to true." << endl;
+               result += 1;
+       }
+
+       return result;
+}
+
+// These should fall back to looking up info flags.
+static unsigned exam_relational_possymbol()
+{
+       unsigned result = 0;
+       possymbol p("p");
+
+       if (p == 0) {
+               clog << "for positive p, 'p == 0' was converted to true." << endl;
+               result += 1;
+       }
+       if (!(p != 0)) {
+               clog << "for positive p, 'p != 0' was not converted to true." << endl;
+               result += 1;
+       }
+       if (p < 0) {
+               clog << "for positive p, 'p < 0' was converted to true." << endl;
+               result += 1;
+       }
+       if (p <= 0) {
+               clog << "for positive p, 'p <= 0' was converted to true." << endl;
+               result += 1;
+       }
+       if (!(p > 0)) {
+               clog << "for positive p, 'p > 0' was not converted to true." << endl;
+               result += 1;
+       }
+       if (!(p >= 0)) {
+               clog << "for positive p, 'p >= 0' was not converted to true." << endl;
+               result += 1;
+       }
+
+       return result;
+}
+
+// Very simple arithmetic should be supported, too.
+static unsigned exam_relational_arith()
+{
+       unsigned result = 0;
+       possymbol p("p");
+
+       if (!(p + 2 > p + 1)) {
+               clog << "for positive p, 'p + 2 > p + 1' was not converted to true." << endl;
+               result += 1;
+       }
+       if (!(p > -p)) {
+               clog << "for positive p, 'p > -p' was not converted to true." << endl;
+               result += 1;
+       }
+       if (!(2*p > p)) {
+               clog << "for positive p, '2*p > p' was not converted to true." << endl;
+               result += 1;
+       }
+
+       return result;
+}
+
+unsigned exam_relational()
+{
+       unsigned result = 0;
+
+       cout << "examining relational objects" << flush;
+
+       result += exam_relational_elementary(); cout << '.' << flush;
+       result += exam_relational_possymbol(); cout << '.' << flush;
+       result += exam_relational_arith(); cout << '.' << flush;
+
+       return result;
+}
+
+int main(int argc, char** argv)
+{
+       return exam_relational();
+}