From: Richard Kreckel Date: Sun, 28 Jun 2020 15:21:33 +0000 (+0200) Subject: Add exam for exam_common_factors. X-Git-Tag: release_1-7-10~1 X-Git-Url: https://www.ginac.de/ginac.git//ginac.git?p=ginac.git;a=commitdiff_plain;h=1193f765c62171a4267ef0138ecc22c875a7daf4 Add exam for exam_common_factors. Including a case involving a hidden zero to catch errors like the one fixed in 5f7f81ad35a, as suggested by Alexey Sheplyakov . --- diff --git a/check/CMakeLists.txt b/check/CMakeLists.txt index c229a818..9d9e0839 100644 --- a/check/CMakeLists.txt +++ b/check/CMakeLists.txt @@ -19,6 +19,7 @@ set(ginac_tests exam_inifcns_nstdsums exam_differentiation exam_polygcd + exam_collect_common_factors exam_normalization exam_factor exam_pseries diff --git a/check/Makefile.am b/check/Makefile.am index e8adab07..8d00fdb1 100644 --- a/check/Makefile.am +++ b/check/Makefile.am @@ -16,6 +16,7 @@ EXAMS = exam_paranoia \ exam_inifcns_nstdsums \ exam_differentiation \ exam_polygcd \ + exam_collect_common_factors \ exam_normalization \ exam_factor \ exam_pseries \ @@ -114,6 +115,9 @@ exam_differentiation_LDADD = ../ginac/libginac.la exam_polygcd_SOURCES = exam_polygcd.cpp exam_polygcd_LDADD = ../ginac/libginac.la +exam_collect_common_factors_SOURCES = exam_collect_common_factors.cpp +exam_collect_common_factors_LDADD = ../ginac/libginac.la + exam_normalization_SOURCES = exam_normalization.cpp exam_normalization_LDADD = ../ginac/libginac.la diff --git a/check/exam_collect_common_factors.cpp b/check/exam_collect_common_factors.cpp new file mode 100644 index 00000000..520e0d84 --- /dev/null +++ b/check/exam_collect_common_factors.cpp @@ -0,0 +1,59 @@ +#include +#include "ginac.h" +using namespace std; +using namespace GiNaC; + +static unsigned exam_collect_common_factors_simple() +{ + unsigned result = 0; + symbol a("a"), b("b"), c("c"), x("x"), y("y"); + ex ei, ef, ref; + + ei = a*x + a*y; + ef = collect_common_factors(ei); + ref = (x+y)*a; + if (ef != ref) { + clog << "ERROR: collect_common_factors(" << ei << ") returned " + << ef << ", not " << ref << '.' << endl; + ++result; + } + + ei = a*x*x + 2*a*x*y + a*y*y; + ef = collect_common_factors(ei); + ref = a*(x*x + 2*x*y + y*y); + if (ef != ref) { + clog << "ERROR: collect_common_factors(" << ei << ") returned " + << ef << ", not " << ref << '.' << endl; + ++result; + } + + return result; +} + +static unsigned exam_collect_common_factors_zero() +{ + // r = 0 = c*0 = c*(x + 1 - 1 - x) = c*(x + 1) - c - c*x + // e = a*r - b*r + symbol a("a"), b("b"), c("c"), x("x"); + + ex r = c*(x+1) - c - c*x; + ex ei = a*r + b*r; + ex ef = collect_common_factors(ei); + if (!ef.is_zero()) { + clog << "ERROR: " << ei << " should be 0, got " << ef << " instead." << endl; + return 1; + } + return 0; +} + +int main(int argc, char** argv) +{ + int result = 0; + + cout << "examining collect_common_factors" << flush; + + result += exam_collect_common_factors_simple(); cout << '.' << flush; + result += exam_collect_common_factors_zero(); cout << '.' << flush; + + return result; +}