diff options
| author | Wolfgang Jenkner | 2015-01-15 20:02:17 +0100 |
|---|---|---|
| committer | Wolfgang Jenkner | 2015-01-15 23:54:00 +0100 |
| commit | 2290000ed69b1157739c280f090e5b60112e83fe (patch) | |
| tree | f99e98a90548c979fa53347344d307bf25f225c1 /test | |
| parent | b577fe28c73cacfd1e81dca5ebf8cc7b0830d957 (diff) | |
| download | emacs-2290000ed69b1157739c280f090e5b60112e83fe.tar.gz emacs-2290000ed69b1157739c280f090e5b60112e83fe.zip | |
Handle the `neg' operator in some calc-units functions.
* lisp/calc/calc-units.el (math-units-in-expr-p)
(math-single-units-in-expr-p, math-find-compatible-unit-rec)
(math-extract-units): Handle the `neg' operator. (Bug#19582)
* test/automated/calc-tests.el (calc-tests-equal, calc-tests-simple):
New functions.
(test-calc-remove-units, test-calc-extract-units)
(test-calc-convert-units): New tests.
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 7 | ||||
| -rw-r--r-- | test/automated/calc-tests.el | 52 |
2 files changed, 59 insertions, 0 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 95d3e544aab..b3a0494267e 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,5 +1,12 @@ | |||
| 1 | 2015-01-15 Wolfgang Jenkner <wjenkner@inode.at> | 1 | 2015-01-15 Wolfgang Jenkner <wjenkner@inode.at> |
| 2 | 2 | ||
| 3 | * automated/calc-tests.el (calc-tests-equal, calc-tests-simple): | ||
| 4 | New functions. | ||
| 5 | (test-calc-remove-units, test-calc-extract-units) | ||
| 6 | (test-calc-convert-units): New tests. | ||
| 7 | |||
| 8 | 2015-01-15 Wolfgang Jenkner <wjenkner@inode.at> | ||
| 9 | |||
| 3 | * automated/Makefile.in (WRITE_LOG): Use POSIX redirection. | 10 | * automated/Makefile.in (WRITE_LOG): Use POSIX redirection. |
| 4 | 11 | ||
| 5 | 2015-01-15 Stefan Monnier <monnier@iro.umontreal.ca> | 12 | 2015-01-15 Stefan Monnier <monnier@iro.umontreal.ca> |
diff --git a/test/automated/calc-tests.el b/test/automated/calc-tests.el index 331e01e4640..d5252ea62a9 100644 --- a/test/automated/calc-tests.el +++ b/test/automated/calc-tests.el | |||
| @@ -27,6 +27,40 @@ | |||
| 27 | (require 'cl-lib) | 27 | (require 'cl-lib) |
| 28 | (require 'ert) | 28 | (require 'ert) |
| 29 | (require 'calc) | 29 | (require 'calc) |
| 30 | (require 'calc-ext) | ||
| 31 | (require 'calc-units) | ||
| 32 | |||
| 33 | ;; XXX The order in which calc libraries (in particular calc-units) | ||
| 34 | ;; are loaded influences whether a calc integer in an expression | ||
| 35 | ;; involving units is represented as a lisp integer or a calc float, | ||
| 36 | ;; see bug#19582. Until this will be fixed the following function can | ||
| 37 | ;; be used to compare such calc expressions. | ||
| 38 | (defun calc-tests-equal (a b) | ||
| 39 | "Like `equal' but allow for different representations of numbers. | ||
| 40 | For example: (calc-tests-equal 10 '(float 1 1)) => t. | ||
| 41 | A and B should be calc expressions." | ||
| 42 | (cond ((math-numberp a) | ||
| 43 | (and (math-numberp b) | ||
| 44 | (math-equal a b))) | ||
| 45 | ((atom a) | ||
| 46 | (equal a b)) | ||
| 47 | ((consp b) | ||
| 48 | ;; Can't be dotted or circular. | ||
| 49 | (and (= (length a) (length b)) | ||
| 50 | (equal (car a) (car b)) | ||
| 51 | (cl-every #'calc-tests-equal (cdr a) (cdr b)))))) | ||
| 52 | |||
| 53 | (defun calc-tests-simple (fun string &rest args) | ||
| 54 | "Push STRING on the calc stack, then call FUN and return the new top. | ||
| 55 | The result is a calc (i.e., lisp) expression, not its string representation. | ||
| 56 | Also pop the entire stack afterwards. | ||
| 57 | An existing calc stack is reused, otherwise a new one is created." | ||
| 58 | (calc-eval string 'push) | ||
| 59 | (prog1 | ||
| 60 | (ignore-errors | ||
| 61 | (apply fun args) | ||
| 62 | (calc-top-n 1)) | ||
| 63 | (calc-pop 0))) | ||
| 30 | 64 | ||
| 31 | (ert-deftest test-math-bignum () | 65 | (ert-deftest test-math-bignum () |
| 32 | ;; bug#17556 | 66 | ;; bug#17556 |
| @@ -34,6 +68,24 @@ | |||
| 34 | (should (math-negp n)) | 68 | (should (math-negp n)) |
| 35 | (should (cl-notany #'cl-minusp (cdr n))))) | 69 | (should (cl-notany #'cl-minusp (cdr n))))) |
| 36 | 70 | ||
| 71 | (ert-deftest test-calc-remove-units () | ||
| 72 | (should (calc-tests-equal (calc-tests-simple #'calc-remove-units "-1 m") -1))) | ||
| 73 | |||
| 74 | (ert-deftest test-calc-extract-units () | ||
| 75 | (should (calc-tests-equal (calc-tests-simple #'calc-extract-units "-1 m") | ||
| 76 | '(var m var-m))) | ||
| 77 | (should (calc-tests-equal (calc-tests-simple #'calc-extract-units "-1 m*cm") | ||
| 78 | '(* (float 1 -2) (^ (var m var-m) 2))))) | ||
| 79 | |||
| 80 | (ert-deftest test-calc-convert-units () | ||
| 81 | ;; Used to ask for `(The expression is unitless when simplified) Old Units: '. | ||
| 82 | (should (calc-tests-equal (calc-tests-simple #'calc-convert-units "-1 m" nil "cm") | ||
| 83 | '(* -100 (var cm var-cm)))) | ||
| 84 | ;; Gave wrong result. | ||
| 85 | (should (calc-tests-equal (calc-tests-simple #'calc-convert-units "-1 m" | ||
| 86 | (math-read-expr "1m") "cm") | ||
| 87 | '(* -100 (var cm var-cm))))) | ||
| 88 | |||
| 37 | (provide 'calc-tests) | 89 | (provide 'calc-tests) |
| 38 | ;;; calc-tests.el ends here | 90 | ;;; calc-tests.el ends here |
| 39 | 91 | ||