From 506adfe907f13f1bdda6d3c4a3f1e888764d73e9 Mon Sep 17 00:00:00 2001
From: Alexey Sheplyakov <asheplyakov@altlinux.org>
Date: Tue, 23 Jun 2020 11:56:22 +0400
Subject: [PATCH] Added a test case for collect_common_factors

Constructs an expression with a common factor being zero:

c*x + c - c*(x+1)

and checks if collect_common_factors is able to handle it.
---
 check/check_collect_common_factor_zero.cpp | 24 ++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 check/check_collect_common_factor_zero.cpp

diff --git a/check/check_collect_common_factor_zero.cpp b/check/check_collect_common_factor_zero.cpp
new file mode 100644
index 00000000..10f8fa32
--- /dev/null
+++ b/check/check_collect_common_factor_zero.cpp
@@ -0,0 +1,24 @@
+#include <iostream>
+#include "ginac.h"
+using namespace std;
+using namespace GiNaC;
+
+int main(int argc, char** argv) {
+	cout << "checking if find_common_factors handles zero factors " << flush;
+	parser p;
+	// r = 0 = c*0 = c*(x + 1 - 1 - x) = c*(x + 1) - c - c*x
+	//   = c*((x+1)^2 - 1) - (x^2 - 2*x))
+	//   = c*(x+1)^2 - c - c*(x^2 + 2*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()) {
+		cout << " err, no" << endl << flush;
+		cerr << ei << " should have been rewritten as 0, got " << ef << " instead" << endl;
+		return 1;
+	}
+	cout << " OK" << endl;
+	return 0;
+}
-- 
2.17.1

