]> www.ginac.de Git - ginac.git/blobdiff - check/exam_factor.cpp
Update copyright statements.
[ginac.git] / check / exam_factor.cpp
index 71a63f24ba68dce756efd210005b93d5b2b6a4c1..01e5af1ee323e6d436da63d3f2ea8b976ea3707a 100644 (file)
@@ -3,7 +3,7 @@
  *  Factorization test suite. */
 
 /*
- *  GiNaC Copyright (C) 1999-2008 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2014 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
  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#include <iostream>
 #include "ginac.h"
-using namespace std;
 using namespace GiNaC;
 
+#include <iostream>
+using namespace std;
+
 static symbol w("w"), x("x"), y("y"), z("z");
 
 static unsigned check_factor(const ex& e)
@@ -183,6 +184,33 @@ static unsigned exam_factor3()
        return result;
 }
 
+static unsigned check_factorization(const exvector& factors)
+{
+       ex e = (new mul(factors))->setflag(status_flags::dynallocated);
+       ex ef = factor(e.expand());
+       if (ef.nops() != factors.size()) {
+               clog << "wrong number of factors, expected " << factors.size() <<
+                       ", got " << ef.nops();
+               return 1;
+       }
+       for (size_t i = 0; i < ef.nops(); ++i) {
+               if (find(factors.begin(), factors.end(), ef.op(i)) == factors.end()) {
+                       clog << "wrong factorization: term not found: " << ef.op(i);
+                       return 1;
+               }
+       }
+       return 0;
+}
+
+static unsigned factor_integer_content_bug()
+{
+       parser reader;
+       exvector factors;
+       factors.push_back(reader("x+y+x*y"));
+       factors.push_back(reader("3*x+2*y"));
+       return check_factorization(factors);
+}
+
 unsigned exam_factor()
 {
        unsigned result = 0;
@@ -192,6 +220,8 @@ unsigned exam_factor()
        result += exam_factor1(); cout << '.' << flush;
        result += exam_factor2(); cout << '.' << flush;
        result += exam_factor3(); cout << '.' << flush;
+       result += factor_integer_content_bug();
+       cout << '.' << flush;
 
        return result;
 }