summaryrefslogtreecommitdiff
path: root/test/lisp/calc/calc-tests.el
diff options
context:
space:
mode:
authorMattias EngdegÄrd <mattiase@acm.org>2020-10-10 11:29:43 +0200
committerMattias EngdegÄrd <mattiase@acm.org>2020-10-10 11:29:43 +0200
commit1006eb119849e4f81aa9a0b1c214a72bc2fbf8e3 (patch)
treea5a5245c7ef579ad703378f005002013b50544dd /test/lisp/calc/calc-tests.el
parent5824c209ba17b97978519ea62478c57010311e88 (diff)
downloademacs-1006eb119849e4f81aa9a0b1c214a72bc2fbf8e3.tar.gz
emacs-1006eb119849e4f81aa9a0b1c214a72bc2fbf8e3.tar.bz2
emacs-1006eb119849e4f81aa9a0b1c214a72bc2fbf8e3.zip
Improve coverage of Calc bit shift test
* test/lisp/calc/calc-tests.el (calc-tests--rsh, calc-tests--rash) (calc-shift-binary): Test with negative word sizes.
Diffstat (limited to 'test/lisp/calc/calc-tests.el')
-rw-r--r--test/lisp/calc/calc-tests.el15
1 files changed, 10 insertions, 5 deletions
diff --git a/test/lisp/calc/calc-tests.el b/test/lisp/calc/calc-tests.el
index 4bced28a64f..fe37c424d5e 100644
--- a/test/lisp/calc/calc-tests.el
+++ b/test/lisp/calc/calc-tests.el
@@ -594,7 +594,10 @@ An existing calc stack is reused, otherwise a new one is created."
"Logical shift right X by N steps, word size W."
(if (< n 0)
(calc-tests--lsh x (- n) w)
- (ash (calc-tests--clip x w) (- n))))
+ ;; First zero-extend, then shift.
+ (calc-tests--clip
+ (ash (calc-tests--clip x (abs w)) (- n))
+ w)))
(defun calc-tests--ash (x n w)
"Arithmetic shift left X by N steps, word size W."
@@ -607,8 +610,9 @@ An existing calc stack is reused, otherwise a new one is created."
(if (< n 0)
(calc-tests--ash x (- n) w)
;; First sign-extend, then shift.
- (let ((x-sext (calc-tests--clip x (- (abs w)))))
- (calc-tests--clip (ash x-sext (- n)) w))))
+ (calc-tests--clip
+ (ash (calc-tests--clip x (- (abs w))) (- n))
+ w)))
(defun calc-tests--rot (x n w)
"Rotate X left by N steps, word size W."
@@ -619,11 +623,12 @@ An existing calc stack is reused, otherwise a new one is created."
w)))
(ert-deftest calc-shift-binary ()
- (dolist (w '(16 32))
+ (dolist (w '(16 32 -16 -32))
(dolist (x '(0 1 #x1234 #x8000 #xabcd #xffff
#x12345678 #xabcdef12 #x80000000 #xffffffff
#x1234567890ab #x1234967890ab
- -1 -14))
+ -1 -14 #x-8000 #x-ffff #x-8001 #x-10000
+ #x-80000000 #x-ffffffff #x-80000001 #x-100000000))
(dolist (n '(0 1 4 16 32 -1 -4 -16 -32))
(should (equal (calcFunc-lsh x n w)
(calc-tests--lsh x n w)))