Add membership test.
authorChris Hanson <org/chris-hanson/cph>
Sun, 30 May 2010 23:26:32 +0000 (16:26 -0700)
committerChris Hanson <org/chris-hanson/cph>
Sun, 30 May 2010 23:26:32 +0000 (16:26 -0700)
tests/runtime/test-char-set.scm

index 9857f5cf55062fe7ff35f60685f7c9090dc6966a..caf958ceb01cbc7b423ac798583826b6c9474dce 100644 (file)
@@ -72,6 +72,35 @@ USA.
              (if (= m 0)
                  n
                  (cons n (+ n m 1))))))))))
+
+(define-test 'membership
+  (lambda ()
+    (map (lambda (svl)
+          (map (lambda (value)
+                 (run-sub-test
+                  (lambda ()
+                    (with-test-properties
+                        (lambda ()
+                          (assert-boolean-=
+                           (char-set-member? (scalar-values->char-set svl)
+                                             (integer->char value))
+                           (named-call 'SVL-MEMBER? svl-member? svl value)))
+                      'EXPRESSION `(CHAR-SET-MEMBER? ,svl ,value)))))
+               (enumerate-test-values)))
+        interesting-svls)))
+
+(define (enumerate-test-values)
+  (append (iota (+ %low-limit 8))
+         (iota 8 (- char-code-limit 8))))
+
+(define (svl-member? svl value)
+  (let loop ((svl svl))
+    (if (pair? svl)
+       (if (and (<= (segment-start (car svl)) value)
+                (< value (segment-end (car svl))))
+           #t
+           (loop (cdr svl)))
+       #f)))
 \f
 (define-test 'invert
   (lambda ()