[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/dash 4640a2a 405/439: Allow for approx comparison of fl
From: |
Phillip Lord |
Subject: |
[elpa] externals/dash 4640a2a 405/439: Allow for approx comparison of floats in tests |
Date: |
Tue, 04 Aug 2015 20:31:17 +0000 |
branch: externals/dash
commit 4640a2a51cba13b935b3670fd4e0c054342aaf2d
Author: William West <address@hidden>
Commit: William West <address@hidden>
Allow for approx comparison of floats in tests
defexample entries may now include a symbol `~>' instead of `=>' which
uses an approximate comparison instead of `equal' to compare actual and
expected floating-point values.
Also, for completeness, add support for the `should-error' symbol `!!>' in
`examples-to-docs.el'. This is formatted as the comment ";; Error"
---
dev/examples-to-docs.el | 12 +++++++++---
dev/examples-to-tests.el | 2 ++
dev/examples.el | 13 ++++++++++++-
3 files changed, 23 insertions(+), 4 deletions(-)
diff --git a/dev/examples-to-docs.el b/dev/examples-to-docs.el
index 6d5044e..f40ce5b 100644
--- a/dev/examples-to-docs.el
+++ b/dev/examples-to-docs.el
@@ -5,9 +5,15 @@
(defvar functions '())
(defun example-to-string (example)
- (let ((actual (car example))
- (expected (nth 2 example)))
- (--> (format "%S ;; => %S" actual expected)
+ (-let* (((actual sym expected) example)
+ (comment
+ (cond
+ ((eq sym '=>) (format "=> %S" expected))
+ ((eq sym '~>) (format "~> %S" expected))
+ ((eq sym '!!>) (format "Error"))
+ (t (error "Invalid test case: %S" `(,actual ,sym ,expected))))))
+ (--> comment
+ (format "%S ;; %s" actual it)
(replace-regexp-in-string "\\\\\\?" "?" it)
(replace-regexp-in-string "\n" "\\n" it t t)
(replace-regexp-in-string "\t" "\\t" it t t)
diff --git a/dev/examples-to-tests.el b/dev/examples-to-tests.el
index 49d6649..bd01637 100644
--- a/dev/examples-to-tests.el
+++ b/dev/examples-to-tests.el
@@ -3,6 +3,8 @@
(defun example-to-should (actual sym expected)
(cond ((eq sym '=>)
`(should (equal ,actual ,expected)))
+ ((eq sym '~>)
+ `(should (approx-equal ,actual ,expected)))
((eq sym '!!>)
`(should-error (eval ',actual) :type ',expected))
(t
diff --git a/dev/examples.el b/dev/examples.el
index 79ac244..ac09d16 100644
--- a/dev/examples.el
+++ b/dev/examples.el
@@ -9,6 +9,17 @@
(defun square (num) (* num num))
(defun three-letters () '("A" "B" "C"))
+;; Allow approximate comparison of floating-point results, to work
+;; around differences in implementation between systems. Use the `~>'
+;; symbol instead of `=>' to test the expected and actual values with
+;; `approx-equal'
+(defvar epsilon 1e-15)
+(defun approx-equal (u v)
+ (or (= u v)
+ (< (/ (abs (- u v))
+ (max (abs u) (abs v)))
+ epsilon)))
+
(def-example-group "Maps"
"Functions in this category take a transforming function, which
is then applied sequentially to each or selected elements of the
@@ -977,5 +988,5 @@ new list."
(funcall (-prodfn (-compose f ff) (-compose g gg))
input3)))) => t)))
;; Local Variables:
-;; eval: (font-lock-add-keywords nil '(("defexamples\\|def-example-group\\| =>
\\| !!> " (0 'font-lock-keyword-face)) ("(defexamples[[:blank:]]+\\(.*\\)" (1
'font-lock-function-name-face))))
+;; eval: (font-lock-add-keywords nil '(("defexamples\\|def-example-group\\| =>
\\| !!> \\| ~>" (0 'font-lock-keyword-face))
("(defexamples[[:blank:]]+\\(.*\\)" (1 'font-lock-function-name-face))))
;; End:
- [elpa] externals/dash 1677338 428/439: Merge pull request #138 from phillord/fix/group-by-write-out, (continued)
- [elpa] externals/dash 1677338 428/439: Merge pull request #138 from phillord/fix/group-by-write-out, Phillip Lord, 2015/08/04
- [elpa] externals/dash e468937 435/439: Formatting, Phillip Lord, 2015/08/04
- [elpa] externals/dash 89abffe 437/439: Make it explicit that not all VALS are evalled in -if-let*, Phillip Lord, 2015/08/04
- [elpa] externals/dash b88cfb7 436/439: Add dash prefix to epsilon variable., Phillip Lord, 2015/08/04
- [elpa] externals/dash eadb265 439/439: Swap examples to better show how -some-> works, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2aeeacb 433/439: Release 2.11.0, Phillip Lord, 2015/08/04
- [elpa] externals/dash c3cf98d 438/439: Add `-some->`, `-some->>`, and `-some-->` macros., Phillip Lord, 2015/08/04
- [elpa] externals/dash 1c2f43d 434/439: Add "See also" for the reduce family, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2b69c14 411/439: Add dash.info and dash.texi to repo, Phillip Lord, 2015/08/04
- [elpa] externals/dash e574465 404/439: Add `-some`, Phillip Lord, 2015/08/04
- [elpa] externals/dash 4640a2a 405/439: Allow for approx comparison of floats in tests,
Phillip Lord <=
- [elpa] externals/dash 3b63476 412/439: Move anaphoric function intro up into Functions section, Phillip Lord, 2015/08/04
- [elpa] externals/dash 19fbc24 426/439: Fix anaphoric -spice-list macro, Phillip Lord, 2015/08/04
- [elpa] externals/dash 2db56f5 424/439: [-let] Add support for &as bindings (#115), Phillip Lord, 2015/08/04
- [elpa] externals/dash ffa37bf 425/439: Merge pull request #129 from holomorph/docs, Phillip Lord, 2015/08/04
- [elpa] externals/dash 81b808d 409/439: Ignore dash.elc, Phillip Lord, 2015/08/04
- [elpa] externals/dash c61113b 420/439: [-let] Update outdated comment, Phillip Lord, 2015/08/04
- [elpa] externals/dash 733274f 398/439: Merge pull request #120 from holomorph/info-manual, Phillip Lord, 2015/08/04
- [elpa] externals/dash a803dd5 414/439: Merge readme changes, Phillip Lord, 2015/08/04
- [elpa] externals/dash 7bd6b3b 400/439: Add dir entry to texinfo template, Phillip Lord, 2015/08/04
- [elpa] externals/dash 5219ac0 422/439: [-let] Eliminate useless re-binding of symbols when sources are immutable, Phillip Lord, 2015/08/04