SummaryRefsLogTreeCommitDiffStats
diff options
context:
space:
mode:
authorMathieu Lirzin <mthl@gnu.org>2018-03-26 16:39:13 +0200
committerMathieu Lirzin <mthl@gnu.org>2018-03-26 17:20:26 +0200
commitfad58ca8c221def75093463e917f66fc006f3df5 (patch)
tree77f7dce258ab0069d95734bd9436e80417998de8
parente66f0dcdd6f1838c8d4f5d70cea7ca63dc150ead (diff)
downloadmcron-fad58ca8c221def75093463e917f66fc006f3df5.tar.gz
mcron-fad58ca8c221def75093463e917f66fc006f3df5.tar.bz2
mcron-fad58ca8c221def75093463e917f66fc006f3df5.zip
job-specifier: Preserve '%find-best-next' arguments exactness
The behavior of the 'min' procedure which converts its parameters to inexact numbers when at least one of them is inexact was causing '%find-best-next' to always return real numbers. * src/mcron/job-specifier.scm (%find-best-next): Preserve the exactness of numbers in NEXT-LIST. * tests/job-specifier.scm ("%find-best-next: exact"): New test. Reported-by: Ludovic Courtès <ludo@gnu.org>
-rw-r--r--src/mcron/job-specifier.scm8
-rw-r--r--tests/job-specifier.scm11
2 files changed, 16 insertions, 3 deletions
diff --git a/src/mcron/job-specifier.scm b/src/mcron/job-specifier.scm
index 5c8e171..e3b3391 100644
--- a/src/mcron/job-specifier.scm
+++ b/src/mcron/job-specifier.scm
@@ -60,12 +60,16 @@ go into the list. For example, (range 1 6 2) returns '(1 3 5)."
;; consisting of the smallest element of the NEXT-LIST, and the smallest
;; element larger than the CURRENT value. If an example of the latter
;; cannot be found, +INF.0 will be returned.
+ (define (exact-min a b)
+ ;; An implement of 'min' which preserves the exactness its arguments.
+ (if (< a b) a b))
+
(let loop ((smallest (inf)) (closest+ (inf)) (lst next-list))
(match lst
(() (cons smallest closest+))
((time . rest)
- (loop (min time smallest)
- (if (> time current) (min time closest+) closest+)
+ (loop (exact-min time smallest)
+ (if (> time current) (exact-min time closest+) closest+)
rest)))))
(define (bump-time time value-list component higher-component
diff --git a/tests/job-specifier.scm b/tests/job-specifier.scm
index 889530b..48a46de 100644
--- a/tests/job-specifier.scm
+++ b/tests/job-specifier.scm
@@ -16,7 +16,8 @@
;;; You should have received a copy of the GNU General Public License
;;; along with GNU Mcron. If not, see <http://www.gnu.org/licenses/>.
-(use-modules (srfi srfi-64)
+(use-modules (ice-9 match)
+ (srfi srfi-64)
(mcron job-specifier))
(test-begin "job-specifier")
@@ -40,4 +41,12 @@
(test-assert "range: reverse boundaries"
(range 10 3))
+(define %find-best-next (@@ (mcron job-specifier) %find-best-next))
+
+(test-assert "%find-best-next: exact"
+ ;; Ensure that '%find-best-next' preserves the exactness of the numbers
+ ;; inside the NEXT-LIST argument.
+ (match (pk 'match (%find-best-next 1 '(0 2)))
+ ((a . b) (and (exact? a) (exact? b)))))
+
(test-end)