Commits

Anonymous committed 938d25c

Refactor tests. Add 18 new test cases.

  • Participants
  • Parent commits 263480b

Comments (0)

Files changed (3)

Cheatsheet

-bert = BERT.encode(t[:foo,42,666,t[12,[],t[255,:bar],111222333444555666]])
-
-bert.each_byte{|c| print c, ' '}
-
-131 104 4 100 0 3 102 111 111 97 42 98 0 0 2 154 104 4 97 12 106 104 2 97 255 100 0 3 98 97 114 110 8 0 146 131 13 124 31 36 139 1
 Caveats
 -------
 
-Regular expressions conversion is not supported, because evey Scheme comes with its own regexp implementation and I haven't found any portable library which allows to get source regexp after one is compiled.
+Regular expressions conversion is not supported, because every Scheme comes with its own regexp implementation and I haven't found any portable library which allows to get the source string of a regexp after one is compiled.
 
 Trivia
 ------
 #!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))))))))