search-bitvector.lsp 6.14 KB
Newer Older
1 2 3
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sun Aug 25 13:06:54 2002
4
;;;; Contains: Tests for SEARCH on bit vectors
5 6 7

(in-package :cl-test)

8

9

10 11
(deftest search-bitvector.1
  (let ((target *searched-bitvector*)
sds's avatar
sds committed
12
        (pat #*0))
13
    (loop for i from 0 to (1- (length target))
sds's avatar
sds committed
14 15 16 17
          for tail = (subseq target i)
          always
          (let ((pos (search pat tail)))
            (search-check pat tail pos))))
18 19 20 21
  t)

(deftest search-bitvector.2
  (let ((target *searched-bitvector*)
sds's avatar
sds committed
22
        (pat #*0))
23
    (loop for i from 1 to (length target)
sds's avatar
sds committed
24 25 26
          always
          (let ((pos (search pat target :end2 i :from-end t)))
            (search-check pat target pos :end2 i :from-end t))))
27 28 29 30 31
  t)

(deftest search-bitvector.3
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
32 33 34
          for pos = (search pat target)
          unless (search-check pat target pos)
          collect pat))
35 36 37 38 39
  nil)

(deftest search-bitvector.4
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
40 41 42
          for pos = (search pat target :from-end t)
          unless (search-check pat target pos :from-end t)
          collect pat))
43 44 45 46 47
  nil)

(deftest search-bitvector.5
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
48 49 50
          for pos = (search pat target :start2 25 :end2 75)
          unless (search-check pat target pos :start2 25 :end2 75)
          collect pat))
51 52 53 54 55
  nil)

(deftest search-bitvector.6
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
56 57 58 59
          for pos = (search pat target :from-end t :start2 25 :end2 75)
          unless (search-check pat target pos :from-end t
                               :start2 25 :end2 75)
          collect pat))
60 61 62 63 64
  nil)

(deftest search-bitvector.7
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
65 66 67
          for pos = (search pat target :start2 20)
          unless (search-check pat target pos :start2 20)
          collect pat))
68 69 70 71 72
  nil)

(deftest search-bitvector.8
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
73 74 75 76
          for pos = (search pat target :from-end t :start2 20)
          unless (search-check pat target pos :from-end t
                               :start2 20)
          collect pat))
77 78 79 80 81
  nil)

(deftest search-bitvector.9
  (let ((target *searched-bitvector*))
    (loop for pat in (mapcar #'(lambda (x)
sds's avatar
sds committed
82 83 84 85 86 87 88 89
                                 (map 'vector
                                      #'(lambda (y)
                                          (sublis '((a . 2) (b . 3)) y))
                                      x))
                             *pattern-sublists*)
          for pos = (search pat target :start2 20 :key #'evenp)
          unless (search-check pat target pos :start2 20 :key #'evenp)
          collect pat))
90 91 92 93 94
  nil)

(deftest search-bitvector.10
  (let ((target *searched-bitvector*))
    (loop for pat in (mapcar #'(lambda (x)
sds's avatar
sds committed
95 96 97 98 99 100 101 102 103
                                 (map 'vector
                                      #'(lambda (y)
                                          (sublis '((a . 2) (b . 3)) y))
                                      x))
                             *pattern-sublists*)
          for pos = (search pat target :from-end t :start2 20 :key 'oddp)
          unless (search-check pat target pos :from-end t
                               :start2 20 :key 'oddp)
          collect pat))
104 105 106 107 108
  nil)

(deftest search-bitvector.11
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
109 110 111 112
          for pos = (search pat target :start2 20 :test (complement #'eql))
          unless (search-check pat target pos :start2 20
                               :test (complement #'eql))
          collect pat))
113 114 115 116 117
  nil)

(deftest search-bitvector.12
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
118 119 120 121
          for pos = (search pat target :from-end t :start2 20 :test-not #'eql)
          unless (search-check pat target pos :from-end t
                               :start2 20 :test (complement #'eql))
          collect pat))
122 123 124 125 126
  nil)

(deftest search-bitvector.13
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
127 128 129 130 131 132 133
          when (and (> (length pat) 0)
                    (let ((pos (search pat target :start1 1
                                       :test (complement #'eql))))
                      (not (search-check pat target pos
                                         :start1 1
                                         :test (complement #'eql)))))
          collect pat))
134 135 136 137 138
  nil)

(deftest search-bitvector.14
  (let ((target *searched-bitvector*))
    (loop for pat in *pattern-subbitvectors*
sds's avatar
sds committed
139 140 141 142 143 144 145 146
          when (let ((len (length pat)))
                 (and (> len 0)
                      (let ((pos (search pat target :end1 (1- len)
                                         :test (complement #'eql))))
                      (not (search-check pat target pos
                                         :end1 (1- len)
                                         :test (complement #'eql))))))
          collect pat))
147
  nil)
148 149 150

(deftest search-bitvector.15
  (let ((a (make-array '(10) :initial-contents '(0 1 1 0 0 0 1 0 1 1)
sds's avatar
sds committed
151 152
                       :fill-pointer 5
                       :element-type 'bit)))
153 154 155 156 157 158 159 160 161 162 163
    (values
     (search #*0 a)
     (search #*0 a :from-end t)
     (search #*01 a)
     (search #*01 a :from-end t)
     (search #*010 a)
     (search #*010 a :from-end t)))
  0 4 0 0 nil nil)

(deftest search-bitvector.16
  (let ((pat (make-array '(3) :initial-contents '(0 1 0)
sds's avatar
sds committed
164 165
                         :fill-pointer 1))
        (a #*01100))
166 167 168 169 170 171 172 173 174 175 176 177 178
    (values
     (search pat a)
     (search pat a :from-end t)
     (progn
       (setf (fill-pointer pat) 2)
       (search pat a))
     (search pat a :from-end t)
     (progn
       (setf (fill-pointer pat) 3)
       (search pat a))
     (search pat a :from-end t)))
  0 4 0 0 nil nil)

179 180 181 182
;; Order of test, test-not

(deftest search-bitvector.17
  (let ((pat #*10)
sds's avatar
sds committed
183
        (target #*000011))
184 185 186 187 188
    (search pat target :test #'<=))
  4)

(deftest search-bitvector.18
  (let ((pat #*10)
sds's avatar
sds committed
189
        (target #*000011))
190 191 192
    (search pat target :test-not #'>))
  4)