mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-28 16:00:22 +02:00
(string->number): New tests.
This commit is contained in:
parent
6255e812dc
commit
fd4ba60be8
1 changed files with 26 additions and 0 deletions
|
@ -851,6 +851,32 @@
|
|||
;;; string->number
|
||||
;;;
|
||||
|
||||
|
||||
(with-test-prefix "string->number"
|
||||
|
||||
(pass-if "documented?"
|
||||
(documented? string->number))
|
||||
|
||||
;; Prior to Guile 1.6.7 the bignum size calculation (used for strings >=
|
||||
;; 6 chars) was wrong (for bases other than 2, 10 and 16), resulting in
|
||||
;; numerical overflow errors for certain conversions.
|
||||
;;
|
||||
;; The following exercises string->number of strings like "999999" (each
|
||||
;; digit is base-1) in bases 2 to 16.
|
||||
;;
|
||||
(do ((base 2 (1+ base)))
|
||||
((> base 16))
|
||||
|
||||
(with-test-prefix (list 'base base)
|
||||
|
||||
(do ((digit (string-ref (number->string (1- base) base) 0))
|
||||
(want (1- base) (+ (* want base) base -1))
|
||||
(len 1 (1+ len)))
|
||||
((> len 300))
|
||||
|
||||
(pass-if (list 'length len)
|
||||
(eqv? want (string->number (make-string len digit) base)))))))
|
||||
|
||||
;;;
|
||||
;;; number?
|
||||
;;;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue