]> www.ginac.de Git - ginac.git/blobdiff - check/exam_factor.cpp
Add proper functions to make clifford_bar() and clifford_star().
[ginac.git] / check / exam_factor.cpp
index ba5c137aa24083f5e7bd9ad2c6379a1681568497..69885d2ce778e6b4dd79ad3eb3356f405d396cb1 100644 (file)
@@ -3,7 +3,7 @@
  *  Factorization test suite. */
 
 /*
- *  GiNaC Copyright (C) 1999-2010 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2016 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
@@ -113,8 +113,7 @@ static unsigned exam_factor2()
        unsigned result = 0;
        ex e;
        symbol x("x"), y("y"), z("z");
-       lst syms;
-       syms = x, y, z;
+       lst syms = {x, y, z};
        
        e = ex("x+y", syms);
        result += check_factor(e);
@@ -172,8 +171,7 @@ static unsigned exam_factor3()
        unsigned result = 0;
        ex e;
        symbol k("k"), n("n");
-       lst syms;
-       syms = k, n;
+       lst syms = {k, n};
        
        e = ex("1/2*(-3+3*k-n)*(-2+3*k-n)*(-1+3*k-n)", syms);
        result += check_factor(e);
@@ -184,6 +182,33 @@ static unsigned exam_factor3()
        return result;
 }
 
+static unsigned check_factorization(const exvector& factors)
+{
+       ex e = dynallocate<mul>(factors);
+       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;
@@ -193,6 +218,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;
 }