spec/spec.google_hash.rb in google_hash-0.7.0 vs spec/spec.google_hash.rb in google_hash-0.8.0
- old
+ new
@@ -47,29 +47,49 @@
end
it "should have all the methods desired" do
# guess these could all be tests, themselves...
- @subject.each{}
- @subject[33] = 'abc'
+ @subject.each{|k, v| raise}
+ @subject[33] = 34
@subject.length.should == 1
- @subject.each{}
+ sum = 0
+ @subject.each{|k, v| sum += k; sum += v}
+ sum.should == (33+34)
+ @subject[33] = 'abc'
@subject.each{|k, v|
k.should == 33
v.should == 'abc'
}
- @subject.delete(33).should == 'abc' # guess we don't do delete yet [?]
- @subject.length.should == 0
- @subject[33] = 'abc'
- @subject.length.should == 1
+
@subject.clear
+ @subject.length.should == 0
+ @subject.keys.should == []
+ @subject[33] = 'abc'
+ @subject.delete(33).should == 'abc' # we don't actually have these methods yet :)
@subject.length.should == 0
+ @subject[33] = 'def'
+ @subject[33].should == 'def'
end
- it 'should not be able to set the absent key for double' do
- fail
+ pending "they should all have a clear method" do
+ for kls in get_all_classes
+ kls.new.clear
+ end
end
+
+ it 'should not be able to set the absent key for double' do
+ if OS.bits == 32
+ unreachable_int = 31
+ unreachable_long = 31
+ else
+ unreachable_int = 31
+ unreachable_long = 63
+ end
+ proc { GoogleHashSparseIntToInt[1<<unreachable_int] = 3 } # should raise...
+ proc { GoogleHashSparseLongToInt[1<<unreachable_long] = 3 }
+ end
def populate(a)
a['abc'] = 'def'
a['bbc'] = 'yoyo'
end
@@ -120,15 +140,14 @@
it "should do longs" do
GoogleHashDenseLongToLong.new
end
if OS.bits == 64
- it "should disallow keys like 1<<40 for ints on 64 bit"
+ it "should disallow keys like 1<<40 for ints on 64 bit, since they'll be lost"
end
- it "should have sets"
- it "should have Set#each"
+ it "should have sets, Set#each, etc."
it "Set should have #combination calls" do
@subject[33] = 34
@subject[36] = 37
@subject.keys_combination_2{|a, b|
@@ -174,33 +193,38 @@
a = GoogleHashDenseDoubleToInt.new
a[10000000000000000000] = 1
a[10000000000000000000].should == 1
end
- it "should not leak" do
- pending 'something that might leak'
- a = GoogleHashDenseIntToInt.new
+ it "should not leak [?]" do
+ a = GoogleHashSparseIntToInt.new
100_000.times {
a[1] = 1
a[1]
a.each{|k, v|}
a.delete(1) rescue nil
}
+ a.length.should == 0
OS.rss_bytes.should be < 25_000_000
end
+ it "should do delete from dense" do
+ GoogleHashDenseDoubleToInt.new.delete('a').should == nil
+ end
+
it "should do int values as doubles" do
a = GoogleHashDenseDoubleToInt.new
a[1] = 1
a[1].should == 1
end
- it "should do float values as doubles" do
- pending "interest in floats"
- a = GoogleHashDenseDoubleToInt.new
- a[1.0] = 1
- a[1.0].should == 1
+ it "should do float values as doubles, too, not just big numbers" do
+ pending "request" do
+ a = GoogleHashDenseDoubleToInt.new
+ a[1.0] = 1
+ a[1.0].should == 1
+ end
end
it "should do bignum to doubles et al" do
a = GoogleHashDenseDoubleToDouble.new
a[10000000000000000000] = 1
@@ -218,55 +242,51 @@
fail 'same as above plus the following:'
a = GoogleHashDenseBignumToRuby.new
a[10000000000000000000] = 'abc'
end
- it 'should be able to delete bignums without leaking' do
- pending
- a = GoogleHashDenseBignumToBignum.new
- 100_000.times {
- a[10000000000000000000] = 1
- a.size.should == 1
- a.delete[10000000000000000000]
- a.size.should == 0
- }
- assert OS.rss_bytes < 100_000
- end
+ it "should have an Enumerator return for values, keys [?] instead of an array?"
- it "should have an Enumerator for values, keys, an on demand, getNext enumerator object..."
-
- it "should have a block access for values, keys" do
- pending "interest"
- @a[3] = 4
- a.each_value {}
- a.each_key {}
+ it "should have a block access for just values, or just keys" do
+ pending "interest" do
+ @subject[3] = 4
+ sum = 0
+ @subject.each_value {|v| sum += v}
+ @subject.each_key {|k| sum += k}
+ sum.should == 7
+ end
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 have sets, too, not just hashes"
-
it "should skip GC when native to native" do
- # tough to test...
+ pending 'caring, get from gc_bench.rb'
end
+ def get_all_classes
+ Object.constants.grep(/googlehash/i).map{|c| Object.const_get(c) }
+ end
+
it "should allow for setting the right keys" do
- all_classes = Object.constants.grep(/googlehash/i).map{|c| Object.const_get(c) }
- all_classes.select{|c| c.to_s =~ /(int|long)to/i}.each{|c|
+ all_classes = get_all_classes
+ all_classes.select{|c| c.to_s =~ /(int|long|double)to/i}.each{|c|
p c
keys = [0, 1, -1, 1<<29]
if OS.bits == 64
- keys << (1<<61)
+ keys << (1<<61)
end
keys.each{|k|
instance = c.new
+ instance[k].should == nil
instance[k] = 0
+ instance[k-1] = 2
instance[k].should == 0
+ instance[k-1].should == 2
}
}
end
end