From ef7787a325ea1f272ea08d78f2b86c48b6b2b286 Mon Sep 17 00:00:00 2001 From: Richard Kreckel Date: Sun, 6 Jun 2021 14:48:00 +0200 Subject: [PATCH] Add simple exam test for releational objects. --- check/.gitignore | 2 + check/CMakeLists.txt | 1 + check/Makefile.am | 4 ++ check/exam_relational.cpp | 135 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 142 insertions(+) create mode 100644 check/exam_relational.cpp diff --git a/check/.gitignore b/check/.gitignore index 633cf233..6da20c83 100644 --- a/check/.gitignore +++ b/check/.gitignore @@ -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 diff --git a/check/CMakeLists.txt b/check/CMakeLists.txt index 663dbbde..db949115 100644 --- a/check/CMakeLists.txt +++ b/check/CMakeLists.txt @@ -5,6 +5,7 @@ set(ginac_exams exam_match exam_parser exam_numeric + exam_relational exam_powerlaws exam_collect exam_inifcns diff --git a/check/Makefile.am b/check/Makefile.am index 8fa225f3..0c119d52 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -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 index 00000000..3b652b05 --- /dev/null +++ b/check/exam_relational.cpp @@ -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 +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(); +} -- 2.49.0