1. David Krentzlin
  2. data-generators

Commits

certainty  committed 9f5aa22

added flonum generator

  • Participants
  • Parent commits 47bce45
  • Branches default

Comments (0)

Files changed (2)

File data-generators-impl.scm

View file
    ((and (> val lower) (<= val upper)) val)
    (else lower)))
 
+
 ;;== ranges are used to configure some generators
 (: range (forall (start (stop *)) (start stop -> (pair start stop))))
 (define (range start stop)
      (assert-valid-bounds lower upper)
      (generator (%random-real (- upper lower) lower)))))
 
-(define flonums gen-real)
+;; TODO: find better name
+(define (gen-flonum-specialties)
+  (gen-sample (list +nan.0 +inf.0 -inf.0)))
+
+(define gen-flonum
+  (case-lambda
+    (()
+     (gen-sample-of (gen-flonum-specialties) (gen-flonum 0.0 1.0)))
+    ((range)
+     (safe-apply-range gen-flonum range))
+    ((lower upper)
+     (assert-valid-bounds lower upper)
+     (generator (%random-real (- upper lower) lower)))))
+
+(define flonums gen-flonum)
 
 (register-generator-for-type! flonum? gen-real)
 

File data-generators.scm

View file
    gen-current-fixnum-max
    gen-current-default-size
    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-constant  gen-int8 gen-uint8 gen-int16 gen-uint16 gen-int32 gen-uint32 gen-int64 gen-uint64 fixnums even-fixnums odd-fixnums gen-flonum flonums
    gen-bool booleans gen-series gen-char chars gen-fixnum gen-even-fixnum gen-odd-fixnum gen-real gen-rational 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-symbol gen-keyword-of gen-keyword gen-procedure gen-hash-table-of gen-record gen-values-of gen-transform
    with-size range size-spec->gen)