(defn acmp [a1 a2 tolerance] (every? #(< % tolerance) (map #(Math/abs (- %1 %2)) (seq a1) (seq a2))))
user=> (acmp (double-array [0.01 0.7 2.2]) (double-array [0.011 0.695 2.199]) 0.01) true user=> (acmp (double-array [0.01 0.7 2.2]) (double-array [0.011 0.695 2.199]) 0.005) false user=> Will work on any seqables of float/double. On Tue, May 28, 2013 at 12:57 PM, Jim - FooBar(); <jimpil1...@gmail.com>wrote: > ooo thanks Chris! I was suspecting the exact same thing because I tried > this: > > (is (= (seq (aget ready 0)) > (seq (aget ready 1)))) > > and got this: > > expected: (= (seq (aget ready 0)) (seq (aget ready 1))) > actual: (not (= (-0.5345224838248488 0.2672612419124244 0.801783725737273* > 1*) > (-0.5345224838248488 0.2672612419124244 > 0.801783725737273*2*))) > > observe the last digit of the 3rd number (the bold ones)! This is why the > test fails in Clojure... > > thanks again :) > > Jim > > > > > On 28/05/13 17:42, Jim - FooBar(); wrote: > > Hi everyone, > > sometimes I feel really stupid! > > I am currently looking at a well-known java library's tests and found this: > > Assert.assertArrayEquals(arrayOutput[0], arrayOutput[1], 0.01); > //arrayOutput is a 2d double-array btw > > since I've basically wrapped this lib, I'd like to port the java tests as > well. First of all, how do I compare 2 arrays in Clojure without using > .equals() which is broken for arrays. More importantly, where on earth is > that method (*assertArrayEquals*)? Looking at the docs for JUnit [1], I > can see no overload that takes 2 arrays and a double!!! In fact the only > methods that take 3 args expect a String as the first arg....what is > happening? can anyone shine some light please? I am utterly confused... > > thanks in advance, > > Jim > > [1]http://junit.sourceforge.net/javadoc/org/junit/Assert.html > > > -- > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with > your first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > 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 clojure+unsubscr...@googlegroups.com. > For more options, visit https://groups.google.com/groups/opt_out. > > > -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com 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 clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.