[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/bignum 6d4bf2c 09/24: Add some bignum tests
From: |
Tom Tromey |
Subject: |
[Emacs-diffs] feature/bignum 6d4bf2c 09/24: Add some bignum tests |
Date: |
Fri, 13 Jul 2018 00:25:07 -0400 (EDT) |
branch: feature/bignum
commit 6d4bf2cedab365411f0aedb373b63291086658e9
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>
Add some bignum tests
* test/src/data-tests.el (data-tests-bignum, data-tests-+)
(data-tests-/, data-tests-number-predicates): New tests.
* test/src/fns-tests (test-bignum-eql): New test.
* test/src/lread-tests (lread-long-hex-integer): Expect bignum.
* test/src/print-tests (print-bignum): New test.
---
test/src/data-tests.el | 59 +++++++++++++++++++++++++++++++++++++++++++++++++
test/src/fns-tests.el | 8 +++++++
test/src/lread-tests.el | 4 +---
test/src/print-tests.el | 6 +++++
4 files changed, 74 insertions(+), 3 deletions(-)
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index 3cd5378..543bb90 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -515,4 +515,63 @@ comparing the subr with a much slower lisp implementation."
(bound-and-true-p data-tests-foo2)
(bound-and-true-p data-tests-foo3)))))))
+(ert-deftest data-tests-bignum ()
+ (should (bignump (+ most-positive-fixnum 1)))
+ (let ((f0 (+ (float most-positive-fixnum) 1))
+ (f-1 (- (float most-negative-fixnum) 1))
+ (b0 (+ most-positive-fixnum 1))
+ (b-1 (- most-negative-fixnum 1)))
+ (should (> b0 -1))
+ (should (> b0 f-1))
+ (should (> b0 b-1))
+ (should (>= b0 -1))
+ (should (>= b0 f-1))
+ (should (>= b0 b-1))
+ (should (>= b-1 b-1))
+
+ (should (< -1 b0))
+ (should (< f-1 b0))
+ (should (< b-1 b0))
+ (should (<= -1 b0))
+ (should (<= f-1 b0))
+ (should (<= b-1 b0))
+ (should (<= b-1 b-1))
+
+ (should (= b0 f0))
+ (should (= b0 b0))
+
+ (should (/= b0 f-1))
+ (should (/= b0 b-1))))
+
+(ert-deftest data-tests-+ ()
+ (should-not (fixnump (+ most-positive-fixnum most-positive-fixnum)))
+ (should (> (+ most-positive-fixnum most-positive-fixnum)
most-positive-fixnum))
+ (should (eq (- (+ most-positive-fixnum most-positive-fixnum)
+ (+ most-positive-fixnum most-positive-fixnum))
+ 0)))
+
+(ert-deftest data-tests-/ ()
+ (let* ((x (* most-positive-fixnum 8))
+ (y (* most-negative-fixnum 8))
+ (z (- y)))
+ (should (= most-positive-fixnum (/ x 8)))
+ (should (= most-negative-fixnum (/ y 8)))
+ (should (= -1 (/ y z)))
+ (should (= -1 (/ z y)))
+ (should (= 0 (/ x (* 2 x))))
+ (should (= 0 (/ y (* 2 y))))
+ (should (= 0 (/ z (* 2 z))))))
+
+(ert-deftest data-tests-number-predicates ()
+ (should (fixnump 0))
+ (should (fixnump most-negative-fixnum))
+ (should (fixnump most-positive-fixnum))
+ (should (integerp (+ most-positive-fixnum 1)))
+ (should (integer-or-marker-p (+ most-positive-fixnum 1)))
+ (should (numberp (+ most-positive-fixnum 1)))
+ (should (number-or-marker-p (+ most-positive-fixnum 1)))
+ (should (natnump (+ most-positive-fixnum 1)))
+ (should-not (fixnump (+ most-positive-fixnum 1)))
+ (should (bignump (+ most-positive-fixnum 1))))
+
;;; data-tests.el ends here
diff --git a/test/src/fns-tests.el b/test/src/fns-tests.el
index d9cca55..f5f3b89 100644
--- a/test/src/fns-tests.el
+++ b/test/src/fns-tests.el
@@ -593,4 +593,12 @@
(should (equal 1 (string-distance "ab" "a我b")))
(should (equal 1 (string-distance "我" "她"))))
+(ert-deftest test-bignum-eql ()
+ "Test that `eql' works for bignums."
+ (let ((x (+ most-positive-fixnum 1))
+ (y (+ most-positive-fixnum 1)))
+ (should (eq x x))
+ (should (eql x y))
+ (should (equal x y))))
+
(provide 'fns-tests)
diff --git a/test/src/lread-tests.el b/test/src/lread-tests.el
index 639a6da..1738134 100644
--- a/test/src/lread-tests.el
+++ b/test/src/lread-tests.el
@@ -195,9 +195,7 @@ literals (Bug#20852)."
(should (eq x (cdr x)))))
(ert-deftest lread-long-hex-integer ()
- (should-error
- (read
"#xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff")
- :type 'overflow-error))
+ (should (bignump (read
"#xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"))))
(ert-deftest lread-test-bug-31186 ()
(with-temp-buffer
diff --git a/test/src/print-tests.el b/test/src/print-tests.el
index c96cb5d..091f1aa 100644
--- a/test/src/print-tests.el
+++ b/test/src/print-tests.el
@@ -98,5 +98,11 @@ otherwise, use a different charset."
(let ((sym '\’bar))
(should (eq (read (prin1-to-string sym)) sym))))
+(ert-deftest print-bignum ()
+ (let* ((str "999999999999999999999999999999999")
+ (val (read str)))
+ (should (> val most-positive-fixnum))
+ (should (equal (prin1-to-string val) str))))
+
(provide 'print-tests)
;;; print-tests.el ends here
- [Emacs-diffs] branch feature/bignum created (now cc3d758), Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum eefa65e 07/24: Make comparison operators handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum b2f3f4e 04/24: Provide new functions to create bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 580d173 05/24: Make eql work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a0f2adb 03/24: Introduce the bignum type, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 23eab9a 10/24: Make number-to-string work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 025adce 13/24: Make abs handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 6d4bf2c 09/24: Add some bignum tests,
Tom Tromey <=
- [Emacs-diffs] feature/bignum 872faab 12/24: Allow conversion of bignums to floats, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 5875fba 08/24: Make arithmetic work with bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a770fb4 16/24: Make logcount handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 0d86891 14/24: Make 1+ and 1- handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 8fb995b 17/24: Make min and max handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 3dea8f8 19/24: Make % and mod handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum d14808c 11/24: Make format handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum c7e393b 15/24: Make lognot handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 1e8ae6c 06/24: Make the reader accept bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 27980e3 21/24: Make ash and lsh handle bignums, Tom Tromey, 2018/07/13