scheme-bert / test / tests.ss

Diff from to

test/tests.ss

 #!r6rs
 (import (scheme-bert)
         (rnrs)
-        (rnrs bytevectors)        
+        (rnrs bytevectors)
+        (rnrs io ports)
         ;; Either import SRFI 19 or use 
         ;; builtin functions (as in Chez Scheme))
         (srfi :19)
         )
 
 ; calling of these procs independently is useful: 
-; test-encoder, test-decoder, test-bert
+; test-encoder, test-decoder, test-roundtrip
 
 (define (fold/and proc lst)
   (cond
         (newline)
         #f)))
 
-(define (test-encoder)
-  (let* ((result (list (test-encoder-1)
-                       (test-encoder-time)
-                       (test-bignum)))
+(define (test-group tests)
+  (let* ((result (map (lambda (x) (x)) tests))
          (suc (filter (lambda (x) x) result))
          (fail (filter not result)))
-    (display "=== Performing encoder test ===") (newline)
-    (display (string-append "Successful: " 
-                            (number->string (length suc))
-                            ". " 
-                            "Failed: " (number->string (length fail))))
-    (newline) (display "Encoder test done.") (newline)))
+    (display (string-append (number->string (length suc))  " tests, " 
+                            (number->string (length fail)) " failures"))
+    (newline) (display "Finished.") (newline)))
+
+(define (test-encoder)
+  (display "=== Performing encoder test ===") (newline)
+  (test-group (list test-encoder-1
+                    test-encoder-time
+                    test-bignum)))
 
 (define (test-decoder)
-  (let* ((result (list (test-decoder-string)))
-         (suc (filter (lambda (x) x) result))
-         (fail (filter not result)))
-    (display "=== Performing decoder test ===") (newline)
-    (display (string-append "Successful: " 
-                            (number->string (length suc))
-                            ". " 
-                            "Failed: " (number->string (length fail))))
-    (newline) (display "Decoder test done.") (newline)))
+  (display "=== Performing decoder test ===") (newline)
+  (test-group (list test-decoder-string
+                    test-hash)))
 
-(define (test-bert)
-  (let* ((result (list (test-hash)))
-         (suc (filter (lambda (x) x) result))
-         (fail (filter not result)))
-    (display "=== Performing roundtrip tests ===") (newline)
-    (display (string-append "Successful: " 
-                            (number->string (length suc))
-                            ". " 
-                            "Failed: " (number->string (length fail))))
-    (newline) (display "Test done.") (newline)))
+(define (checkthis-bert datum)
+  (lambda ()
+    (checkthis (call-with-string-output-port
+                (lambda (outport) (display datum outport))) 
+               (bert-decode (bert-encode datum))
+               datum)))
+
+(define (test-roundtrip)
+  (display "=== Performing roundtrip tests ===") (newline)
+  (test-group (list (checkthis-bert 1)
+                    (checkthis-bert 1.0)
+                    (checkthis-bert 'a)
+                    (checkthis-bert (vector))
+                    (checkthis-bert (vector 'a))
+                    (checkthis-bert (vector 'a 'b))
+                    (checkthis-bert (vector (vector 'a 1) (vector 'b 2)))
+                    (checkthis-bert '())
+                    (checkthis-bert '(a))
+                    (checkthis-bert '(a 1))
+                    (checkthis-bert '('(a 1) '(b 2)))
+                    (checkthis-bert "a")
+                    (checkthis-bert 'nil)
+                    (checkthis-bert #t)
+                    (checkthis-bert #f)
+                    (checkthis-bert (- (expt 256 256) 1))
+                    (checkthis-bert 'true)
+                    (checkthis-bert 'false))))
 
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Encoder test cases
                                          110 103 32 83 112 97 103 104 
                                          101 116 116 105 32 77 111 110 
                                          115 116 101 114)))))
-  
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; Roundtrip (encode->decode and vice versa) test cases
 ;;
                     (fold/and (lambda (x) (member x (vector->list keys2)))
                               (vector->list keys2))
                     (fold/and (lambda (x) (member x (vector->list vals2)))
-                              (vector->list vals2))))))))
+                              (vector->list vals2))))))))
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.