Implement set equality.
This commit is contained in:
parent
30664d10f8
commit
575c1cdb3d
7 changed files with 44 additions and 7 deletions
|
@ -389,6 +389,13 @@ Returns a new lset instance containing elements present both in
|
|||
Returns a new lset instance from ```ls1``` with all elements in
|
||||
```ls2``` removed from it.
|
||||
|
||||
(lset=? ls1 ls2)
|
||||
|
||||
* ```ls1``` - lset instance
|
||||
* ```ls2``` - lset instance
|
||||
|
||||
Returns true if the sets contain exactly the same values.
|
||||
|
||||
### String
|
||||
|
||||
(import util-string)
|
||||
|
|
|
@ -93,7 +93,8 @@ listing.o: listing.import.scm
|
|||
listing.import.scm: $(LISTING-SOURCES)
|
||||
|
||||
UTIL-DICT-LIST-SOURCES=util-dict-list.scm testing.import.scm \
|
||||
util-tag.import.scm util-proc.import.scm
|
||||
util-tag.import.scm util-proc.import.scm \
|
||||
util-set-list.import.scm
|
||||
|
||||
util-dict-list.o: util-dict-list.import.scm
|
||||
util-dict-list.import.scm: $(UTIL-DICT-LIST-SOURCES)
|
||||
|
|
|
@ -354,10 +354,11 @@
|
|||
member-record
|
||||
(test-equal? make-member-record
|
||||
(make-member-record '|1234| "members/1234" '(|member|))
|
||||
'((file-name . |1234|)
|
||||
(make-ldict
|
||||
'((file-name . |1234|)
|
||||
(file-path . "members/1234")
|
||||
(symlinks |member|)
|
||||
(id . 1234)))
|
||||
(id . 1234))))
|
||||
(test-equal? make-member-record
|
||||
(make-member-record '|1234| "members/1234" '(|member|) #:msg "msg")
|
||||
'((msg . "msg")
|
||||
|
|
|
@ -161,14 +161,15 @@
|
|||
(test-equal? files+symlinks->files-dictionary
|
||||
(files+symlinks->files-dictionary
|
||||
'(joe (2803 . joe)))
|
||||
'((joe 2803)))
|
||||
(make-ldict '((joe 2803))))
|
||||
(test-equal? files+symlinks->files-dictionary
|
||||
(files+symlinks->files-dictionary
|
||||
'(joe
|
||||
(2803 . joe)
|
||||
(666 . nonexistent)))
|
||||
'((nonexistent error-0 666)
|
||||
(joe 2803)))
|
||||
(make-ldict
|
||||
'((joe 2803)
|
||||
(nonexistent error-0 666))))
|
||||
(test-true is-4digit-string? (is-4digit-string? "0000"))
|
||||
(test-false is-4digit-string? (is-4digit-string? "AAAA"))
|
||||
(test-false is-4digit-string? (is-4digit-string? "666"))
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
ldict-map
|
||||
ldict-filter
|
||||
ldict-reduce
|
||||
|
||||
ldict-equal?
|
||||
|
||||
ldict-tests!
|
||||
)
|
||||
|
@ -55,7 +57,8 @@
|
|||
(chicken base)
|
||||
testing
|
||||
util-tag
|
||||
util-proc)
|
||||
util-proc
|
||||
util-set-list)
|
||||
|
||||
;; Tag used for identifying list dictionaries from this module
|
||||
(define TAG-LDICT (make-tag LDICT))
|
||||
|
@ -208,6 +211,14 @@
|
|||
(loop (cdr pairs)
|
||||
(proc acc (caar pairs) (cdar pairs))))))
|
||||
|
||||
;; Returns true if both dictionaries contain the same keys and
|
||||
;; values.
|
||||
(define (ldict-equal? d1 d2)
|
||||
(let ((k1 (list->lset (ldict-keys d1)))
|
||||
(k2 (list->lset (ldict-keys d2))))
|
||||
;; Compare key sets
|
||||
#f))
|
||||
|
||||
;; Performs self-tests of the dictionary module.
|
||||
(define (ldict-tests!)
|
||||
(run-tests
|
||||
|
|
|
@ -50,6 +50,8 @@
|
|||
lset-intersect
|
||||
lset-subtract
|
||||
|
||||
lset=?
|
||||
|
||||
lset-tests!
|
||||
)
|
||||
|
||||
|
@ -172,6 +174,11 @@
|
|||
(loop (cdr lst)
|
||||
(lset-remove ls (car lst))))))
|
||||
|
||||
;; Returns true if two sets are equal
|
||||
(define (lset=? s1 s2)
|
||||
(and (lset-empty? (lset-subtract s1 s2))
|
||||
(lset-empty? (lset-subtract s2 s1))))
|
||||
|
||||
;; Module self-tests
|
||||
(define (lset-tests!)
|
||||
(run-tests
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
(
|
||||
string-repeat
|
||||
string-first+rest
|
||||
string-utf8?
|
||||
)
|
||||
|
||||
(import scheme
|
||||
|
@ -57,6 +58,12 @@
|
|||
(val (irregex-replace (irregex "^[ \\t]*" 'u) sep+val "")))
|
||||
(cons key-str val))
|
||||
(cons str ""))))
|
||||
|
||||
;; Returns true, if given string contains UTF-8 characters
|
||||
(define (string-utf8? str)
|
||||
(let ((asciilen (string-length str))
|
||||
(utf8len (length (irregex-extract (irregex "." 'u)))))
|
||||
(not (= asciilen utf8len))))
|
||||
|
||||
;; Performs utils module self-tests.
|
||||
(define (utils-tests!)
|
||||
|
@ -77,6 +84,8 @@
|
|||
(test-equal? string-first+rest
|
||||
(string-first+rest "asdf")
|
||||
'("asdf" . ""))
|
||||
(test-true string-utf8? (string-utf8? "ěščř"))
|
||||
(test-false string-utf8? (string-utf8? "Hello World!"))
|
||||
))
|
||||
|
||||
)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue