Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pnathan/generic-comparability
Browse files Browse the repository at this point in the history
  • Loading branch information
pnathan committed May 2, 2015
2 parents 82afaff + 25296ec commit 9ad75d4
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 12 deletions.
45 changes: 45 additions & 0 deletions generic-comparability-test.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,51 @@
'<)
"asd ASDf case-sensitive nil"))

(test comparability
(test lt-compare
(is (lt 0 100))
(is (not (lt 20 20)))
(is (not (lt 40 0))))

(test lte-compare
(is (lte 0 200))
(is (lte 200 200))
(is (not (lte 50 -3))))

(test gt-compare
(is (gt 200 0))
(is (not (gt -800 -800)))
(is (not (gt -800 0))))

(test gte-compare
(is (gte 100 0))
(is (gte 200 200))
(is (not (gte 0 300)))))

;; example from the spec.
(defstruct foo a s d)

(test incomparable
(signals incomparable-object
(lte (make-array 3 :initial-element 0)
(vector 1 2 42)))
(signals incomparable-object
(lte (make-foo :a 0 :d "I am a FOO")
(make-foo :a 42 :d "I am a foo"))))

(test verify-generic-hash-code
(is (eql (hash-code 10)
(hash-code 10)))

(is (not (eql (hash-code "One Thing")
(hash-code "1d10t"))))

(is (not (eql (hash-code 0)
(hash-code "String"))))

(is (eql (hash-code "A string")
(hash-code "A string"))))

(defun run-tests ()
(let ((results (run 'test-set)))
(explain! results)
Expand Down
25 changes: 13 additions & 12 deletions generic-comparability.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -303,32 +303,33 @@ the relevant information about its recursive dependent behavior. "))

(let ((underlying #'(lambda (a b &rest keys)
(apply #'compare a b keys)) ))

(defmethod lt (a b &rest keys)
(case (apply underlying a b keys)
(:< t)
(:> nil)
(:= nil)
(< t)
(> nil)
(= nil)
(t
(incomparable-object a b))))
(defmethod lte (a b &rest keys)
(case (apply underlying a b keys)
(:< t)
(:> nil)
(:= t)
(< t)
(> nil)
(= t)
(t
(incomparable-object a b))))
(defmethod gt (a b &rest keys)
(case (apply underlying a b keys)
(:< nil)
(:> t)
(:= nil)
(< nil)
(> t)
(= nil)
(t
(incomparable-object a b))))
(defmethod gte (a b &rest keys)
(case (apply underlying a b keys)
(:< nil)
(:> t)
(:= t)
(< nil)
(> t)
(= t)
(t
(incomparable-object a b)))))

Expand Down

0 comments on commit 9ad75d4

Please sign in to comment.