spec/spec.google_hash.rb in google_hash-0.8.9 vs spec/spec.google_hash.rb in google_hash-0.9.0
- old
+ new
@@ -6,10 +6,15 @@
rescue LoadError
require 'rspec' # rspec2
require 'rspec/autorun'
end
+
+RSpec.configure do |config|
+ config.expect_with(:rspec) { |c| c.syntax = :should } # silence warning
+end
+
describe "google_hash" do
before do
@subject = GoogleHashSparseIntToRuby.new
end
@@ -111,16 +116,10 @@
a = GoogleHashDenseRubyToRuby.new
a['abc'] = 'def'
a['abc'].should == 'def'
end
- it "should have better namespace" do
- pending do
- GoogleHash::Sparse
- end
- end
-
it "should disallow non numeric keys" do
lambda { @subject['33']}.should raise_error(TypeError)
end
it "should return nil if key is absent" do
@@ -179,11 +178,11 @@
a[3].should == 4
end
it "should raise on errant values" do
a = GoogleHashDenseIntToInt.new
- proc { a[3] = 'abc'}.should raise_error
+ proc { a[3] = 'abc'}.should raise_error(TypeError)
end
it "should do bignum values as doubles" do
a = GoogleHashDenseDoubleToInt.new
a[10000000000000000000] = 1
@@ -230,11 +229,11 @@
a[10000000000000000000] = 10000000000000000000
a[10000000000000000000].should == 10000000000000000000
end
it "should do bignum to doubles et al" do
- test_big_numbers( GoogleHashDenseDoubleToDouble.new)
+ test_big_numbers(GoogleHashDenseDoubleToDouble.new)
end
it "should allow for storing true BigNum" do
pending 'caring about bignums at all and even having the classes in there'
test_big_numbers(GoogleHashDenseBigNumToRuby.new)
@@ -252,19 +251,30 @@
@subject.each_value {|v| sum += v}
@subject.each_key {|k| sum += k}
sum.should == 7
end
end
-
+
+ it "should not call Ruby #== during GC" do
+ a = GoogleHashSparseRubyToRuby.new
+ b = Object.new
+ def b.eql?(something)
+ raise "should not call this during GC!"
+ end
+ a[b] = 3
+ GC.start # used to raise...
+ a.each{|k, v| } # just in case, this really shouldn't either
+ end
+
it "should have nice inspect" do
a = GoogleHashSparseIntToRuby.new
a[3] = 4
a[4] = 5
a.inspect.should == "GoogleHashSparseIntToRuby {3=>4,4=>5}"
end
- it "should skip GC when native to native" do
+ it "should skip iterating during GC when native to native" do
pending 'caring, get from gc_bench.rb'
end
def self.get_all_classes
Object.constants.grep(/googlehash/i).map{|c| Object.const_get(c) }
@@ -275,10 +285,10 @@
keys = [0, 1, -1, 2, -1, 1<<29]
if OS.bits == 64
keys << (1<<61)
end
keys.each{|k|
- it "should allow for setting the right keys #{k} #{c}" do
+ it "should allow for setting the right keys key=#{k} class=#{c} (1<<61=#{1<<61})" do
instance = c.new
instance[k].should == nil
instance[k] = 0
instance[k+1] = 3
instance[k-1] = 2