Commits

Anonymous committed 8ac4a96

added aliases that read nicer like (gen-list-of (chars))

  • Participants
  • Parent commits 71970ce
  • Branches 3.0.0

Comments (0)

Files changed (3)

File data-generators-impl.scm

      (assert-valid-bounds lower upper)
      (generator (%random-fixnum lower upper)))))
 
+(define fixnums gen-fixnum)
+
 (register-generator-for-type! fixnum? gen-fixnum)
 
 (define gen-odd-fixnum
         (let ((val (%random-fixnum lower upper)))
           (if (odd? val) val (+ 1 val))))))))
 
+(define odd-fixnums gen-odd-fixnum)
+
 (define gen-even-fixnum
   (case-lambda
     (()
         (let ((val (%random-fixnum lower upper)))
           (if (even? val) val (+ 1 val))))))))
 
+(define even-fixnums gen-even-fixnum)
+
 (define-syntax define-fixed-range-generator
   (syntax-rules ()
     ((_ ?name ?lower ?upper)
      (assert-valid-bounds lower upper)
      (generator (%random-real (- upper lower) lower)))))
 
+(define flonums gen-real)
+
 (register-generator-for-type! flonum? gen-real)
 
 (define (gen-bool)
   (generator (zero? (bsd:random-fixnum 2))))
 
+(define booleans gen-bool)
+
 (define char-set->vector (o list->vector char-set->list))
 
 (define (boundaries->char-vector lower upper)
          (error "lower bound must be <= upper bound" lower upper))
        (%char-gen (boundaries->char-vector lower upper))))))
 
+(define chars gen-char)
+
 (register-generator-for-type! char? gen-char)
 
 (define (gen-sample candidates)
        (generator
         (list->string (<- (<- size-gen) gen)))))))
 
+(define gen-string gen-string-of)
+
+(define (gen-symbol-of)
+  (case-lambda
+    (()
+     (gen-symbol-of char-set:letter+digit))
+    ((char-gen)
+     (gen-transform string->symbol (gen-string-of char-gen)))))
+
+(define gen-symbol gen-symbol-of)
 
 (define gen-vector-of
   (case-lambda
 
 (define gen-hash-table-of
   (case-lambda
-    ((key-gen value-gen) (gen-hash-table-of key-gen value-gen (gen-current-default-size)))
+    ((key-gen value-gen)
+     (gen-hash-table-of key-gen value-gen (gen-current-default-size) eq?))
     ((key-gen value-gen size-spec)
+     (gen-hash-table-of key-gen value-gen size-spec eq?))
+    ((key-gen value-gen size-spec equal?)
      (let ((size-gen (size-spec->gen size-spec)))
        (generator
 	(let ((size (<- size-gen)))
 	  (do ((i 0 (add1 i))
-	       (ht (make-hash-table)))
+	       (ht (make-hash-table equal?)))
 	      ((>= i size) ht)
 	    (hash-table-set! ht (<- key-gen) (<- value-gen)))))))))
 

File data-generators.scm

    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
-   gen-bool gen-char 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-hash-table-of gen-record gen-values-of gen-transform
+   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
    with-size range size-spec->gen)
   (import chicken scheme)
   (use (prefix random-bsd bsd:)

File tests/run.scm

                          (<- (gen-string-of (gen-char char-set:graphic))))))
     (test-size-spec-support string-length (gen-string-of (gen-char))))
 
+(test-group "gen-symbol"
+            (test-assert "produces a symbol"
+                         (symbol? (<- (gen-symbol-of)))))
+
 (test-group "gen-hash-table-of"
     (test-assert "produces a hash-table"
                  (hash-table? (<- (gen-hash-table-of (gen-fixnum) (gen-fixnum)))))