Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added sequence tests #27

Merged
merged 11 commits into from
Aug 3, 2018
84 changes: 84 additions & 0 deletions auxiliary/eus-predicates.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
; (in-package "COMMON_LISP")
; (export '(char-equal equalp))

(defun char-equal (character &rest more-characters)
"Returns T if all of its arguments are the same character.
Case is ignored."
(do ((clist more-characters (cdr clist)))
((atom clist) T)
(unless (= (car clist) character)
(return nil))))


;;; EQUALP -- public.
;;
(defun equalp (x y)
"Just like EQUAL, but more liberal in several respects.
Numbers may be of different types, as long as the values are identical
after coercion. Characters may differ in alphabetic case. Vectors and
arrays must have identical dimensions and EQUALP elements, but may differ
in their type restriction."
(cond ((eq x y) t)
((characterp x) (and (characterp y) (char-equal x y)))
((numberp x) (and (numberp y) (= x y)))
((consp x)
(and (consp y)
(equalp (car x) (car y))
(equalp (cdr x) (cdr y))))
((pathnamep x)
;; (and (pathnamep y) (pathname= x y)))
(error "pathname is not yet supported here. Sorry."))
((hash-table-p x)
(error "hash table is not yet supported here. Sorry."))
;; (and (hash-table-p y)
;; (eql (hash-table-count x) (hash-table-count y))
;; (eql (hash-table-test x) (hash-table-test y))
;; (with-hash-table-iterator (next x)
;; (loop
;; (multiple-value-bind (more x-key x-value)
;; (next)
;; (cond (more
;; (multiple-value-bind (y-value foundp)
;; (gethash x-key y)
;; (unless (and foundp (equalp x-value y-value))
;; (return nil))))
;; (t
;; (return t))))))))
;; ((%instancep x)
;; (let* ((layout-x (%instance-layout x))
;; (len (layout-length layout-x)))
;; (and (%instancep y)
;; (eq layout-x (%instance-layout y))
;; (structure-class-p (layout-class layout-x))
;; (do ((i 1 (1+ i)))
;; ((= i len) t)
;; (declare (fixnum i))
;; (let ((x-el (%instance-ref x i))
;; (y-el (%instance-ref y i)))
;; (unless (or (eq x-el y-el)
;; (equalp x-el y-el))
;; (return nil)))))))
((vectorp x)
(let ((length (length x)))
(and (vectorp y)
(= length (length y))
(dotimes (i length t)
(let ((x-el (aref x i))
(y-el (aref y i)))
(unless (or (eq x-el y-el)
(equalp x-el y-el))
(return nil)))))))
((arrayp x)
(and (arrayp y)
(= (array-rank x) (array-rank y))
(dotimes (axis (array-rank x) t)
(unless (= (array-dimension x axis)
(array-dimension y axis))
(return nil)))
(dotimes (index (array-total-size x) t)
(let ((x-el (row-major-aref x index))
(y-el (row-major-aref y index)))
(unless (or (eq x-el y-el)
(equalp x-el y-el))
(return nil))))))
(t nil)))
133 changes: 133 additions & 0 deletions auxiliary/eus-sequences.l
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
;; Shadows a few substitute functions
;; - substitute should accept a from-end keyword
;; - count = nil should default to count = 10^6 (due to hacky reasons)

(in-package :lisp)


(defun substitute (newitem olditem seq &key (start 0)
(end (length seq))
(test #'eq)
(test-not nil)
(count 1000000)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-substitute newitem olditem (reverse seq) test test-not key nil nil start end count))
(system::raw-substitute newitem olditem seq test test-not key nil nil start end count))))

(defun substitute-if (newitem pred seq &key (start 0)
(end (length seq))
(count 1000000)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-substitute newitem nil (reverse seq) nil nil key pred nil start end count))
(system::raw-substitute newitem nil seq nil nil key pred nil start end count))))

(defun substitute-if-not (newitem pred seq &key (start 0)
(end (length seq))
(count 1000000)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-substitute newitem nil (reverse seq) nil nil key nil pred start end count))
(system::raw-substitute newitem nil seq nil nil key nil pred start end count))))


(defun nsubstitute (newitem olditem seq &key (start 0)
(end (length seq))
(test #'eq)
(test-not nil)
(count 1000000)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-nsubstitute newitem olditem (reverse seq) test test-not key nil nil start end count))
(system::raw-nsubstitute newitem olditem seq test test-not key nil nil start end count))))

(defun nsubstitute-if (newitem pred seq &key (start 0)
(end (length seq))
(nil)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-nsubstitute newitem nil (reverse seq) nil nil key pred nil start end count))
(system::raw-nsubstitute newitem nil seq nil nil key pred nil start end count))))

(defun nsubstitute-if-not (newitem pred seq &key (start 0)
(end (length seq))
(count 1000000)
(key #'identity)
(from-end nil))
(let ((count (or (and count (< 0 count) 0) count 1000000)))
(if from-end
(reverse (system::raw-nsubstitute newitem nil (reverse seq) nil nil key nil pred start end count))
(system::raw-nsubstitute newitem nil seq nil nil key nil pred start end count))))

;; ;; Shadows replace function
;; ;; - replace should default nil to entire string

(defun replace (dest src &key (start1 0) (end1 nil)
(start2 0) (end2 nil))
(let ((end1 (or end1 (length dest)))
(end2 (or end2 (length src))))
(let ((result dest) (count (min (- end1 start1) (- end2 start2))))
(cond ((listp dest)
(setq dest (nthcdr start1 dest))
(cond ((listp src)
(setq src (nthcdr start2 src))
(dotimes (c count)
(setq (dest . car) (pop src))
(pop dest)))
(t
(dotimes (c count)
(setq (dest . car) (aref src start2))
(inc start2) (pop dest)))))
((listp src) ; list --> vector
(setq src (nthcdr start2 src))
(dotimes (c count)
(aset dest start1 (pop src))
(inc start1)))
(t (system::vector-replace dest src start1 end1 start2 end2)))
result)))


;; Add mismatch function

(defun mismatch (seq1 seq2 &key (from-end nil)
(test #'eql)
(start1 0)
(start2 0)
(end1 nil)
(end2 nil))
(let ((end1 (or end1 (length seq1)))
(end2 (or end2 (length seq2)))
(seq1 (or (and from-end (reverse seq1)) seq1))
(seq2 (or (and from-end (reverse seq2)) seq2)))
(progn
(loop
for index1 from start1 to (- end1 1)
for index2 from start2 to (- end2 1)
do
(when (not (funcall test (elt seq1 index1) (elt seq2 index2)))
(return-from mismatch index1))
)
(if (> (- end1 start1) (- end2 start2))
end1
nil))))


;; Shadows peek-char to accept peek-type, and ignore it for now
(defun peek-char (&optional (peek-type nil) (stream *standard-input*)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It shouldn't work.. I've accidentally pushed the wrong update, but will push the correct one as soon as I can (I'm without my computer right now)..

(eof-errorp t) eof-value recursive-p)
(if (streamp peek-type)
(peek-char peek-type stream eof-errorp)
(peek-char stream eof-errorp eof-value)))

(export 'mismatch)
50 changes: 25 additions & 25 deletions auxiliary/search-aux.lsp
Original file line number Diff line number Diff line change
Expand Up @@ -10,42 +10,42 @@
a b a b b a b a a b a a a b b a a b a a a a b b a b a b a a a b a b
b a b a a b b b b b a a a a a b a b b b b b a b a b b a b a b))

(defparameter *pattern-sublists*
(remove-duplicates
(let* ((s *searched-list*) (len (length s)))
(loop for x from 0 to 8 nconc
(loop for y from 0 to (- len x)
collect (subseq s y (+ y x)))))
:test #'equal))
;; (defparameter *pattern-sublists*
;; (remove-duplicates
;; (let* ((s *searched-list*) (len (length s)))
;; (loop for x from 0 to 8 nconc
;; (loop for y from 0 to (- len x)
;; collect (subseq s y (+ y x)))))
;; :test #'equal))

(defparameter *searched-vector*
(make-array (length *searched-list*)
:initial-contents *searched-list*))

(defparameter *pattern-subvectors*
(mapcar #'(lambda (x) (apply #'vector x)) *pattern-sublists*))
;; (defparameter *pattern-subvectors*
;; (mapcar #'(lambda (x) (apply #'vector x)) *pattern-sublists*))

(defparameter *searched-bitvector*
#*1101111111010111010111000010010000001011010010001100100001101010001011010011111000001011111010110101)
;; (defparameter *searched-bitvector*
;; #*1101111111010111010111000010010000001011010010001100100001101010001011010011111000001011111010110101)

(defparameter *pattern-subbitvectors*
(remove-duplicates
(let* ((s *searched-bitvector*) (len (length s)))
(loop for x from 0 to 8 nconc
(loop for y from 0 to (- len x)
collect (subseq s y (+ y x)))))
:test #'equalp))
;; (defparameter *pattern-subbitvectors*
;; (remove-duplicates
;; (let* ((s *searched-bitvector*) (len (length s)))
;; (loop for x from 0 to 8 nconc
;; (loop for y from 0 to (- len x)
;; collect (subseq s y (+ y x)))))
;; :test #'equalp))

(defparameter *searched-string*
"1101111111010111010111000010010000001011010010001100100001101010001011010011111000001011111010110101")

(defparameter *pattern-substrings*
(remove-duplicates
(let* ((s *searched-string*) (len (length s)))
(loop for x from 0 to 8 nconc
(loop for y from 0 to (- len x)
collect (subseq s y (+ y x)))))
:test #'equalp))
;; (defparameter *pattern-substrings*
;; (remove-duplicates
;; (let* ((s *searched-string*) (len (length s)))
;; (loop for x from 0 to 8 nconc
;; (loop for y from 0 to (- len x)
;; collect (subseq s y (+ y x)))))
;; :test #'equalp))

(defun subseq-equalp (seq1 seq2 start1 start2 len &key (test #'equalp))
(assert
Expand Down
4 changes: 3 additions & 1 deletion eus-test.l
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
;; LOAD CL-compatibility libraries
(load "auxiliary/eus-multiple-values.l")
(load "auxiliary/eus-loop.l")
(load "auxiliary/eus-predicates.l")
(load "auxiliary/eus-sequences.l")

(defvar *signals-error* t)

Expand Down Expand Up @@ -174,8 +176,8 @@
;; (load "packages/load.lsp")
;; (load "printer/load.lsp")
(load "reader/load.lsp")
;; (load "sequences/load.lsp")
(load "streams/load.lsp")
(load "sequences/load.lsp")
(load "system-construction/load.lsp")
(load "structures/load.lsp")
;; (load "types-and-classes/load.lsp")
Expand Down
48 changes: 35 additions & 13 deletions reports/README.org
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,25 @@
- define-method-combination
- deftype

** 6 Sequence
*** Caveats
- (map 'list #'identity a), where a is a sequence, does not work
- Undefined functions:
- complement
- characterp
- stable-sort
- do-special-integer-vectors
- map-into
- constantly
- simple-vector-p
- check-type-error
- type-of
- Non-complyinh functions
- no such keyword :from-end in (position-if-not
- integer expected in (position-if-not #'oddp #(1 3 1 4 3 2 1 8 9) :end nil)
- No such keyword :from-end in find
- No such keyword :from-end in count-if-not
- No such keyword :key in (reduce #'+ '(1 2 3) :key '1+)
** DONE 6 Misc
*** Caveats
- "no such package":
Expand Down Expand Up @@ -245,17 +264,20 @@
* Results


| Tests-version | Test-num | Passed | Failure |
|-----------------------+----------+--------+---------|
| 1 | 5557 | 2983 | 2574 |
|-----------------------+----------+--------+---------|
| 2 - Add Arrays tests | 6297 | 3087 | 3210 |
|-----------------------+----------+--------+---------|
| 3 | 7676 | 3489 | 4187 |
|-----------------------+----------+--------+---------|
| 4 - Add misc tests | 8187 | 3506 | 4681 |
|-----------------------+----------+--------+---------|
| 5 - Add numbers tests | 9582 | 3988 | 5594 |
|-----------------------+----------+--------+---------|
| | | | |
| Tests-version | Test-num | Passed | Failure |
|-------------------------+----------+--------+---------|
| 1 | 5557 | 2983 | 2574 |
|-------------------------+----------+--------+---------|
| 2 - Add Arrays tests | 6297 | 3087 | 3210 |
|-------------------------+----------+--------+---------|
| 3 | 7676 | 3489 | 4187 |
|-------------------------+----------+--------+---------|
| 4 - Add misc tests | 8187 | 3506 | 4681 |
|-------------------------+----------+--------+---------|
| 5 - Add numbers tests | 9582 | 3988 | 5594 |
|-------------------------+----------+--------+---------|
| 6 - Add sequences tests | 11249 | 4659 | 6590 |
|-------------------------+----------+--------+---------|
| | | | |


Loading