Commits

Anonymous committed 5cbe9cb

added proper handling of inexact numbers in is-matcher

Comments (0)

Files changed (1)

veritas-verifiers.scm

 (module veritas-verifiers
   *
-  (import chicken scheme data-structures extras ports)
+  (import chicken scheme data-structures extras ports srfi-69)
   (use veritas srfi-1)
 
 
     ((_ pred value more-values ...)
      (is-verifier/predicate pred (list value more-values ...)))))
 
+(define (is-equal? a b)
+  (or (equal? a b)
+      (and (number? a)
+           (inexact? a)
+           (inexact? b)
+           (approx-equal? a b))))
+
+(define (approx-equal? a b delta)
+  (cond
+   ((> (abs a) (abs b))
+    (approx-equal? b a delta))
+   ((zero? b)
+    (< (abs a) delta))
+   (else
+    (< (abs (/ (- a b) b)) delta))))
 
 (define ((is-verifier pred-or-value) complement? quoted-expr expr)
   (let* ((value (force expr))
            complement?
            (if (procedure? pred-or-value)
                (pred-or-value value)
-               (equal? pred-or-value value)))))
+               (is-equal? pred-or-value value)))))
     (if result
         (pass quoted-expr)
         (cond
         (fail quoted-expr (sprintf "Expected ~S ~A be a ~A" value (if complement? "not to" "to") type)))))
 
 (define ((close-to what #!key (delta 0.3)) actual)
-  (define (approx-equal? a b delta)
-    (cond
-     ((> (abs a) (abs b))
-      (approx-equal? b a delta))
-     ((zero? b)
-      (< (abs a) delta))
-     (else
-      (< (abs (/ (- a b) b)) delta))))
   (approx-equal? what actual delta))
 
 (define roughly close-to)
        (let ((subject (vector->list subject)))
          (every (cut member <> subject) args))))
 
-(define ((hash-table-including item . more-items) subject) #t)
+(define ((hash-table-including . args) subject)
+  (and (hash-table? subject)
+       (every (lambda (pair)
+                (equal? (cdr pair) (hash-table-ref subject (car pair))))
+              args)))
 
 )
 
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.