Fixing bug in iset-adjoin for values already present at a node boundary.

This commit is contained in:
Alex Shinn 2013-11-09 16:35:22 +09:00
parent c0619b769d
commit d2bd4d6d44
2 changed files with 9 additions and 6 deletions

View file

@ -81,7 +81,7 @@
(if (let* ((left (iset-left iset))
(m-end (and left (iset-max-end left))))
(and m-end
(or (< n m-end)
(or (<= n m-end)
(< (- n m-end) s-diff))))
(iset-adjoin1! (iset-left iset) n)
(cond
@ -98,7 +98,7 @@
(if (let* ((right (iset-right iset))
(m-start (and right (iset-min-start right))))
(and m-start
(or (> n m-start)
(or (>= n m-start)
(> (- n m-start) e-diff))))
(iset-adjoin1! (iset-right iset) n)
(cond

View file

@ -1,6 +1,7 @@
(cond-expand
(modules (import (chibi iset) (chibi iset optimize) (srfi 1) (chibi test)))
(modules
(import (chibi) (chibi iset) (chibi iset optimize) (srfi 1) (chibi test)))
(else #f))
(test-begin "iset")
@ -15,6 +16,7 @@
((0 1 2) (- 1) (- 2) (? 0))
((1 2 3 1000 2000) (u 1 4))
((1 2 3 1000 1005))
((97308 97827 97845 97827))
((1 128 127))
((129 2 127))
((1 -128 -126))
@ -25,10 +27,11 @@
(for-each
(lambda (tst)
(let* ((ls (car tst))
(is (list->iset ls)))
(is (list->iset ls))
(ls2 (delete-duplicates ls =)))
;; initial creation and sanity checks
(test-assert (lset= equal? ls (iset->list is)))
(test (length ls) (iset-size is))
(test-assert (lset= equal? ls2 (iset->list is)))
(test (length ls2) (iset-size is))
(for-each
(lambda (x) (test-assert (iset-contains? is x)))
ls)