Commits

Anonymous committed f4da68e

added type-specs for random generators

Comments (0)

Files changed (3)

data-generators-impl.scm

 
 
 ;;== random primitives
+(: %random-fixnum ((or fixnum float) (or fixnum float) -> fixnum))
 (define (%random-fixnum lo hi)
   (let ((range (- hi lo -1)))
     (inexact->exact (+ (bsd:random-integer range) lo))))
 
 ;; currently this only return flonums
+(: %random-real (float float -> float))
 (define (%random-real #!optional (size 1.0) (start 0.0))
   (let ((ub (+ size start)))
     (%clamp (+ start (* size (bsd:random-real))) start ub)))
 (define-fixed-range-generator gen-uint16 0 65535)
 (define-fixed-range-generator gen-int32 -2147483647 2147483647)
 (define-fixed-range-generator gen-uint32 0 4294967295)
-(define-fixed-range-generator gen-int64 -9223372036854775807 9223372036854775807)
+(define-fixed-range-generator gen-int64  -9223372036854775807 9223372036854775807)
 (define-fixed-range-generator gen-uint64 0 18446744073709551615)
 
 (define gen-real
 
 (define gen-string gen-string-of)
 
-(define (gen-symbol-of)
+(define gen-symbol-of
   (case-lambda
     (()
-     (gen-symbol-of char-set:letter+digit))
+     (gen-symbol-of (gen-char char-set:letter+digit)))
     ((char-gen)
      (gen-transform string->symbol (gen-string-of char-gen)))))
 
    generator <- gen-for-each register-generator-for-type! gen
    gen-constant  gen-int8 gen-uint8 gen-int16 gen-uint16 gen-int32 gen-uint32 gen-int64 gen-uint64 fixnums even-fixnums odd-fixnums flonums
    gen-bool booleans gen-char chars gen-fixnum gen-even-fixnum gen-odd-fixnum gen-real gen-sample gen-sample-of gen-pair-of gen-tuple-of
-   gen-list-of gen-alist-of gen-vector-of gen-string-of gen-symbol-of gen-hash-table-of gen-record gen-values-of gen-transform
+   gen-list-of gen-alist-of gen-vector-of gen-string-of gen-symbol-of gen-symbol gen-hash-table-of gen-record gen-values-of gen-transform
    with-size range size-spec->gen)
   (import chicken scheme)
   (use (prefix random-bsd bsd:)
      (between? (<- (gen-fixnum 2 4)) 2 4))
     (test-assert
      (between? (<- (gen-fixnum (range 2 4))) 2 4))
+    (test-assert
+     (fixnum? (<- (fixnums))))
     (test-error "lower bound <= upper bound"
      (gen-fixnum 4 2)))
 
             (between? (<- (gen-even-fixnum 2 4)) 2 4))
            (test-assert
             (between? (<- (gen-even-fixnum (range 2 4))) 2 4))
+           (test-assert
+            (even? (<- (even-fixnums))))
            (test-error "lower bound <= upper bound"
                        (gen-even-fixnum 4 2)))
 
             (between? (<- (gen-odd-fixnum 2 4)) 2 4))
            (test-assert
             (between? (<- (gen-odd-fixnum (range 2 4))) 2 4))
+           (test-assert
+            (odd? (<- (odd-fixnums))))
            (test-error "lower bound <= upper bound"
                        (gen-odd-fixnum 4 2)))