Hi,
I was trying to build clojure with ibm versions of java and noticed that 
the following tests fail.

To debug i wrote the following program:
import java.math.BigInteger;

public class testHash {
   public static void main(String[] args) {
      BigInteger i = new BigInteger("1");
      BigInteger j = new BigInteger("9223372039002259457");
      //String j = new String("9223372039002259457N");
      //String j = new String("9223372039002259457N");
      System.out.println(i.hashCode());
      System.out.println(j.hashCode());
   }
}

which has the output:
1
33


The hashCode() method in Java only promises to report the same hash value 
for the same object, and to report the same value for two objects which 
equals() says are equal. It does not make any promise about the value 
itself, or about consistency with alternative JVM implementations.
Reference: 
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/Object.html#hashCode%28%29

So I kind of see the following as a wrong test.  Let me know if i'm wrong.



The failing tests:
https://github.com/clojure/clojure/blob/master/test/clojure/test_clojure/control.clj

(testing "test correct behavior on hash collision"
;; case uses Java .hashCode to put values into hash buckets.
(is (== (.hashCode 1) (.hashCode 9223372039002259457N)))
(are [result input] (= result (case input
1 :long
9223372039002259457N :big
:else))
:long 1
:big 9223372039002259457N
:else 4294967296
:else 2)
(are [result input] (= result (case input
9223372039002259457N :big
1 :long
:else))
:long 1
:big 9223372039002259457N
:else 4294967296
:else 2)
(are [result input] (= result (case input
0 :zero
-1 :neg1
2 :two
:oops :OOPS))
:zero 0
:neg1 -1
:two 2
:OOPS :oops)
(are [result input] (= result (case input
1204766517646190306 :a
1 :b
-2 :c
:d))
:a 1204766517646190306
:b 1
:c -2
:d 4294967296
:d 3))
(testing "test warn for hash collision"
(should-print-err-message
#"Performance warning, .*:\d+ - hash collision of some case test constants; 
if selected, those entries will be tested sequentially..*\r?\n"
(case 1 1 :long 9223372039002259457N :big 2)))
(testing "test constants are *not* evaluated"
(let [test-fn
;; never write code like this...
#(case %
(throw (RuntimeException. "boom")) :piece-of-throw-expr
:no-match)]
(are [result input] (= result (test-fn input))
:piece-of-throw-expr 'throw
:piece-of-throw-expr '[RuntimeException. "boom"]
:no-match nil))))

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to