diff options
author | Mattias EngdegÄrd <mattiase@acm.org> | 2020-05-15 14:52:50 +0200 |
---|---|---|
committer | Mattias EngdegÄrd <mattiase@acm.org> | 2020-05-15 20:15:36 +0200 |
commit | 60cd6cce55744e8d3ae844e0602c9dd268dc4bc3 (patch) | |
tree | 168fe989cb322c487b017f4f4ed293be6a40cb5c /test/lisp/calc/calc-tests.el | |
parent | b76cdd0c1a7978decc0c1044ad23ecc9432c526a (diff) | |
download | emacs-60cd6cce55744e8d3ae844e0602c9dd268dc4bc3.tar.gz emacs-60cd6cce55744e8d3ae844e0602c9dd268dc4bc3.tar.bz2 emacs-60cd6cce55744e8d3ae844e0602c9dd268dc4bc3.zip |
Calc: GCD(0,x)=GCD(x,0)=|x|, not x (bug#41279)
Reported by David Ongaro.
* lisp/calc/calc-comb.el (calcFunc-gcd): Fix GCD simplification.
* test/lisp/calc/calc-tests.el (calc-gcd, calc-sum-gcd): New tests.
Diffstat (limited to 'test/lisp/calc/calc-tests.el')
-rw-r--r-- | test/lisp/calc/calc-tests.el | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el index 9e36d91ac3e..c8cb97a8bca 100644 --- a/test/lisp/calc/calc-tests.el +++ b/test/lisp/calc/calc-tests.el @@ -368,6 +368,34 @@ An existing calc stack is reused, otherwise a new one is created." (vec 0 0 (var a var-a) 0))) '(neg (var a var-a))))) +(ert-deftest calc-gcd () + (should (equal (calcFunc-gcd 3 4) 1)) + (should (equal (calcFunc-gcd 12 15) 3)) + (should (equal (calcFunc-gcd -12 15) 3)) + (should (equal (calcFunc-gcd 12 -15) 3)) + (should (equal (calcFunc-gcd -12 -15) 3)) + (should (equal (calcFunc-gcd 0 5) 5)) + (should (equal (calcFunc-gcd 5 0) 5)) + (should (equal (calcFunc-gcd 0 -5) 5)) + (should (equal (calcFunc-gcd -5 0) 5)) + (should (equal (calcFunc-gcd 0 0) 0)) + (should (equal (calcFunc-gcd 0 '(var x var-x)) + '(calcFunc-abs (var x var-x)))) + (should (equal (calcFunc-gcd '(var x var-x) 0) + '(calcFunc-abs (var x var-x))))) + +(ert-deftest calc-sum-gcd () + ;; sum(gcd(0,n),n,-1,-1) + (should (equal (math-simplify '(calcFunc-sum (calcFunc-gcd 0 (var n var-n)) + (var n var-n) -1 -1)) + 1)) + ;; sum(sum(gcd(n,k),k,-1,1),n,-1,1) + (should (equal (math-simplify + '(calcFunc-sum + (calcFunc-sum (calcFunc-gcd (var n var-n) (var k var-k)) + (var k var-k) -1 1) + (var n var-n) -1 1)) + 8))) (provide 'calc-tests) ;;; calc-tests.el ends here |