File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed
spec/ruby/library/bigdecimal
src/main/java/org/truffleruby/stdlib/bigdecimal Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change
1
+ require_relative '../../spec_helper'
2
+ require 'bigdecimal'
3
+
4
+ describe "BidDecimal#hash" do
5
+ describe "two BigDecimal objects with the same value" do
6
+ it "should have the same hash for ordinary values" do
7
+ BigDecimal ( '1.2920' ) . hash . should == BigDecimal ( '1.2920' ) . hash
8
+ end
9
+
10
+ it "should have the same hash for infinite values" do
11
+ BigDecimal ( "+Infinity" ) . hash . should == BigDecimal ( "+Infinity" ) . hash
12
+ BigDecimal ( "-Infinity" ) . hash . should == BigDecimal ( "-Infinity" ) . hash
13
+ end
14
+
15
+ it "should have the same hash for NaNs" do
16
+ BigDecimal ( "NaN" ) . hash . should == BigDecimal ( "NaN" ) . hash
17
+ end
18
+
19
+ it "should have the same hash for zero values" do
20
+ BigDecimal ( "+0" ) . hash . should == BigDecimal ( "+0" ) . hash
21
+ BigDecimal ( "-0" ) . hash . should == BigDecimal ( "-0" ) . hash
22
+ end
23
+ end
24
+
25
+ describe "two BigDecimal objects with numerically equal values" do
26
+ it "should have the same hash value" do
27
+ BigDecimal ( "1.2920" ) . hash . should == BigDecimal ( "1.2920000" ) . hash
28
+ end
29
+ end
30
+ end
Original file line number Diff line number Diff line change @@ -1566,7 +1566,7 @@ public Object hashNormal(DynamicObject value) {
1566
1566
public Object hashSpecial (DynamicObject value ) {
1567
1567
final BigDecimalType type = Layouts .BIG_DECIMAL .getType (value );
1568
1568
1569
- return getContext ().getHashing (this ).hash (CLASS_SALT , System . identityHashCode ( type ));
1569
+ return getContext ().getHashing (this ).hash (CLASS_SALT , type . hashCode ( ));
1570
1570
}
1571
1571
1572
1572
}
You can’t perform that action at this time.
0 commit comments