Bug? Strange set equality (r1075)

21 views
Skip to first unread message

Achim Passen

unread,
Oct 19, 2008, 3:02:23 PM10/19/08
to clo...@googlegroups.com
Hi,

user> (= #{1 4} #{2 3})
true

it's not, is it?

Kind regards,
achim


--
http://rauschabstand.twoday.net

Chouser

unread,
Oct 19, 2008, 3:35:27 PM10/19/08
to clo...@googlegroups.com
On Sun, Oct 19, 2008 at 3:02 PM, Achim Passen <achim....@gmail.com> wrote:
>
> user> (= #{1 4} #{2 3})
> true
>
> it's not, is it?

I hope not!

Patch attached.

--Chouser

fix-APersistentSet-equals.patch

Stephen C. Gilardi

unread,
Oct 19, 2008, 4:00:09 PM10/19/08
to clo...@googlegroups.com

On Oct 19, 2008, at 3:02 PM, Achim Passen wrote:

Hi,

user> (= #{1 4} #{2 3})
true

it's not, is it?

It's not. Line 62 of APersistentSet.java should be:

if (!contains(aM))

rather than

if (!m.contains(aM))

As a more general thought, we Clojure users would benefit from a test suite for the functions (and macros) shipped with the Clojure distribution. This seems like an ideal thing for members of the community to work together on--a large effort that can be done in parallel. Any work we do on it is to the good and it can grow over time to be more complete.

Is there already a wiki page for it? Anybody want to sign up for writing tests for a range of lines in boot.clj? Stuart's clojure.contrib.test-is lib should provide a good framework to get started with.

--Steve

Rich Hickey

unread,
Oct 19, 2008, 4:00:18 PM10/19/08
to Clojure


On Oct 19, 3:02 pm, Achim Passen <achim.pas...@gmail.com> wrote:
> Hi,
>
> user> (= #{1 4} #{2 3})

Fixed - thanks for the report.

Rich

J. McConnell

unread,
Oct 19, 2008, 5:11:20 PM10/19/08
to clo...@googlegroups.com
> As a more general thought, we Clojure users would benefit from a test suite
> for the functions (and macros) shipped with the Clojure distribution. This
> seems like an ideal thing for members of the community to work together
> on--a large effort that can be done in parallel. Any work we do on it is to
> the good and it can grow over time to be more complete.
>
> Is there already a wiki page for it? Anybody want to sign up for writing
> tests for a range of lines in boot.clj? Stuart's clojure.contrib.test-is lib
> should provide a good framework to get started with.

I've been thinking the same thing for awhile now and I'd love to help
contribute to an effort like this. Thanks for getting the idea out
there.

- J.

Stephen C. Gilardi

unread,
Oct 19, 2008, 6:43:44 PM10/19/08
to clo...@googlegroups.com

On Oct 19, 2008, at 5:11 PM, J. McConnell wrote:

> I've been thinking the same thing for awhile now and I'd love to help
> contribute to an effort like this. Thanks for getting the idea out
> there.

You're welcome. It seems like clojure.contrib could be a more
convenient place to keep this than the wiki.

Direct or indirect contributions to clojure.contrib require that the
contributed code be written by the contributor and that the
contributor have a contributor agreement on file with Rich. Would that
be acceptable to people interested in participating? I appreciate the
care Rich showed and long view he took in coming up with the
Contributor Agreement process. I think it would be a good idea to
leverage that process for this effort as well.

Discussion of alternative proposals for a good way to do this and
place to keep it are welcome.

I made a start on this today. I started with the Reader page at
clojure.org and started making tests. I'm thinking of a structure like
this:

Run tests with:

(require 'clojure.contrib.test-clojure)

The definition of clojure.contrib.test-clojure requires subordinate
test namespaces like

'clojure.contrib.test-clojure.Reader
'clojure.contrib.test-clojure.Evaluation
'clojure.contrib.test-clojure.Special-Forms
...

with names that correspond to pages on the Clojure web site. After
requiring the individual test namespaces, test-clojure runs
"clojure.contrib.test-is/run-tests" on each one.

Here's a sample from clojure.contrib.test-clojure.

(ns clojure.contrib.test-clojure.Reader
(:use clojure.contrib.test-is))

(deftest t-Symbols
(is (= 'abc (symbol "abc")))
(is (= '*+!-_? (symbol "*+!-_?")))
(is (= 'abc:def:ghi (symbol "abc:def:ghi")))
(is (= 'abc/def (symbol "abc" "def")))
(is (= 'abc.def/ghi (symbol "abc.def" "ghi")))
(is (= 'abc/def.ghi (symbol "abc" "def.ghi")))
(is (= 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno")))
(is (instance? clojure.lang.Symbol 'alphabet))
)

; additional tests to flesh out
(deftest t-Numbers)
(deftest t-Characters)
(deftest t-nil)
(deftest t-Booleans)
(deftest t-Keywords)
(deftest t-Lists)
(deftest t-Vectors)
(deftest t-Maps)
(deftest t-Sets)
(deftest t-Quote)
(deftest t-Character)
(deftest t-Comment)
(deftest t-Meta)
(deftest t-Deref)
(deftest t-Regex)
(deftest t-Metadata)
(deftest t-read)

and a run:

user=> (require 'clojure.contrib.test-clojure)
Testing #<Namespace: clojure.contrib.test-clojure.Reader>

Ran 18 tests with 10 assertions.
0 failures, 0 exceptions.
nil
user=>

(Currently the number of tests exceeds the number of assertions by so
much because of the placeholders.)

Tesing Clojure is a big project and will take a lot of work over time.
There many pieces and many interactions among them to test. The hope
is that having it available will allow Rich to make changes with an
even higher degree of confidence that they didn't have unintended
consequences and to support efforts like Chouser's ClojureScript to
bring Clojure to new platforms

Discussion and suggestions are welcome.

--Steve

Paul Barry

unread,
Oct 19, 2008, 8:22:11 PM10/19/08
to Clojure
I like this idea and I would be willing to contribute.

Michael Beauregard

unread,
Oct 19, 2008, 9:07:06 PM10/19/08
to clo...@googlegroups.com
Ditto. I've been thinking about this for a few weeks and would be
happy to help out where I can.

J. McConnell

unread,
Oct 20, 2008, 9:10:42 AM10/20/08
to clo...@googlegroups.com
> Direct or indirect contributions to clojure.contrib require that the
> contributed code be written by the contributor and that the
> contributor have a contributor agreement on file with Rich.

Just put mine in the mail :)

J. McConnell

unread,
Oct 21, 2008, 10:02:52 AM10/21/08
to clo...@googlegroups.com
> I made a start on this today. I started with the Reader page at
> clojure.org and started making tests.

Unless I hear that someone else has started, I guess I'll take a shot
at the Evaluation page next time I get a chance.

- J.

Stephen C. Gilardi

unread,
Oct 21, 2008, 10:15:27 AM10/21/08
to clo...@googlegroups.com
That's great, J. Thanks. I want to use the wiki to coordinate efforts. I'll be putting a page up in the next day or two. Was the example I posted enough to get you started?

You're all signed up for Evaluation.

--Steve

J. McConnell

unread,
Oct 21, 2008, 10:33:48 AM10/21/08
to clo...@googlegroups.com
> That's great, J. Thanks. I want to use the wiki to coordinate efforts. I'll
> be putting a page up in the next day or two.

Sounds good.

> Was the example I posted enough to get you started?

I think so, it made sense to me. If I'm stumped (I'm thinking of
load-file here) I'll be sure to ask questions here or on IRC.

Thanks,

- J.

Stuart Halloway

unread,
Oct 21, 2008, 10:37:26 AM10/21/08
to clo...@googlegroups.com
Since there is now a movement afoot to write a comprehensive test
suite, I want to re-post the spike I did earlier on ClojureCheck.

It would be cool to use check-style tests for at least part of the
Clojure suite. If there is interest in this, I hope to have time to
work on this in late November, or would be delighted if someone else
picks up the idea and runs with it.

Original message follows:

---------------

At the JVM summit Clojure breakout someone suggested a Haskell
QuickCheck/ScalaCheck library for Clojure. I am attaching a small
spike in that direction below. A few questions:

(1) Is anybody interested?

(2) If the answer to (1) is yes, do you like the direction I am going
in the public API, e.g.

(for-all [x Integer y Integer] (some stuff that must be true))

(3) Any suggestions about implementation detail? (E.g. I like using a
multimethod for arbitrary--is there a prettier syntax for ignoring the
argument after using it for dispatch?)

Cheers,
Stuart

;;; clojure_check.clj: quick check framework for Clojure

;; Copyright (c) 2008 Stuart Halloway. All rights reserved.

;; Inspired by Scalacheck et al (http://code.google.com/p/scalacheck/)
;; Licensed under the same CPL as Clojure (http://clojure.org)

;; Uses clojure.contrib.test-is for assertions
;;
;; Example (passing)
;; (for-all [x Integer y Integer] (= (+ x y) (+ y x)))
;;
;; Example (failing)
;; (for-all [x Integer y Integer] (= (+ x y) (- y x)))

(ns clojure-check
(:import (java.util Random))
(:use clojure.contrib.test-is))

(defmulti arbitrary identity)

(def random (Random.))

(defn collection-size []
(.nextInt random 100))
(def *check-count* 50)

(defn choose [rng]
(nth rng (.nextInt random (count rng))))

(defmethod arbitrary Integer [_] (.nextInt random))
(defmethod arbitrary Character [_] (char (.nextInt random)))
(defmethod arbitrary :ascii-character [_] (char (choose (range 32
128))))

(defmethod arbitrary String [_]
(apply str (take (collection-size) (iterate (fn[_] (arbitrary
Character)) nil))))
(defmethod arbitrary :ascii-string [_]
(apply str (take (collection-size) (iterate (fn[_] (arbitrary :ascii-
character)) nil))))

(defmacro binding-values [& vars]
`(vector ~@(map (fn [v] `['~v ~v]) vars)))

(defmacro for-all [args & forms]
(let [vars (take-nth 2 args)
value-generators (map (fn [x] `(arbitrary ~x))(take-nth 2 (rest
args)))]
`(do
~@(map (fn [f]
`(dotimes i# *check-count*
(let ~(apply vector (interleave vars value-generators))
(is (true? ~f) (pr-str (binding-values ~@vars))))))
forms))))


J. McConnell

unread,
Oct 22, 2008, 8:22:54 AM10/22/08
to clo...@googlegroups.com
> Run tests with:
>
> (require 'clojure.contrib.test-clojure)

I don't see clojure.contrib.test-clojure. Are you going to be committing that?

Thanks,

- J.

mb

unread,
Oct 22, 2008, 8:40:58 AM10/22/08
to Clojure
Hello Stuart,

On 21 Okt., 16:37, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> Since there is now a movement afoot to write a comprehensive test  
> suite, I want to re-post the spike I did earlier on ClojureCheck.
>
> It would be cool to use check-style tests for at least part of the  
> Clojure suite. If there is interest in this, I hope to have time to  
> work on this in late November, or would be delighted if someone else  
> picks up the idea and runs with it.

I am working on a TAP implementation[1] for Clojure. For this I
would really like to have a ClojureCheck (as there is LectroTest
for Perl). And as stated in the original ClojureCheck thread
I will work on this.

Unfortunately, (not= de.kotka.tap clojure/test clojure.contrib.test-
is)
but I think the basic machinery like arbitrary definition etc. can
be reused. I will hopefully soon post a first draft of the
implementation.

Sincerely
Meikel

[1]: http://kotka.de/projects/clojure/tap.html (Not up-to-date, though)

Stephen C. Gilardi

unread,
Oct 22, 2008, 4:36:34 PM10/22/08
to clo...@googlegroups.com
It's up now. Once your CA is in to Rich, I'll be happy to accept patches to extend its nascent testing reach:

user=> (require 'clojure.contrib.test-clojure :reload-all)
Testing #<Namespace: clojure.contrib.test-clojure.Reader>

Ran 22 tests with 10 assertions.
0 failures, 0 exceptions.
nil
user=>

Thanks,

--Steve

Frantisek Sodomka

unread,
Nov 10, 2008, 4:37:56 PM11/10/08
to clo...@googlegroups.com
Hello, I would like to contribute to testing Clojure. (Rich has my CA
already.)
I have been thinking about it and going through some unit tests for
different language. I am proposing this syntax change to macro 'is':

Instead of writing:

(deftest test-+
(is (= (+) 0))
(is (= (+ 1) 1))
(is (= (+ 1 2) 3))
(is (= (+ 1 2 3) 6))
(is (number? (+ 1 2)))
(is (integer? (+ 1 2)))
(throws ClassCastException (+ "abc" 2)))

1) Take multiple expressions instead of just one

(deftest test-+
(is
(= (+) 0)
(= (+ 1) 1)
(= (+ 1 2) 3)
(= (+ 1 2 3) 6)
(number? (+ 1 2))
(integer? (+ 1 2)))
(throws ClassCastException (+ "abc" 2)))

2) Abstract equality tests (the most common tests):

(deftest test-+
(is
(:equal
(+) 0
(+ 1) 1
(+ 1 2) 3
(+ 1 2 3) 6 )
(number? (+ 1 2))
(integer? (+ 1 2)))
(throws ClassCastException (+ "abc" 2)))

I believe that this syntax change would make writing tests easier and less
tedious. Also, personally, I would prefer the name 'check' instead of
'is', but that's just me :-)

Greetings, Frantisek



On Mon, 20 Oct 2008 00:43:44 +0200, Stephen C. Gilardi <sque...@mac.com>
wrote:

Frantisek Sodomka

unread,
Nov 13, 2008, 9:30:58 AM11/13/08
to clo...@googlegroups.com
Using this, test t-Symbols

(deftest t-Symbols
(is (= 'abc (symbol "abc")))
(is (= '*+!-_? (symbol "*+!-_?")))
(is (= 'abc:def:ghi (symbol "abc:def:ghi")))
(is (= 'abc/def (symbol "abc" "def")))
(is (= 'abc.def/ghi (symbol "abc.def" "ghi")))
(is (= 'abc/def.ghi (symbol "abc" "def.ghi")))
(is (= 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno")))
(is (instance? clojure.lang.Symbol 'alphabet))
)

becomes:

(deftest t-Symbols
(check
(:equal
'abc (symbol "abc")
'*+!-_? (symbol "*+!-_?")


'abc:def:ghi (symbol "abc:def:ghi")

'abc/def (symbol "abc" "def")
'abc.def/ghi (symbol "abc.def" "ghi")
'abc/def.ghi (symbol "abc" "def.ghi")


'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno")
)

(instance? clojure.lang.Symbol 'alphabet)))

which is in my opinion much more readable. Any comments to this syntactic
enhancement?

Thank you, Frantisek

Dave Newton

unread,
Nov 13, 2008, 10:35:52 AM11/13/08
to clo...@googlegroups.com
--- On Thu, 11/13/08, Frantisek Sodomka wrote:
> [...]

> becomes:
>
> (deftest t-Symbols
> (check
> (:equal
> 'abc (symbol "abc")
> '*+!-_? (symbol "*+!-_?")
> 'abc:def:ghi (symbol "abc:def:ghi")
> 'abc/def (symbol "abc" "def")
> 'abc.def/ghi (symbol "abc.def" "ghi")
> 'abc/def.ghi (symbol "abc" "def.ghi")
> 'abc:def/ghi:jkl.mno (symbol "abc:def" "ghi:jkl.mno")
> )
> (instance? clojure.lang.Symbol 'alphabet)))
>
> which is in my opinion much more readable. Any comments to
> this syntactic enhancement?

My first impression when I read that is that it's expecting each arg to be equal to each other, not the reality of being a list of (expected to be) equal pairs.

That's probably just me, I'm sure, but I find the original more readable and precise--something I think is key in tests, as tests are also documentation.

Dave

Frantisek Sodomka

unread,
Nov 13, 2008, 10:59:06 AM11/13/08
to clo...@googlegroups.com
On Thu, 13 Nov 2008 16:35:52 +0100, Dave Newton <newto...@yahoo.com>
wrote:

Yes, I am just trying to save on typing... ;-)

:equal could be also :equal-pairs. It introduces new (and maybe strange)
syntax...

Anyway, accepting multiple expressions would be nice.

Frantisek

Reply all
Reply to author
Forward
0 new messages