document and test dict behavior on bad association lists
Follows up on ce3992dbf3
to document and test the constraints
that required reverting the earlier change.
This commit is contained in:
parent
ce3992dbf3
commit
387f90ed92
|
@ -15,14 +15,20 @@ values. The following datatypes are all dictionaries:
|
|||
|
||||
@item{@techlink{vectors} (using only exact integers as keys);}
|
||||
|
||||
@item{@techlink{lists} of @techlink{pairs} (an @deftech{association
|
||||
list} using @racket[equal?] to compare keys); and}
|
||||
@item{@techlink{lists} of @techlink{pairs} as an @deftech{association
|
||||
list} using @racket[equal?] to compare keys, which must be distinct; and}
|
||||
|
||||
@item{@techlink{structures} whose types implement the @racket[gen:dict]
|
||||
@tech{generic interface}.}
|
||||
|
||||
]
|
||||
|
||||
When list of pairs is used as @tech{association list} but does not
|
||||
have distinct keys (so it's not an association list), operations like
|
||||
@racket[dict-ref] and @racket[dict-remove] operate on the first
|
||||
instance of the key, while operations like @racket[dict-map] and
|
||||
@racket[dict-keys] produce an element for every instance of the key.
|
||||
|
||||
@note-lib[racket/dict]
|
||||
|
||||
@section{Dictionary Predicates and Contracts}
|
||||
|
|
|
@ -163,6 +163,16 @@
|
|||
;; preserve from GC:
|
||||
(list s1 s2)))
|
||||
|
||||
;; Check behavior on a list of pairs that isn't
|
||||
;; a dictionary due to duplicate keys:
|
||||
(test 1 dict-ref '((a . 1) (b . 2) (a . 3)) 'a)
|
||||
(test '((b . 2) (a . 3)) dict-remove '((a . 1) (b . 2) (a . 3)) 'a)
|
||||
(test '((a . 4) (b . 2) (a . 3)) dict-set '((a . 1) (b . 2) (a . 3)) 'a 4)
|
||||
(test 3 dict-count '((a . 1) (b . 2) (a . 3)))
|
||||
(test '((a 1) (b 2) (a 3)) dict-map '((a . 1) (b . 2) (a . 3)) list)
|
||||
(test '(a b a) dict-keys '((a . 1) (b . 2) (a . 3)))
|
||||
(test '(1 2 3) dict-values '((a . 1) (b . 2) (a . 3)))
|
||||
|
||||
;; ----------------------------------------
|
||||
|
||||
(report-errs)
|
||||
|
|
Loading…
Reference in New Issue
Block a user