Anonymous avatar Anonymous committed ec76591

more tests

Comments (0)

Files changed (4)

data-generators-impl.scm

 ;; combinators
 (define gen-current-default-size (make-parameter (gen-uint8)))
 
+(define-syntax with-size
+  (syntax-rules ()
+    ((_ size body0 ...)
+     (parameterize ((gen-current-default-size size))
+       body0 ...))))
+
 (define (gen-sample-of list-of-gen)
   (let* ((l   (length list-of-gen))
          (gen (list-ref list-of-gen  (between gen-fixnum 0 (sub1 l)))))
 
 (define gen-string-of
   (case-lambda
-    (()    (gen-string-of (gen-current-default-size) gen-char))
-    ((gen) (gen-string-of (gen-current-default-size) gen))
-    ((size gen)
+    (()    (gen-string-of (gen-current-default-size) char-set:graphic))
+    ((cs) (gen-string-of (gen-current-default-size) cs))
+    ((size cs)
      (with-output-to-string
        (lambda ()
          (do ((i 0 (add1 i)))
              ((>= i size))
-           (display (gen))))))))
+           (display (gen-char cs))))))))
 
 (define gen-hash-table-of
   (case-lambda

data-generators.meta

  (author "David Krentzlin")
  (category data)
  (license "BSD")
- (depends)
- (test-depends)
- (foreign-depends))
+ (depends random-bsd)
+ (test-depends test))

data-generators.scm

 (module data-generators
-
   (%random-fixnum
    gen-current-fixnum-min
    gen-current-fixnum-max
    gen-current-default-size
    gen-int8 gen-uint8 gen-int16 gen-uint16 gen-int32 gen-uint32 gen-int64 gen-uint64
-   gen-bool gen-char gen-real gen-pair-of gen-list-of gen-tuple-of gen-vector-of gen-string-of
+   gen-bool gen-char gen-real gen-pair-of gen-list-of gen-alist-of gen-tuple-of gen-vector-of gen-string-of
    gen-fixnum gen-hash-table-of gen-sample-of
-   between at-most at-least)
+   between at-most at-least with-size)
   (import chicken scheme)
   (use (prefix random-bsd bsd:)
        (only ports with-output-to-string)
 (define (between? a x y) (and (>= a x) (<= a y)))
 
 (test-group "gen-bool"
-    (test-assert
-     (in? (gen-bool) (list #t #f))))
+  (test-assert
+    (in? (gen-bool) (list #t #f))))
 
 (test-group "gen-fixnum"
     (test-assert
-      (between? (gen-fixnum) (gen-current-fixnum-min) (gen-current-fixnum-max)))
+     (between? (gen-fixnum) (gen-current-fixnum-min) (gen-current-fixnum-max)))
     (test-assert
      (between? (between gen-fixnum 0 4) 0 4))
     (test-assert
      (>= (at-least gen-real 1.0) 1.0))
     (test-assert
      (<= (at-most gen-real 2.0) 2.0)))
+
+(test-group "gen-pair-of"
+    (test-assert "produces a pair"
+      (pair? (gen-pair-of gen-fixnum gen-fixnum)))
+    (test-assert "car is element of expected set"
+      (fixnum? (car (gen-pair-of gen-fixnum gen-fixnum))))
+    (test-assert "cdr is element of expected set"
+      (fixnum? (cdr (gen-pair-of gen-fixnum gen-fixnum)))))
+
+(test-group "gen-tuple-of"
+    (test "produces tuple of given size"
+          3 (length (gen-tuple-of gen-fixnum gen-fixnum gen-fixnum)))
+    (test "each element is element of expected set"
+          #t
+          (every fixnum? (gen-tuple-of gen-fixnum gen-fixnum))))
+
+(test-group "gen-list-of"
+    (test-assert "produces a list"
+       (list? (gen-list-of gen-fixnum)))
+    (test-assert "each element is part of expected set"
+       (every fixnum? (gen-list-of gen-fixnum)))
+    (test "it generates list of given length"
+      3
+      (with-size 3
+        (length (gen-list-of gen-fixnum)))))
+
+(test-group "gen-alist-of"
+   (test-assert "produces a list"
+      (list? (gen-alist-of gen-char gen-fixnum)))
+   (test-assert "every key is of expected set"
+      (every (compose char? car) (gen-alist-of gen-char gen-fixnum)))
+   (test-assert "every value is of expected set"
+      (every (compose fixnum? cdr) (gen-alist-of gen-char gen-fixnum)))
+   (test "it generates alist of given length"
+       4
+       (with-size 4 (length (gen-alist-of gen-char gen-fixnum)))))
+
+(test-group "gen-vector-of"
+   (test-assert "produces a vector"
+      (vector? (gen-vector-of gen-fixnum)))
+   (test-assert "every element is element of expected set"
+      (every fixnum? (vector->list (gen-vector-of gen-fixnum))))
+   (test "it generates vector of given length"
+      4
+      (with-size 4
+        (vector-length (gen-vector-of gen-fixnum)))))
+
+(test-group "gen-string-of"
+    (test-assert "produces a string"
+      (string? (gen-string-of)))
+    (test-assert "every element is within the given char-set"
+                 (every (cut char-set-contains? char-set:graphic <>)
+                        (string->list
+                         (gen-string-of char-set:graphic))))
+    (test "it generates a string of the given length"
+       10
+       (with-size 10 (string-length (gen-string-of)))))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.