]> www.ginac.de Git - ginac.git/blob - check/exam_collect_common_factors.cpp
Set version, soname ahead of release.
[ginac.git] / check / exam_collect_common_factors.cpp
1 #include <iostream>
2 #include "ginac.h"
3 using namespace std;
4 using namespace GiNaC;
5
6 static unsigned exam_collect_common_factors_simple()
7 {
8         unsigned result = 0;
9         symbol a("a"), b("b"), c("c"), x("x"), y("y");
10         ex ei, ef, ref;
11
12         ei = a*x + a*y;
13         ef = collect_common_factors(ei);
14         ref = (x+y)*a;
15         if (ef != ref) {
16                 clog << "ERROR: collect_common_factors(" << ei << ") returned "
17                      << ef << ", not " << ref << '.' << endl;
18                 ++result;
19         }
20
21         ei = a*x*x + 2*a*x*y + a*y*y;
22         ef = collect_common_factors(ei);
23         ref = a*(x*x + 2*x*y + y*y);
24         if (ef != ref) {
25                 clog << "ERROR: collect_common_factors(" << ei << ") returned "
26                      << ef << ", not " << ref << '.' << endl;
27                 ++result;
28         }
29
30         return result;
31 }
32
33 static unsigned exam_collect_common_factors_zero()
34 {
35         // r = 0 = c*0 = c*(x + 1 - 1 - x) = c*(x + 1) - c - c*x
36         // e = a*r - b*r
37         symbol a("a"), b("b"), c("c"), x("x");
38
39         ex r = c*(x+1) - c - c*x;
40         ex ei = a*r + b*r;
41         ex ef = collect_common_factors(ei);
42         if (!ef.is_zero()) {
43                 clog << "ERROR: " << ei << " should be 0, got " << ef << " instead." << endl;
44                 return 1;
45         }
46         return 0;
47 }
48
49 int main(int argc, char** argv)
50 {
51         int result = 0;
52
53         cout << "examining collect_common_factors" << flush;
54
55         result += exam_collect_common_factors_simple();  cout << '.' << flush;
56         result += exam_collect_common_factors_zero();  cout << '.' << flush;
57
58         return result;
59 }