diff options
| author | Paul Eggert | 2013-11-18 10:56:42 -0800 |
|---|---|---|
| committer | Paul Eggert | 2013-11-18 10:56:42 -0800 |
| commit | ec2c4ee6d2cb9c5505f120229269941f064b23fa (patch) | |
| tree | 9c0e0ba58f15f602fce7d349cfa89fc665728161 /test | |
| parent | 87d86601022feb7a330fc6344cc85ec65563c1b6 (diff) | |
| download | emacs-ec2c4ee6d2cb9c5505f120229269941f064b23fa.tar.gz emacs-ec2c4ee6d2cb9c5505f120229269941f064b23fa.zip | |
Improve API of recently-added bool vector functions.
The old API had (bool-vector-count-matches A B)
and (bool-vector-count-matches-at A B I), which gave the
misleading impression that the two functions were variants, one
with a location I. The new API has (bool-vector-count-population A)
and (bool-vector-count-consecutive A B I) to make the distinction
clearer. The first function no longer has a B argument, since the
caller can easily determine the number of nils if the length and
number of ts is known.
* src/data.c (Fbool_vector_count_population): Rename from
bool_vector_count_matches, and accept just 1 argument.
(Fbool_vector_count_consecutive): Rename from
Fbool_vector_count_matches_at.
* test/automated/data-tests.el: Adjust to API changes.
Fixes: debbugs:15912
Diffstat (limited to 'test')
| -rw-r--r-- | test/ChangeLog | 5 | ||||
| -rw-r--r-- | test/automated/data-tests.el | 46 |
2 files changed, 27 insertions, 24 deletions
diff --git a/test/ChangeLog b/test/ChangeLog index 79d9ab544e0..35a168ce0c4 100644 --- a/test/ChangeLog +++ b/test/ChangeLog | |||
| @@ -1,3 +1,8 @@ | |||
| 1 | 2013-11-18 Paul Eggert <eggert@cs.ucla.edu> | ||
| 2 | |||
| 3 | Improve API of recently-added bool vector functions (Bug#15912). | ||
| 4 | * automated/data-tests.el: Adjust to API changes. | ||
| 5 | |||
| 1 | 2013-11-16 Michael Albinus <michael.albinus@gmx.de> | 6 | 2013-11-16 Michael Albinus <michael.albinus@gmx.de> |
| 2 | 7 | ||
| 3 | * automated/tramp-tests.el (tramp-test07-file-exists-p) | 8 | * automated/tramp-tests.el (tramp-test07-file-exists-p) |
diff --git a/test/automated/data-tests.el b/test/automated/data-tests.el index d79e1643848..f731b8bf1db 100644 --- a/test/automated/data-tests.el +++ b/test/automated/data-tests.el | |||
| @@ -77,42 +77,40 @@ | |||
| 77 | ;; Bool vector tests. Compactly represent bool vectors as hex | 77 | ;; Bool vector tests. Compactly represent bool vectors as hex |
| 78 | ;; strings. | 78 | ;; strings. |
| 79 | 79 | ||
| 80 | (ert-deftest bool-vector-count-matches-all-0-nil () | 80 | (ert-deftest bool-vector-count-population-all-0-nil () |
| 81 | (cl-loop for sz in '(0 45 1 64 9 344) | 81 | (cl-loop for sz in '(0 45 1 64 9 344) |
| 82 | do (let* ((bv (make-bool-vector sz nil))) | 82 | do (let* ((bv (make-bool-vector sz nil))) |
| 83 | (should | 83 | (should |
| 84 | (eql | 84 | (zerop |
| 85 | (bool-vector-count-matches bv nil) | 85 | (bool-vector-count-population bv)))))) |
| 86 | sz))))) | ||
| 87 | 86 | ||
| 88 | (ert-deftest bool-vector-count-matches-all-0-t () | 87 | (ert-deftest bool-vector-count-population-all-1-t () |
| 89 | (cl-loop for sz in '(0 45 1 64 9 344) | 88 | (cl-loop for sz in '(0 45 1 64 9 344) |
| 90 | do (let* ((bv (make-bool-vector sz nil))) | 89 | do (let* ((bv (make-bool-vector sz t))) |
| 91 | (should | 90 | (should |
| 92 | (eql | 91 | (eql |
| 93 | (bool-vector-count-matches bv t) | 92 | (bool-vector-count-population bv) |
| 94 | 0))))) | 93 | sz))))) |
| 95 | 94 | ||
| 96 | (ert-deftest bool-vector-count-matches-1-nil () | 95 | (ert-deftest bool-vector-count-population-1-nil () |
| 97 | (let* ((bv (make-bool-vector 45 nil))) | 96 | (let* ((bv (make-bool-vector 45 nil))) |
| 98 | (aset bv 40 t) | 97 | (aset bv 40 t) |
| 99 | (aset bv 0 t) | 98 | (aset bv 0 t) |
| 100 | (should | 99 | (should |
| 101 | (eql | 100 | (eql |
| 102 | (bool-vector-count-matches bv t) | 101 | (bool-vector-count-population bv) |
| 103 | 2))) | 102 | 2)))) |
| 104 | ) | ||
| 105 | 103 | ||
| 106 | (ert-deftest bool-vector-count-matches-1-t () | 104 | (ert-deftest bool-vector-count-population-1-t () |
| 107 | (let* ((bv (make-bool-vector 45 nil))) | 105 | (let* ((bv (make-bool-vector 45 t))) |
| 108 | (aset bv 40 t) | 106 | (aset bv 40 nil) |
| 109 | (aset bv 0 t) | 107 | (aset bv 0 nil) |
| 110 | (should | 108 | (should |
| 111 | (eql | 109 | (eql |
| 112 | (bool-vector-count-matches bv nil) | 110 | (bool-vector-count-population bv) |
| 113 | 43)))) | 111 | 43)))) |
| 114 | 112 | ||
| 115 | (defun mock-bool-vector-count-matches-at (a b i) | 113 | (defun mock-bool-vector-count-consecutive (a b i) |
| 116 | (loop for i from i below (length a) | 114 | (loop for i from i below (length a) |
| 117 | while (eq (aref a i) b) | 115 | while (eq (aref a i) b) |
| 118 | sum 1)) | 116 | sum 1)) |
| @@ -147,8 +145,8 @@ | |||
| 147 | (nreverse nibbles) | 145 | (nreverse nibbles) |
| 148 | ""))) | 146 | ""))) |
| 149 | 147 | ||
| 150 | (defun test-bool-vector-count-matches-at-tc (desc) | 148 | (defun test-bool-vector-count-consecutive-tc (desc) |
| 151 | "Run a test case for bool-vector-count-matches-at. | 149 | "Run a test case for bool-vector-count-consecutive. |
| 152 | DESC is a string describing the test. It is a sequence of | 150 | DESC is a string describing the test. It is a sequence of |
| 153 | hexadecimal digits describing the bool vector. We exhaustively | 151 | hexadecimal digits describing the bool vector. We exhaustively |
| 154 | test all counts at all possible positions in the vector by | 152 | test all counts at all possible positions in the vector by |
| @@ -158,8 +156,8 @@ comparing the subr with a much slower lisp implementation." | |||
| 158 | for lf in '(nil t) | 156 | for lf in '(nil t) |
| 159 | do (loop | 157 | do (loop |
| 160 | for pos from 0 upto (length bv) | 158 | for pos from 0 upto (length bv) |
| 161 | for cnt = (mock-bool-vector-count-matches-at bv lf pos) | 159 | for cnt = (mock-bool-vector-count-consecutive bv lf pos) |
| 162 | for rcnt = (bool-vector-count-matches-at bv lf pos) | 160 | for rcnt = (bool-vector-count-consecutive bv lf pos) |
| 163 | unless (eql cnt rcnt) | 161 | unless (eql cnt rcnt) |
| 164 | do (error "FAILED testcase %S %3S %3S %3S" | 162 | do (error "FAILED testcase %S %3S %3S %3S" |
| 165 | pos lf cnt rcnt))))) | 163 | pos lf cnt rcnt))))) |
| @@ -182,8 +180,8 @@ comparing the subr with a much slower lisp implementation." | |||
| 182 | "0000000000000000000000000" | 180 | "0000000000000000000000000" |
| 183 | "FFFFFFFFFFFFFFFF1")) | 181 | "FFFFFFFFFFFFFFFF1")) |
| 184 | 182 | ||
| 185 | (ert-deftest bool-vector-count-matches-at () | 183 | (ert-deftest bool-vector-count-consecutive () |
| 186 | (mapc #'test-bool-vector-count-matches-at-tc | 184 | (mapc #'test-bool-vector-count-consecutive-tc |
| 187 | bool-vector-test-vectors)) | 185 | bool-vector-test-vectors)) |
| 188 | 186 | ||
| 189 | (defun test-bool-vector-apply-mock-op (mock a b c) | 187 | (defun test-bool-vector-apply-mock-op (mock a b c) |