X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=blobdiff_plain;f=check%2Fexam_numeric.cpp;h=1be029857dfb889f1ab6bf7b146163f9eb07bb06;hp=04cf3547626d502b5b02958b5722ffb4cb129220;hb=2dcbb3a4955e294d62b45c3db8bdccb7d6fdf833;hpb=af922d5eb36ed70e4a9e3ffaf4c24492cf89a1a6 diff --git a/check/exam_numeric.cpp b/check/exam_numeric.cpp index 04cf3547..1be02985 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-2002 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 @@ -23,6 +23,8 @@ #include "exams.h" +#include + /* Simple and maybe somewhat pointless consistency tests of assorted tests and * conversions. */ static unsigned exam_numeric1(void) @@ -38,18 +40,18 @@ static unsigned exam_numeric1(void) if (!test_int1.is_integer()) { clog << test_int1 - << " erroneously not recognized as integer" << endl; + << " erroneously not recognized as integer" << endl; ++result; } if (!test_int1.is_rational()) { clog << test_int1 - << " erroneously not recognized as rational" << endl; + << " erroneously not recognized as rational" << endl; ++result; } if (!test_rat1.is_rational()) { clog << test_rat1 - << " erroneously not recognized as rational" << endl; + << " erroneously not recognized as rational" << endl; ++result; } if (test_rat1.is_integer()) { @@ -60,28 +62,28 @@ static unsigned exam_numeric1(void) if (!test_crat.is_crational()) { clog << test_crat - << " erroneously not recognized as complex rational" << endl; + << " erroneously not recognized as complex rational" << endl; ++result; } int i = numeric(1984).to_int(); if (i-1984) { clog << "conversion of " << i - << " from numeric to int failed" << endl; + << " from numeric to int failed" << endl; ++result; } e1 = test_int1; if (!e1.info(info_flags::posint)) { clog << "expression " << e1 - << " erroneously not recognized as positive integer" << endl; + << " erroneously not recognized as positive integer" << endl; ++result; } 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; + << " erroneously recognized as integer" << endl; ++result; } @@ -90,7 +92,7 @@ static unsigned exam_numeric1(void) test_rat1 += test_rat1; if (!test_rat1.is_integer()) { clog << "3/2 + 3/2 erroneously not integer 3 but instead " - << test_rat1 << endl; + << test_rat1 << endl; ++result; } test_rat1 = numeric(3)/numeric(2); @@ -98,7 +100,7 @@ static unsigned exam_numeric1(void) test_rat2 -= test_rat1; // 1 if (!test_rat2.is_integer()) { clog << "5/2 - 3/2 erroneously not integer 1 but instead " - << test_rat2 << endl; + << test_rat2 << endl; ++result; } @@ -162,7 +164,7 @@ static unsigned exam_numeric3(void) a = 23; b = 4; calc_rem = irem(a, b); if (calc_rem != 3) { clog << "irem(" << a << "," << b << ") erroneously returned " - << calc_rem << endl; + << calc_rem << endl; ++result; } a = 23; b = -4; calc_rem = irem(a, b); @@ -174,38 +176,38 @@ static unsigned exam_numeric3(void) a = -23; b = 4; calc_rem = irem(a, b); if (calc_rem != -3) { clog << "irem(" << a << "," << b << ") erroneously returned " - << calc_rem << endl; + << calc_rem << endl; ++result; } a = -23; b = -4; calc_rem = irem(a, b); if (calc_rem != -3) { clog << "irem(" << a << "," << b << ") erroneously returned " - << calc_rem << endl; + << calc_rem << endl; ++result; } // and now the overloaded irem(a,b,q): a = 23; b = 4; calc_rem = irem(a, b, calc_quo); if (calc_rem != 3 || calc_quo != 5) { clog << "irem(" << a << "," << b << ",q) erroneously returned " - << calc_rem << " with q=" << calc_quo << endl; + << calc_rem << " with q=" << calc_quo << endl; ++result; } a = 23; b = -4; calc_rem = irem(a, b, calc_quo); if (calc_rem != 3 || calc_quo != -5) { clog << "irem(" << a << "," << b << ",q) erroneously returned " - << calc_rem << " with q=" << calc_quo << endl; + << calc_rem << " with q=" << calc_quo << endl; ++result; } a = -23; b = 4; calc_rem = irem(a, b, calc_quo); if (calc_rem != -3 || calc_quo != -5) { clog << "irem(" << a << "," << b << ",q) erroneously returned " - << calc_rem << " with q=" << calc_quo << endl; + << calc_rem << " with q=" << calc_quo << endl; ++result; } a = -23; b = -4; calc_rem = irem(a, b, calc_quo); if (calc_rem != -3 || calc_quo != 5) { clog << "irem(" << a << "," << b << ",q) erroneously returned " - << calc_rem << " with q=" << calc_quo << endl; + << calc_rem << " with q=" << calc_quo << endl; ++result; } // check if iquo(a, b) and iquo(a, b, r) really behave like Maple's @@ -215,50 +217,50 @@ static unsigned exam_numeric3(void) a = 23; b = 4; calc_quo = iquo(a, b); if (calc_quo != 5) { clog << "iquo(" << a << "," << b << ") erroneously returned " - << calc_quo << endl; + << calc_quo << endl; ++result; } a = 23; b = -4; calc_quo = iquo(a, b); if (calc_quo != -5) { clog << "iquo(" << a << "," << b << ") erroneously returned " - << calc_quo << endl; + << calc_quo << endl; ++result; } a = -23; b = 4; calc_quo = iquo(a, b); if (calc_quo != -5) { clog << "iquo(" << a << "," << b << ") erroneously returned " - << calc_quo << endl; + << calc_quo << endl; ++result; } a = -23; b = -4; calc_quo = iquo(a, b); if (calc_quo != 5) { clog << "iquo(" << a << "," << b << ") erroneously returned " - << calc_quo << endl; + << calc_quo << endl; ++result; } // and now the overloaded iquo(a,b,r): a = 23; b = 4; calc_quo = iquo(a, b, calc_rem); if (calc_quo != 5 || calc_rem != 3) { clog << "iquo(" << a << "," << b << ",r) erroneously returned " - << calc_quo << " with r=" << calc_rem << endl; + << calc_quo << " with r=" << calc_rem << endl; ++result; } a = 23; b = -4; calc_quo = iquo(a, b, calc_rem); if (calc_quo != -5 || calc_rem != 3) { clog << "iquo(" << a << "," << b << ",r) erroneously returned " - << calc_quo << " with r=" << calc_rem << endl; + << calc_quo << " with r=" << calc_rem << endl; ++result; } a = -23; b = 4; calc_quo = iquo(a, b, calc_rem); if (calc_quo != -5 || calc_rem != -3) { clog << "iquo(" << a << "," << b << ",r) erroneously returned " - << calc_quo << " with r=" << calc_rem << endl; + << calc_quo << " with r=" << calc_rem << endl; ++result; } a = -23; b = -4; calc_quo = iquo(a, b, calc_rem); if (calc_quo != 5 || calc_rem != -3) { clog << "iquo(" << a << "," << b << ",r) erroneously returned " - << calc_quo << " with r=" << calc_rem << endl; + << calc_quo << " with r=" << calc_rem << endl; ++result; } @@ -274,11 +276,9 @@ static unsigned exam_numeric4(void) // square roots of squares of integers: passed = true; - for (int i=0; i<42; ++i) { - if (!sqrt(numeric(i*i)).is_integer()) { + for (int i=0; i<42; ++i) + if (!sqrt(numeric(i*i)).is_integer()) passed = false; - } - } if (!passed) { clog << "One or more square roots of squares of integers did not return exact integers" << endl; ++result; @@ -286,13 +286,10 @@ static unsigned exam_numeric4(void) // square roots of squares of rationals: passed = true; - for (int num=0; num<41; ++num) { - for (int den=1; den<42; ++den) { - if (!sqrt(numeric(num*num)/numeric(den*den)).is_rational()) { + for (int num=0; num<41; ++num) + for (int den=1; den<42; ++den) + if (!sqrt(numeric(num*num)/numeric(den*den)).is_rational()) passed = false; - } - } - } if (!passed) { clog << "One or more square roots of squares of rationals did not return exact integers" << endl; ++result; @@ -313,13 +310,69 @@ static unsigned exam_numeric5(void) ex e2 = expand(e1 - 10 + 5*pow(3,numeric(3,5))); if (!e2.is_zero()) { clog << "expand((1+3^(1/5)-3^(2/5))^3-10+5*3^(3/5)) returned " - << e2 << " instead of 0." << endl; + << e2 << " instead of 0." << endl; ++result; } return result; } +/* This test checks whether the numeric output/parsing routines are + consistent. */ +static unsigned exam_numeric6(void) +{ + 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