]> www.ginac.de Git - ginac.git/blobdiff - check/check_inifcns.cpp
lexer: when switching to another output stream, clean last read character.
[ginac.git] / check / check_inifcns.cpp
index bec2ed97c602eb0bc509fce9b96d82c313d20f31..9d493290b5ee854e254e053398ec28d6fa4fe2cf 100644 (file)
@@ -4,7 +4,7 @@
  *  functions. */
 
 /*
  *  functions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2008 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
  *
  *  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
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
  *
  *  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 "checks.h"
+#include <iostream>
+#include <cstdlib> // rand()
+#include "ginac.h"
+using namespace std;
+using namespace GiNaC;
 
 /* Some tests on the sine trigonometric function. */
 
 /* Some tests on the sine trigonometric function. */
-static unsigned inifcns_check_sin(void)
+static unsigned inifcns_check_sin()
 {
        unsigned result = 0;
        bool errorflag = false;
 {
        unsigned result = 0;
        bool errorflag = false;
@@ -39,7 +43,7 @@ static unsigned inifcns_check_sin(void)
        if (errorflag) {
                // we don't count each of those errors
                clog << "sin(n*Pi) with integer n does not always return exact 0"
        if (errorflag) {
                // we don't count each of those errors
                clog << "sin(n*Pi) with integer n does not always return exact 0"
-                        << endl;
+                    << endl;
                ++result;
        }
        
                ++result;
        }
        
@@ -47,13 +51,13 @@ static unsigned inifcns_check_sin(void)
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (!sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (!sin((n+numeric(1,2))*Pi).eval().info(info_flags::integer) ||
-                       !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
-                         sin((n+numeric(1,2))*Pi).eval() == numeric(-1)))
+                   !(sin((n+numeric(1,2))*Pi).eval() == numeric(1) ||
+                     sin((n+numeric(1,2))*Pi).eval() == numeric(-1)))
                        errorflag = true;
        }
        if (errorflag) {
                clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
                        errorflag = true;
        }
        if (errorflag) {
                clog << "sin((n+1/2)*Pi) with integer n does not always return exact {+|-}1"
-                        << endl;
+                    << endl;
                ++result;
        }
        
                ++result;
        }
        
@@ -68,7 +72,7 @@ static unsigned inifcns_check_sin(void)
                argument = n*Pi/60;
                if (abs(sin(evalf(argument))-evalf(sin(argument)))>epsilon) {
                        clog << "sin(" << argument << ") returns "
                argument = n*Pi/60;
                if (abs(sin(evalf(argument))-evalf(sin(argument)))>epsilon) {
                        clog << "sin(" << argument << ") returns "
-                                << sin(argument) << endl;
+                            << sin(argument) << endl;
                        errorflag = true;
                }
        }
                        errorflag = true;
                }
        }
@@ -79,7 +83,7 @@ static unsigned inifcns_check_sin(void)
 }
 
 /* Simple tests on the cosine trigonometric function. */
 }
 
 /* Simple tests on the cosine trigonometric function. */
-static unsigned inifcns_check_cos(void)
+static unsigned inifcns_check_cos()
 {
        unsigned result = 0;
        bool errorflag;
 {
        unsigned result = 0;
        bool errorflag;
@@ -88,12 +92,12 @@ static unsigned inifcns_check_cos(void)
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (cos((n+numeric(1,2))*Pi).eval() != numeric(0) ||
-                       !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer))
+                   !cos((n+numeric(1,2))*Pi).eval().info(info_flags::integer))
                        errorflag = true;
        }
        if (errorflag) {
                clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
                        errorflag = true;
        }
        if (errorflag) {
                clog << "cos((n+1/2)*Pi) with integer n does not always return exact 0"
-                        << endl;
+                    << endl;
                ++result;
        }
        
                ++result;
        }
        
@@ -101,13 +105,13 @@ static unsigned inifcns_check_cos(void)
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (!cos(n*Pi).eval().info(info_flags::integer) ||
        errorflag = false;
        for (int n=-10; n<=10; ++n) {
                if (!cos(n*Pi).eval().info(info_flags::integer) ||
-                       !(cos(n*Pi).eval() == numeric(1) ||
-                         cos(n*Pi).eval() == numeric(-1)))
+                   !(cos(n*Pi).eval() == numeric(1) ||
+                     cos(n*Pi).eval() == numeric(-1)))
                        errorflag = true;
        }
        if (errorflag) {
                clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
                        errorflag = true;
        }
        if (errorflag) {
                clog << "cos(n*Pi) with integer n does not always return exact {+|-}1"
-                        << endl;
+                    << endl;
                ++result;
        }
        
                ++result;
        }
        
@@ -122,7 +126,7 @@ static unsigned inifcns_check_cos(void)
                argument = n*Pi/60;
                if (abs(cos(evalf(argument))-evalf(cos(argument)))>epsilon) {
                        clog << "cos(" << argument << ") returns "
                argument = n*Pi/60;
                if (abs(cos(evalf(argument))-evalf(cos(argument)))>epsilon) {
                        clog << "cos(" << argument << ") returns "
-                                << cos(argument) << endl;
+                            << cos(argument) << endl;
                        errorflag = true;
                }
        }
                        errorflag = true;
                }
        }
@@ -133,7 +137,7 @@ static unsigned inifcns_check_cos(void)
 }
 
 /* Simple tests on the tangent trigonometric function. */
 }
 
 /* Simple tests on the tangent trigonometric function. */
-static unsigned inifcns_check_tan(void)
+static unsigned inifcns_check_tan()
 {
        unsigned result = 0;
        bool errorflag;
 {
        unsigned result = 0;
        bool errorflag;
@@ -151,7 +155,7 @@ static unsigned inifcns_check_tan(void)
                argument = n*Pi/60;
                if (abs(tan(evalf(argument))-evalf(tan(argument)))>epsilon) {
                        clog << "tan(" << argument << ") returns "
                argument = n*Pi/60;
                if (abs(tan(evalf(argument))-evalf(tan(argument)))>epsilon) {
                        clog << "tan(" << argument << ") returns "
-                                << tan(argument) << endl;
+                            << tan(argument) << endl;
                        errorflag = true;
                }
        }
                        errorflag = true;
                }
        }
@@ -162,7 +166,7 @@ static unsigned inifcns_check_tan(void)
 }
 
 /* Simple tests on the dilogarithm function. */
 }
 
 /* Simple tests on the dilogarithm function. */
-static unsigned inifcns_check_Li2(void)
+static unsigned inifcns_check_Li2()
 {
        // NOTE: this can safely be removed once CLN supports dilogarithms and
        // checks them itself.
 {
        // NOTE: this can safely be removed once CLN supports dilogarithms and
        // checks them itself.
@@ -176,10 +180,10 @@ static unsigned inifcns_check_Li2(void)
        numeric epsilon(double(1e-16));
        for (int n=0; n<200; ++n) {
                argument = numeric(20.0*rand()/(RAND_MAX+1.0)-10.0)
        numeric epsilon(double(1e-16));
        for (int n=0; n<200; ++n) {
                argument = numeric(20.0*rand()/(RAND_MAX+1.0)-10.0)
-                                + numeric(20.0*rand()/(RAND_MAX+1.0)-10.0)*I;
+                        + numeric(20.0*rand()/(RAND_MAX+1.0)-10.0)*I;
                if (abs(Li2(pow(argument,2))-2*Li2(argument)-2*Li2(-argument)) > epsilon) {
                if (abs(Li2(pow(argument,2))-2*Li2(argument)-2*Li2(-argument)) > epsilon) {
-                       cout << "Li2(z) at z==" << argument
-                                << " failed to satisfy Li2(z^2)==2*(Li2(z)+Li2(-z))" << endl;
+                       clog << "Li2(z) at z==" << argument
+                            << " failed to satisfy Li2(z^2)==2*(Li2(z)+Li2(-z))" << endl;
                        errorflag = true;
                }
        }
                        errorflag = true;
                }
        }
@@ -190,24 +194,21 @@ static unsigned inifcns_check_Li2(void)
        return result;
 }
 
        return result;
 }
 
-unsigned check_inifcns(void)
+unsigned check_inifcns()
 {
        unsigned result = 0;
 
        cout << "checking consistency of symbolic functions" << flush;
 {
        unsigned result = 0;
 
        cout << "checking consistency of symbolic functions" << flush;
-       clog << "---------consistency of symbolic functions:" << endl;
        
        result += inifcns_check_sin();  cout << '.' << flush;
        result += inifcns_check_cos();  cout << '.' << flush;
        result += inifcns_check_tan();  cout << '.' << flush;
        result += inifcns_check_Li2();  cout << '.' << flush;
        
        
        result += inifcns_check_sin();  cout << '.' << flush;
        result += inifcns_check_cos();  cout << '.' << flush;
        result += inifcns_check_tan();  cout << '.' << flush;
        result += inifcns_check_Li2();  cout << '.' << flush;
        
-       if (!result) {
-               cout << " passed " << endl;
-               clog << "(no output)" << endl;
-       } else {
-               cout << " failed " << endl;
-       }
-       
        return result;
 }
        return result;
 }
+
+int main(int argc, char** argv)
+{
+       return check_inifcns();
+}