From d088b16157d2712e42c02deb0bffa506e5ef3041 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 | 21 +++++++++++++++++++++
 1 file changed, 21 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..84fd7306
--- /dev/null
+++ b/check/check_collect_common_factor_zero.cpp
@@ -0,0 +1,21 @@
+#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;
+	// 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()) {
+		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

