X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_numeric.cpp;h=d5ae27b27a1e5da5354271a5e65e90703e035c90;hp=aa7bb2d79070ae7e87676630eddec90bc9bd67df;hb=b23a2dfdcd478b00a11c6c2184fbe197a3ac5bfb;hpb=ae3044935ddf13dd325f6e11770357b99bbe6095 diff --git a/check/exam_numeric.cpp b/check/exam_numeric.cpp index aa7bb2d7..d5ae27b2 100644 --- a/check/exam_numeric.cpp +++ b/check/exam_numeric.cpp @@ -4,7 +4,7 @@ * tests on these numbers like is_integer() etc... */ /* - * GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany + * GiNaC Copyright (C) 1999-2011 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 @@ -18,14 +18,19 @@ * * 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 + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#include "exams.h" +#include "ginac.h" +using namespace GiNaC; + +#include +#include +using namespace std; /* Simple and maybe somewhat pointless consistency tests of assorted tests and * conversions. */ -static unsigned exam_numeric1(void) +static unsigned exam_numeric1() { unsigned result = 0; numeric test_int1(42); @@ -63,6 +68,11 @@ static unsigned exam_numeric1(void) << " erroneously not recognized as complex rational" << endl; ++result; } + if (test_crat.info(info_flags::nonnegative)) { + clog << test_crat + << " erroneously recognized as non-negative number" << endl; + ++result; + } int i = numeric(1984).to_int(); if (i-1984) { @@ -79,7 +89,7 @@ static unsigned exam_numeric1(void) } e2 = test_int1 + a; - if (ex_to_numeric(e2).is_integer()) { + if (e2.info(info_flags::integer)) { clog << "expression " << e2 << " erroneously recognized as integer" << endl; ++result; @@ -110,7 +120,7 @@ static unsigned exam_numeric1(void) * Implementing a workaround sadly introduced another bug on May 28th 1999 * that was fixed on May 31st. The workaround turned out to be stupid and * the original bug in CLN was finally killed on September 2nd. */ -static unsigned exam_numeric2(void) +static unsigned exam_numeric2() { unsigned result = 0; @@ -149,7 +159,7 @@ static unsigned exam_numeric2(void) /* Assorted tests to ensure some crucial functions behave exactly as specified * in the documentation. */ -static unsigned exam_numeric3(void) +static unsigned exam_numeric3() { unsigned result = 0; numeric calc_rem, calc_quo; @@ -267,7 +277,7 @@ static unsigned exam_numeric3(void) /* Now we perform some less trivial checks about several functions which should * return exact numbers if possible. */ -static unsigned exam_numeric4(void) +static unsigned exam_numeric4() { unsigned result = 0; bool passed; @@ -298,7 +308,7 @@ static unsigned exam_numeric4(void) /* This test examines that simplifications of the form 5^(3/2) -> 5*5^(1/2) * are carried out properly. */ -static unsigned exam_numeric5(void) +static unsigned exam_numeric5() { unsigned result = 0; @@ -315,25 +325,79 @@ static unsigned exam_numeric5(void) return result; } -unsigned exam_numeric(void) +/* This test checks whether the numeric output/parsing routines are + consistent. */ +static unsigned exam_numeric6() +{ + unsigned result = 0; + + symbol sym("sym"); + vector test_numbers; + test_numbers.push_back(numeric(0)); // zero + test_numbers.push_back(numeric(1)); // one + test_numbers.push_back(numeric(-1)); // minus one + test_numbers.push_back(numeric(42)); // positive integer + test_numbers.push_back(numeric(-42)); // negative integer + test_numbers.push_back(numeric(14,3)); // positive rational + test_numbers.push_back(numeric(-14,3)); // negative rational + test_numbers.push_back(numeric(3.141)); // positive decimal + test_numbers.push_back(numeric(-3.141)); // negative decimal + test_numbers.push_back(numeric(0.1974)); // positive decimal, leading zero + test_numbers.push_back(numeric(-0.1974)); // negative decimal, leading zero + test_numbers.push_back(sym); // symbol + + for (vector::const_iterator br=test_numbers.begin(); br::const_iterator bi=test_numbers.begin(); bi::const_iterator er=test_numbers.begin(); er::const_iterator ei=test_numbers.begin(); ei