You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 

67 rivejä
1.8 KiB

require "./spec_helper"
describe Crystal::Scatter do
# TODO: Write tests
it "add elements to RingGraphs" do
rg = Crystal::Scatter::RingGraph.new
rg.add(UInt64.new(1),[0,0,0,0,0,0],"OSD0")
rg.add(UInt64.new(1),[0,0,0,0,0,1],"OSD1")
rg.add(UInt64.new(1),[0,0,0,0,1,0],"OSD2")
rg.get_weight.should eq(3)
rg.generate_ring(BigRational.new(1))
rg[0][0][0][0][0][0].range_effector.not_nil!.[0].should eq(0)
rg[0][0][0][0][1][0].range_effector.not_nil!.[1].should eq(UInt64::MAX)
end
it "hashes data fast" do
v = Crystal::Scatter::MetaRing.new(3)
time = Time.now
(1..100).each do |numb|
v.hash(numb.to_s)
end
t = (Time.now - time)
(t.milliseconds <= 1).should be_true
end
it "hashes data good" do
v = Crystal::Scatter::MetaRing.new(3)
hash_nb =1000000
store = Hash(UInt64, Int32).new
(1..hash_nb).each do |numb|
h = v.hash(numb.to_s)
nb=store.fetch(h,0)
store[h]=nb+1
end
conflicts = hash_nb-store.size
(conflicts <= 100).should be_true
mod_array = Array(Int32).new(1000,0)
slice_array = Array(Int32).new(1000,0)
store.each_key do |key|
key_mod = key%1000
mod_array[key_mod]+=1
key_slice = key/(UInt64::MAX/1000)
slice_array[key_slice]+=1
end
good_mod = true
good_slice = true
mod_array.each do |v|
good_mod&=(v > (hash_nb/1000*4/5))
end
slice_array.each do |v|
good_slice&=(v > (hash_nb/1000*4/5))
end
good_mod.should be_true
good_slice.should be_true
end
end