Raymond Toy pushed to branch issue-240-add-hashtable-for-destructive-set-ops at cmucl / cmucl

Commits:

1 changed file:

Changes:

  • tests/sets.lisp
    ... ... @@ -88,8 +88,38 @@
    88 88
     				:test 'eql
    
    89 89
     				:test-not 'eql)))
    
    90 90
     
    
    91
    -   
    
    92 91
     
    
    92
    +(define-test nset-diff.1
    
    93
    +    (:tags :issues)
    
    94
    +  ;; From CLHS
    
    95
    +  (flet 
    
    96
    +      ((test1)
    
    97
    +       (let ((lst1 (list "A" "b" "C" "d"))
    
    98
    +             (lst2 (list "a" "B" "C" "d")))
    
    99
    +         (assert-equal '("b" "A")
    
    100
    +                       (nset-difference lst1 lst2 :test 'equal))
    
    101
    +         ;; This isn't specified by the CLHS, but it is what we do.
    
    102
    +         (assert-equal '("A") lst1)))
    
    103
    +    (test1)
    
    104
    +    
    
    105
    +    (let ((lisp::*min-list-length-for-hashtable* 1))
    
    106
    +      (test1))))
    
    107
    +
    
    108
    +(define-test nset-diff.key
    
    109
    +    (:tags :issues)
    
    110
    +  (flet
    
    111
    +      ((test)
    
    112
    +       ;; From CLHS
    
    113
    +       (let ((lst1 (list '("a" . "b") '("c" . "d") '("e" . "f")))
    
    114
    +             (lst2 (list '("c" . "a") '("e" . "b") '("d" . "a"))))
    
    115
    +         (assert-equal '(("e" . "f" ("c" . "d")))
    
    116
    +                       (nset-difference lst1 lst2 :test 'equal :key #'cdr))
    
    117
    +         ;; This isn't specified by the CLHS, but it is what we do.
    
    118
    +         (assert-equal '(("a" . "b") ("c" . "d")) lst1)))
    
    119
    +    (test)
    
    120
    +    (let ((lisp::*min-list-length-for-hashtable* 1))
    
    121
    +      (test))))
    
    122
    +  
    
    93 123
     (define-test union.hash-eql
    
    94 124
         (:tag :issues)
    
    95 125
       ;; For union to use hashtables by making the threshold
    
    ... ... @@ -172,3 +202,82 @@
    172 202
     		       '(3 4)
    
    173 203
     		       :test 'eql
    
    174 204
     		       :test-not 'eql)))
    
    205
    +
    
    206
    +(define-test nunion.1
    
    207
    +    (:tag :issues)
    
    208
    +  (flet
    
    209
    +      ((test)
    
    210
    +       (let ((lst1 (list 1 2 '(1 2) "a" "b"))
    
    211
    +             (lst2 (list 2 3 '(2 3) "B" "C")))
    
    212
    +         (assert-equal '("b" "a" (1 2) 1 2 3 (2 3) "B" "C")
    
    213
    +                       (nunion lst1 lst2))
    
    214
    +         (assert-equal '(1 2 3 (2 3) "B" "C")
    
    215
    +                       lst1)))
    
    216
    +    (test)
    
    217
    +    (let ((lisp::*min-list-length-for-hashtable* 1))
    
    218
    +      (test))))
    
    219
    +
    
    220
    +(define-test nintersection.1
    
    221
    +    (:tag :issues)
    
    222
    +  (flet
    
    223
    +      ((test)
    
    224
    +       (let ((lst1 (list 1 1 2 3 4 a b c "A" "B" "C" "d"))
    
    225
    +             (lst2 (list 1 4 5 b c d "a" "B" "c" "D")))
    
    226
    +         (assert-equal '(c b 4 1 1)
    
    227
    +                       (nintersection lst1 lst2))
    
    228
    +         (assert-equal '(1) lst1)))
    
    229
    +    (test)
    
    230
    +    (let ((lisp::*min-list-length-for-hashtable* 1))
    
    231
    +      (test))))
    
    232
    +
    
    233
    +
    
    234
    +(define-test subsetp.hash-eq
    
    235
    +    (:tag :issues)
    
    236
    +  (let ((lisp::*min-list-length-for-hashtable* 2))
    
    237
    +    (assert-true
    
    238
    +     (subsetp '(a b c a) '(a a d d c b) :test 'eq))
    
    239
    +    (assert-true
    
    240
    +     (subsetp '(a b c a b c a b c) '(a a d d c b) :test 'eq))
    
    241
    +    (assert-false
    
    242
    +     (subsetp '(a b c a z) '(a a d d c b) :test 'eq))
    
    243
    +    (assert-false
    
    244
    +     (subsetp '(a b c a b cz) '(a a d d c b) :test 'eq))))
    
    245
    +
    
    246
    +(define-test subsetp.hash-eql
    
    247
    +    (:tag :issues)
    
    248
    +  (let ((lisp::*min-list-length-for-hashtable* 2))
    
    249
    +    (assert-true
    
    250
    +     (subsetp '(a b c a) '(a a d d c b) :test 'eql))
    
    251
    +    (assert-false
    
    252
    +     (subsetp '(a b c a z) '(a a d d c b) :test 'eql))))
    
    253
    +
    
    254
    +(define-test subsetp.hash-equal
    
    255
    +    (:tag :issues)
    
    256
    +  (let ((lisp::*min-list-length-for-hashtable* 2))
    
    257
    +    (assert-true
    
    258
    +     (subsetp '("a" "b" "c" "a") '("a" "a" "d" "d" "c" "b") :test 'equal))
    
    259
    +    (assert-false
    
    260
    +     (subsetp '("a" "b" "c" "a" "z") '("a" "a" "d" "d" "c" "b") :test 'equal))))
    
    261
    +
    
    262
    +(define-test subsetp.hash-equalp
    
    263
    +    (:tag :issues)
    
    264
    +  (let ((lisp::*min-list-length-for-hashtable* 2))
    
    265
    +    (assert-true
    
    266
    +     (subsetp '("a" "b" "C" "A") '("a" "a" "d" "d" "c" "b") :test 'equalp))
    
    267
    +    (assert-false
    
    268
    +     (subsetp '("a" "b" "C" "A" "z") '("a" "a" "d" "d" "c" "b") :test 'equalp))))
    
    269
    +
    
    270
    +(define-test subsetp.hash-eql-with-key
    
    271
    +    (:tag :issues)
    
    272
    +  (assert-true (subsetp '((1 "a") (2 "b") (3 "c"))
    
    273
    +                        '((3 "c") (3 "c") (2 "b") (1 "a"))
    
    274
    +                        :test 'eql
    
    275
    +                        :key #'first)))
    
    276
    +
    
    277
    +(define-test subsetp.test-and-test-not
    
    278
    +  (assert-error 'simple-error
    
    279
    +                (subsetp '(1 2)
    
    280
    +                         '(3 4)
    
    281
    +                         :test 'eql
    
    282
    +                         :test-not 'equal)))
    
    283
    +>>>>>>> Stashed changes