Mercurial > hg > xemacs-beta
comparison tests/automated/lisp-tests.el @ 1983:9c872f33ecbe
[xemacs-hg @ 2004-04-05 22:49:31 by james]
Add bignum, ratio, and bigfloat support.
author | james |
---|---|
date | Mon, 05 Apr 2004 22:50:11 +0000 |
parents | 74cb069b8417 |
children | ab71063baf27 |
comparison
equal
deleted
inserted
replaced
1982:a748951fd4fb | 1983:9c872f33ecbe |
---|---|
227 (Assert (= (+ 1.0 3.0 0.0) 4.0)) | 227 (Assert (= (+ 1.0 3.0 0.0) 4.0)) |
228 (Assert (= (+ 1 1.0) 2.0)) | 228 (Assert (= (+ 1 1.0) 2.0)) |
229 (Assert (= (+ 1.0 1) 2.0)) | 229 (Assert (= (+ 1.0 1) 2.0)) |
230 (Assert (= (+ 1.0 1 1) 3.0)) | 230 (Assert (= (+ 1.0 1 1) 3.0)) |
231 (Assert (= (+ 1 1 1.0) 3.0)) | 231 (Assert (= (+ 1 1 1.0) 3.0)) |
232 (Assert (eq (1+ most-positive-fixnum) most-negative-fixnum)) | 232 (if (featurep 'bignum) |
233 (Assert (eq (+ most-positive-fixnum 1) most-negative-fixnum)) | 233 (progn |
234 (Assert (bignump (1+ most-positive-fixnum))) | |
235 (Assert (eq most-positive-fixnum (1- (1+ most-positive-fixnum)))) | |
236 (Assert (bignump (+ most-positive-fixnum 1))) | |
237 (Assert (eq most-positive-fixnum (- (+ most-positive-fixnum 1) 1))) | |
238 (Assert (= (1+ most-positive-fixnum) (- most-negative-fixnum))) | |
239 (Assert (zerop (+ (* 3 most-negative-fixnum) (* 3 most-positive-fixnum) | |
240 3)))) | |
241 (Assert (eq (1+ most-positive-fixnum) most-negative-fixnum)) | |
242 (Assert (eq (+ most-positive-fixnum 1) most-negative-fixnum))) | |
243 | |
244 (when (featurep 'ratio) | |
245 (let ((threefourths (read "3/4")) | |
246 (threehalfs (read "3/2")) | |
247 (bigpos (div (+ most-positive-fixnum 2) (1+ most-positive-fixnum))) | |
248 (bigneg (div (+ most-positive-fixnum 2) most-negative-fixnum)) | |
249 (negone (div (1+ most-positive-fixnum) most-negative-fixnum))) | |
250 (Assert (= negone -1)) | |
251 (Assert (= threehalfs (+ threefourths threefourths))) | |
252 (Assert (zerop (+ bigpos bigneg))))) | |
234 | 253 |
235 ;; Test `-' | 254 ;; Test `-' |
236 (Check-Error wrong-number-of-arguments (-)) | 255 (Check-Error wrong-number-of-arguments (-)) |
237 (Assert (eq (- 0) 0)) | 256 (Assert (eq (- 0) 0)) |
238 (Assert (eq (- 1) -1)) | 257 (Assert (eq (- 1) -1)) |
255 (Assert (= (- zero one one) -2)))) | 274 (Assert (= (- zero one one) -2)))) |
256 | 275 |
257 (Assert (= (- 1.5 1) .5)) | 276 (Assert (= (- 1.5 1) .5)) |
258 (Assert (= (- 1 1.5) (- .5))) | 277 (Assert (= (- 1 1.5) (- .5))) |
259 | 278 |
260 (Assert (eq (1- most-negative-fixnum) most-positive-fixnum)) | 279 (if (featurep 'bignum) |
261 (Assert (eq (- most-negative-fixnum 1) most-positive-fixnum)) | 280 (progn |
281 (Assert (bignump (1- most-negative-fixnum))) | |
282 (Assert (eq most-negative-fixnum (1+ (1- most-negative-fixnum)))) | |
283 (Assert (bignump (- most-negative-fixnum 1))) | |
284 (Assert (eq most-negative-fixnum (+ (- most-negative-fixnum 1) 1))) | |
285 (Assert (= (1- most-negative-fixnum) (- 0 most-positive-fixnum 2))) | |
286 (Assert (eq (- (- most-positive-fixnum most-negative-fixnum) | |
287 (* 2 most-positive-fixnum)) | |
288 1))) | |
289 (Assert (eq (1- most-negative-fixnum) most-positive-fixnum)) | |
290 (Assert (eq (- most-negative-fixnum 1) most-positive-fixnum))) | |
291 | |
292 (when (featurep 'ratio) | |
293 (let ((threefourths (read "3/4")) | |
294 (threehalfs (read "3/2")) | |
295 (bigpos (div (+ most-positive-fixnum 2) (1+ most-positive-fixnum))) | |
296 (bigneg (div most-positive-fixnum most-negative-fixnum)) | |
297 (negone (div (1+ most-positive-fixnum) most-negative-fixnum))) | |
298 (Assert (= (- negone) 1)) | |
299 (Assert (= threefourths (- threehalfs threefourths))) | |
300 (Assert (= (- bigpos bigneg) 2)))) | |
262 | 301 |
263 ;; Test `/' | 302 ;; Test `/' |
264 | 303 |
265 ;; Test division by zero errors | 304 ;; Test division by zero errors |
266 (dolist (zero '(0 0.0 ?\0)) | 305 (dolist (zero '(0 0.0 ?\0)) |
284 (dolist (three '(3 3.0 ?\03)) | 323 (dolist (three '(3 3.0 ?\03)) |
285 (Assert (= (/ three 2.0) 1.5))) | 324 (Assert (= (/ three 2.0) 1.5))) |
286 (dolist (two '(2 2.0 ?\02)) | 325 (dolist (two '(2 2.0 ?\02)) |
287 (Assert (= (/ 3.0 two) 1.5))) | 326 (Assert (= (/ 3.0 two) 1.5))) |
288 | 327 |
328 (when (featurep 'bignum) | |
329 (let* ((million 1000000) | |
330 (billion (* million 1000)) ;; American, not British, billion | |
331 (trillion (* billion 1000))) | |
332 (Assert (= (/ billion 1000) (/ trillion million) million 1000000.0)) | |
333 (Assert (= (/ billion -1000) (/ trillion (- million)) (- million))) | |
334 (Assert (= (/ trillion 1000) billion 1000000000.0)) | |
335 (Assert (= (/ trillion -1000) (- billion) -1000000000.0)) | |
336 (Assert (= (/ trillion 10) (* 100 billion) 100000000000.0)) | |
337 (Assert (= (/ (- trillion) 10) (* -100 billion) -100000000000.0)))) | |
338 | |
339 (when (featurep 'ratio) | |
340 (let ((half (div 1 2)) | |
341 (fivefourths (div 5 4)) | |
342 (fivehalfs (div 5 2))) | |
343 (Assert (= half (read "3000000000/6000000000"))) | |
344 (Assert (= (/ fivehalfs fivefourths) 2)) | |
345 (Assert (= (/ fivefourths fivehalfs) half)) | |
346 (Assert (= (- half) (read "-3000000000/6000000000"))) | |
347 (Assert (= (/ fivehalfs (- fivefourths)) -2)) | |
348 (Assert (= (/ (- fivefourths) fivehalfs) (- half))))) | |
349 | |
289 ;; Test `*' | 350 ;; Test `*' |
290 (Assert (= 1 (*))) | 351 (Assert (= 1 (*))) |
291 | 352 |
292 (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) | 353 (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) |
293 (Assert (= 1 (* one)))) | 354 (Assert (= 1 (* one)))) |
303 (dolist (three '(3 3.0 ?\03)) | 364 (dolist (three '(3 3.0 ?\03)) |
304 (dolist (two '(2 2.0 ?\02)) | 365 (dolist (two '(2 2.0 ?\02)) |
305 (Assert (= (* 1.5 two) three)) | 366 (Assert (= (* 1.5 two) three)) |
306 (dolist (five '(5 5.0 ?\05)) | 367 (dolist (five '(5 5.0 ?\05)) |
307 (Assert (= 30 (* five two three)))))) | 368 (Assert (= 30 (* five two three)))))) |
369 | |
370 (when (featurep 'bignum) | |
371 (let ((64K 65536)) | |
372 (Assert (= (* 64K 64K) (read "4294967296"))) | |
373 (Assert (= (* (- 64K) 64K) (read "-4294967296"))) | |
374 (Assert (/= (* -1 most-negative-fixnum) most-negative-fixnum)))) | |
375 | |
376 (when (featurep 'ratio) | |
377 (let ((half (div 1 2)) | |
378 (fivefourths (div 5 4)) | |
379 (twofifths (div 2 5))) | |
380 (Assert (= (* fivefourths twofifths) half)) | |
381 (Assert (= (* half twofifths) (read "3/15"))))) | |
308 | 382 |
309 ;; Test `+' | 383 ;; Test `+' |
310 (Assert (= 0 (+))) | 384 (Assert (= 0 (+))) |
311 | 385 |
312 (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) | 386 (dolist (one `(1 1.0 ?\01 ,(Int-to-Marker 1))) |
334 (Assert (= one (min one two two))) | 408 (Assert (= one (min one two two))) |
335 (Assert (= one (min two two one))) | 409 (Assert (= one (min two two one))) |
336 (Assert (= two (max one two))) | 410 (Assert (= two (max one two))) |
337 (Assert (= two (max one two two))) | 411 (Assert (= two (max one two two))) |
338 (Assert (= two (max two two one))))) | 412 (Assert (= two (max two two one))))) |
413 | |
414 (when (featurep 'bignum) | |
415 (let ((big (1+ most-positive-fixnum)) | |
416 (small (1- most-negative-fixnum))) | |
417 (Assert (= big (max 1 1000000.0 most-positive-fixnum big))) | |
418 (Assert (= small (min -1 -1000000.0 most-negative-fixnum small))))) | |
419 | |
420 (when (featurep 'ratio) | |
421 (let* ((big (1+ most-positive-fixnum)) | |
422 (small (1- most-negative-fixnum)) | |
423 (bigr (div (* 5 (1+ most-positive-fixnum)) 4)) | |
424 (smallr (- bigr))) | |
425 (Assert (= bigr (max 1 1000000.0 most-positive-fixnum big bigr))) | |
426 (Assert (= smallr (min -1 -1000000.0 most-negative-fixnum small smallr))))) | |
339 | 427 |
340 ;; The byte compiler has special handling for these constructs: | 428 ;; The byte compiler has special handling for these constructs: |
341 (let ((three 3) (five 5)) | 429 (let ((three 3) (five 5)) |
342 (Assert (= (+ three five 1) 9)) | 430 (Assert (= (+ three five 1) 9)) |
343 (Assert (= (+ 1 three five) 9)) | 431 (Assert (= (+ 1 three five) 9)) |
474 | 562 |
475 (division-test 7) | 563 (division-test 7) |
476 (division-test ?\07) | 564 (division-test ?\07) |
477 (division-test (Int-to-Marker 7))) | 565 (division-test (Int-to-Marker 7))) |
478 | 566 |
479 | 567 (when (featurep 'bignum) |
568 (let ((big (+ (* 7 most-positive-fixnum 6))) | |
569 (negbig (- (* 7 most-negative-fixnum 6)))) | |
570 (= (% big (1+ most-positive-fixnum)) most-positive-fixnum) | |
571 (= (% negbig (1- most-negative-fixnum)) most-negative-fixnum) | |
572 (= (mod big (1+ most-positive-fixnum)) most-positive-fixnum) | |
573 (= (mod negbig (1- most-negative-fixnum)) most-negative-fixnum))) | |
480 | 574 |
481 ;;----------------------------------------------------- | 575 ;;----------------------------------------------------- |
482 ;; Arithmetic comparison operations | 576 ;; Arithmetic comparison operations |
483 ;;----------------------------------------------------- | 577 ;;----------------------------------------------------- |
484 (Check-Error wrong-number-of-arguments (=)) | 578 (Check-Error wrong-number-of-arguments (=)) |
564 (Assert (<= 1 1)) | 658 (Assert (<= 1 1)) |
565 | 659 |
566 (Assert (not (eq (point) (point-marker)))) | 660 (Assert (not (eq (point) (point-marker)))) |
567 (Assert (= 1 (Int-to-Marker 1))) | 661 (Assert (= 1 (Int-to-Marker 1))) |
568 (Assert (= (point) (point-marker))) | 662 (Assert (= (point) (point-marker))) |
663 | |
664 (when (featurep 'bignum) | |
665 (let ((big1 (1+ most-positive-fixnum)) | |
666 (big2 (* 10 most-positive-fixnum)) | |
667 (small1 (1- most-negative-fixnum)) | |
668 (small2 (* 10 most-negative-fixnum))) | |
669 (Assert (< small2 small1 most-negative-fixnum most-positive-fixnum big1 | |
670 big2)) | |
671 (Assert (<= small2 small1 most-negative-fixnum most-positive-fixnum big1 | |
672 big2)) | |
673 (Assert (> big2 big1 most-positive-fixnum most-negative-fixnum small1 | |
674 small2)) | |
675 (Assert (>= big2 big1 most-positive-fixnum most-negative-fixnum small1 | |
676 small2)) | |
677 (Assert (/= small2 small1 most-negative-fixnum most-positive-fixnum big1 | |
678 big2)))) | |
679 | |
680 (when (featurep 'ratio) | |
681 (let ((big1 (div (* 10 most-positive-fixnum) 4)) | |
682 (big2 (div (* 5 most-positive-fixnum) 2)) | |
683 (big3 (div (* 7 most-positive-fixnum) 2)) | |
684 (small1 (div (* 10 most-negative-fixnum) 4)) | |
685 (small2 (div (* 5 most-negative-fixnum) 2)) | |
686 (small3 (div (* 7 most-negative-fixnum) 2))) | |
687 (Assert (= big1 big2)) | |
688 (Assert (= small1 small2)) | |
689 (Assert (< small3 small1 most-negative-fixnum most-positive-fixnum big1 | |
690 big3)) | |
691 (Assert (<= small3 small2 small1 most-negative-fixnum most-positive-fixnum | |
692 big1 big2 big3)) | |
693 (Assert (> big3 big1 most-positive-fixnum most-negative-fixnum small1 | |
694 small3)) | |
695 (Assert (>= big3 big2 big1 most-positive-fixnum most-negative-fixnum | |
696 small1 small2 small3)) | |
697 (Assert (/= big3 big1 most-positive-fixnum most-negative-fixnum small1 | |
698 small3)))) | |
569 | 699 |
570 ;;----------------------------------------------------- | 700 ;;----------------------------------------------------- |
571 ;; testing list-walker functions | 701 ;; testing list-walker functions |
572 ;;----------------------------------------------------- | 702 ;;----------------------------------------------------- |
573 (macrolet | 703 (macrolet |
1133 (Assert (= (read (format "%d" most-negative-fixnum)) most-negative-fixnum)) | 1263 (Assert (= (read (format "%d" most-negative-fixnum)) most-negative-fixnum)) |
1134 (Assert (= (read (format "%ld" most-negative-fixnum)) most-negative-fixnum)) | 1264 (Assert (= (read (format "%ld" most-negative-fixnum)) most-negative-fixnum)) |
1135 | 1265 |
1136 ;;; "%u" is undocumented, and Emacs Lisp has no unsigned type. | 1266 ;;; "%u" is undocumented, and Emacs Lisp has no unsigned type. |
1137 ;;; What to do if "%u" is used with a negative number? | 1267 ;;; What to do if "%u" is used with a negative number? |
1138 ;;; The most reasonable thing seems to be to print an un-read-able number. | 1268 ;;; For non-bignum XEmacsen, the most reasonable thing seems to be to print an |
1139 ;;; The printed value might be useful to a human, if not to Emacs Lisp. | 1269 ;;; un-read-able number. The printed value might be useful to a human, if not |
1140 (Check-Error invalid-read-syntax (read (format "%u" most-negative-fixnum))) | 1270 ;;; to Emacs Lisp. |
1141 (Check-Error invalid-read-syntax (read (format "%u" -1))) | 1271 ;;; For bignum XEmacsen, we make %u with a negative value throw an error. |
1272 (if (featurep 'bignum) | |
1273 (progn | |
1274 (Check-Error wrong-type-argument (format "%u" most-negative-fixnum)) | |
1275 (Check-Error wrong-type-argument (format "%u" -1))) | |
1276 (Check-Error invalid-read-syntax (read (format "%u" most-negative-fixnum))) | |
1277 (Check-Error invalid-read-syntax (read (format "%u" -1)))) | |
1142 | 1278 |
1143 ;; Check all-completions ignore element start with space. | 1279 ;; Check all-completions ignore element start with space. |
1144 (Assert (not (all-completions "" '((" hidden" . "object"))))) | 1280 (Assert (not (all-completions "" '((" hidden" . "object"))))) |
1145 (Assert (all-completions " " '((" hidden" . "object")))) | 1281 (Assert (all-completions " " '((" hidden" . "object")))) |