equal.lsp 2.98 KB
Newer Older
pfdietz's avatar
pfdietz committed
1 2 3 4 5 6 7 8 9
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Thu Oct 17 21:38:16 2002
;;;; Contains: Tests for EQUAL

(in-package :cl-test)

(deftest equal.1
  (loop for x in *symbols*
sds's avatar
sds committed
10 11 12
        always (loop for y in *symbols*
                     always (if (eq x y) (equal x y)
                              (not (equal x y)))))
pfdietz's avatar
pfdietz committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
  t)

(deftest equal.2
  (equalt (cons 'a 'b) (cons 'a 'b))
  t)

(deftest equal.3
  (equalt (cons 'a 'c) (cons 'a 'b))
  nil)

(deftest equal.4
  (equalt (vector 1 2 3) (vector 1 2 3))
  nil)

(deftest equal.5
  (loop for c in *characters*
sds's avatar
sds committed
29 30 31
        always (loop for d in *characters*
                     always (if (eql c d) (equalt c d)
                              (not (equalt c d)))))
pfdietz's avatar
pfdietz committed
32 33 34 35
  t)

(deftest equal.6
  (equalt (make-pathname :name (copy-seq "foo"))
sds's avatar
sds committed
36
          (make-pathname :name (copy-seq "foo")))
pfdietz's avatar
pfdietz committed
37 38 39 40
  t)

(deftest equal.7
  (equalt (make-pathname :name (copy-seq "foo"))
sds's avatar
sds committed
41
          (make-pathname :name (copy-seq "bar")))
pfdietz's avatar
pfdietz committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
  nil)

(deftest equal.8
  (equalt (copy-seq "abcd") (copy-seq "abcd"))
  t)

(deftest equal.9
  (equalt (copy-seq "abcd") (copy-seq "abc"))
  nil)

(deftest equal.10
  (equalt (copy-seq "abcd") (copy-seq "ABCD"))
  nil)

(deftest equal.11
  (equalt (copy-seq #*000110) (copy-seq #*000110))
  t)

(deftest equal.12
  (equalt (copy-seq #*000110) (copy-seq #*000111))
  nil)

64
(deftest equal.13
65
  :notes (:nil-vectors-are-strings)
66
  (let ((x (make-array '(0) :element-type nil))
sds's avatar
sds committed
67
        (y (make-array '(0) :element-type nil)))
68 69 70 71
    (equalt x y))
  t)

(deftest equal.14
72
  :notes (:nil-vectors-are-strings)
73 74 75 76 77
  (and
   (equalt (make-array '(0) :element-type nil) "")
   (equalt "" (make-array '(0) :element-type nil)))
  t)

78 79
(deftest equal.15
  (equalt (make-array '(0) :element-type 'character)
sds's avatar
sds committed
80
          (make-array '(0) :element-type 'base-char))
81 82 83 84
  t)

(deftest equal.16
  (equalt "abc" (make-array '(3) :element-type 'base-char
sds's avatar
sds committed
85
                            :initial-contents '(#\a #\b #\c)))
86 87 88 89
  t)

(deftest equal.17
  (let ((s (make-array '(10) :element-type 'character
sds's avatar
sds committed
90 91
                       :initial-contents "0123456789"
                       :fill-pointer 3)))
92 93 94 95 96
    (values (equalt s "012") (equalt "012" s)))
  t t)

(deftest equal.18
  (let ((b (make-array '(10) :element-type 'bit
sds's avatar
sds committed
97 98
                       :initial-contents #*0110001110
                       :fill-pointer 5)))
99 100 101 102 103
    (values (equalt #*01100 b) (equalt #*01100 b)))
  t t)

(deftest equal.19
  (let ((s (make-array '(10) :element-type 'base-char
sds's avatar
sds committed
104 105
                       :initial-contents "0123456789"
                       :fill-pointer 3)))
106 107 108 109 110
    (values (equalt s "012") (equalt "012" s)))
  t t)

;;; Should add more pathname equality tests

111
(deftest equal.order.1
112 113 114 115 116 117
  (let ((i 0) x y)
    (values
     (equal (setf x (incf i)) (setf y (incf i)))
     i x y))
  nil 2 1 2)

118 119
;;; Error tests

120
(deftest equal.error.1
121 122
  (signals-error (equal) program-error)
  t)
pfdietz's avatar
pfdietz committed
123

124
(deftest equal.error.2
125 126
  (signals-error (equal nil) program-error)
  t)
pfdietz's avatar
pfdietz committed
127

128
(deftest equal.error.3
129 130
  (signals-error (equal nil nil nil) program-error)
  t)