Raymond Toy pushed to branch rtoy-bignum-mult-less-consing at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • tests/bignum.lisp
    ... ... @@ -5,9 +5,47 @@
    5 5
     
    
    6 6
     (in-package #:bignum-tests)
    
    7 7
     
    
    8
    -(define-test hd-mult
    
    8
    +(define-test hd-mult.same-size
    
    9 9
       "Test bignum multiplier"
    
    10 10
       (:tag :bignum-tests)
    
    11
    +  ;; x and y are randomly generated 128 integers. No particular reason
    
    12
    +  ;; for these values, except that they're bignums.
    
    13
    +  (let ((x 248090201001762284446997112921270181259)
    
    14
    +	(y 313102667534462314033767199170708979663)
    
    15
    +	(prod 77677703722812705876871716049945873590003455155145426220435549433670954735717))
    
    16
    +    ;; Verify the we get the right results for various signed values of x and y.
    
    17
    +    (assert-equal prod (* x y))
    
    18
    +    (assert-equal (- prod) (* (- x) y))
    
    19
    +    (assert-equal (- prod) (* x (- y)))
    
    20
    +    (assert-equal prod (* (- x) (- y)))
    
    21
    +    ;; Nake sure it's commutative
    
    22
    +    (assert-equal prod (* y x))
    
    23
    +    (assert-equal (- prod) (* y (- x)))
    
    24
    +    (assert-equal (- prod) (* (- y) x))
    
    25
    +    (assert-equal prod (* (- y) (- x)))))
    
    26
    +
    
    27
    +(define-test hd-mult.diff-size
    
    28
    +  "Test bignum multiplier"
    
    29
    +  (:tag :bignum-tests)
    
    30
    +  ;; x is a randomly generated bignum.  y is a small bignum.
    
    31
    +  (let ((x 248090201001762284446997112921270181259)
    
    32
    +	(y (1+ most-positive-fixnum))
    
    33
    +	(prod 133192412470079431258262755675409306410924638208))
    
    34
    +    ;; Verify the we get the right results for various signed values of x and y.
    
    35
    +    (assert-equal prod (* x y))
    
    36
    +    (assert-equal (- prod) (* (- x) y))
    
    37
    +    (assert-equal (- prod) (* x (- y)))
    
    38
    +    (assert-equal prod (* (- x) (- y)))
    
    39
    +    ;; Nake sure it's commutative
    
    40
    +    (assert-equal prod (* y x))
    
    41
    +    (assert-equal (- prod) (* y (- x)))
    
    42
    +    (assert-equal (- prod) (* (- y) x))
    
    43
    +    (assert-equal prod (* (- y) (- x)))))
    
    44
    +
    
    45
    +
    
    46
    +(define-test hd-mult.random
    
    47
    +  "Test bignum multiplier with random values"
    
    48
    +  (:tag :bignum-tests)
    
    11 49
       (let ((rng (kernel::make-random-object :state (kernel:init-random-state)
    
    12 50
     					 :rand 0
    
    13 51
     					 :cached-p nil))