Commit 6941b729 authored by pfdietz's avatar pfdietz

Fix up random string generator to produce specialized strings (adjustable,...

Fix up random string generator to produce specialized strings (adjustable, fill pointer, base-char, displaced)
parent d597afc5
......@@ -88,30 +88,40 @@
(defun make-random-string (n)
(let*
((use-random-byte nil)
(etype 'character)
(s (random-case
(progn
(setf use-random-byte *use-random-byte*)
(make-string n))
(progn
(setf use-random-byte *use-random-byte*)
(make-array n :element-type 'character
(make-array n :element-type 'character
:initial-element #\a))
(make-array n :element-type (if *random-readable* 'character
'standard-char)
(make-array n :element-type (setf etype (if *random-readable* 'character 'standard-char))
:adjustable (and (not *random-readable*) (rcase (3 nil) (1 t)))
:fill-pointer (and (not *random-readable*) (rcase (3 nil) (1 (random (1+ n)))))
:initial-element #\a)
(make-array n :element-type (if *random-readable* 'character
'base-char)
(make-array n :element-type (setf etype (if *random-readable* 'character 'base-char))
:adjustable (and (not *random-readable*) (rcase (3 nil) (1 t)))
:fill-pointer (and (not *random-readable*) (rcase (3 nil) (1 (random (1+ n)))))
:initial-element #\a))))
(if (coin)
(dotimes (i n)
(setf (char s i) (elt #(#\a #\b #\A #\B) (random 4))))
(dotimes (i n)
(dotimes (i n)
(setf (char s i)
(or (and use-random-byte (or (code-char (random (min char-code-limit (ash 1 16))))
(code-char (random 256))))
(elt "abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
(random 62)))))))
(setf (char s i)
(or (and use-random-byte (or (code-char (random (min char-code-limit (ash 1 16))))
(code-char (random 256))))
(elt "abcdefghijklmnopqrstuvwyxzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
(random 62))))))
(when (and (not *random-readable*) (coin 5))
(let* ((len (length s))
(len2 (random (1+ len))))
(setf s (make-array len2
:element-type etype
:displaced-to s
:displaced-index-offset (random (1+ (- len len2)))))))
s))
(defun random-leaf ()
......
......@@ -69,9 +69,14 @@
(defun make-random-string-compare-test (n)
(let* ((len (random n))
;; Lengths of the two strings
;; Maximum lengths of the two strings
(len1 (if (or (coin) (= len 0)) len (+ len (random len))))
(len2 (if (or (coin) (= len 0)) len (+ len (random len))))
(s1 (make-random-string len1))
(s2 (make-random-string len2))
;; Actual lengths of the strings
(len1 (length s1))
(len2 (length s2))
;; Lengths of the parts of the strings to be matched
(sublen1 (if (or (coin) (= len1 0)) (min len1 len2) (random len1)))
(sublen2 (if (or (coin) (= len2 0)) (min len2 sublen1) (random len2)))
......@@ -83,9 +88,7 @@
(start2 (if (coin 3) 0
(max 0 (min (1- len2) (random (- len2 sublen2 -1))))))
(end2 (+ start2 sublen2))
;; generate the strings
(s1 (make-random-string len1))
(s2 (make-random-string len2)))
)
#|
(format t "len = ~A, len1 = ~A, len2 = ~A, sublen1 = ~A, sublen2 = ~A~%"
len len1 len2 sublen1 sublen2)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment