summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-08-18 18:29:09 +0000
committerEric Wong <normalperson@yhbt.net>2011-08-18 18:29:09 +0000
commit29b8959851c55b317b5d801e85a55f7b623508c1 (patch)
tree06c44feb4caf593dd2819ee111150959fcc3be04
parent903e89b320b9ba29c2348a224c74807f73884e7c (diff)
Just in case something was horribly wrong in my C++ -> C
ports.
-rw-r--r--test/test_tdb_hash_functions.rb30
1 files changed, 30 insertions, 0 deletions
diff --git a/test/test_tdb_hash_functions.rb b/test/test_tdb_hash_functions.rb
index 86c599a..cd43326 100644
--- a/test/test_tdb_hash_functions.rb
+++ b/test/test_tdb_hash_functions.rb
@@ -12,4 +12,34 @@ class TestHashFunctions < Test::Unit::TestCase
       assert_kind_of Integer, __send__("tdb_hash_#{name}", "hello")
     end
   end
+
+  def test_distro_sequential
+    TDB::HASHES.each do |name,_|
+      next if :default == name
+      m = method "tdb_hash_#{name}"
+      tmp = Hash.new { |h,k| h[k] = 0 }
+      (1..100000).each do |s|
+        tmp[m.call(s.to_s) % 7] += 1
+      end
+      assert_equal 7, tmp.size
+      tmp.each_value do |v|
+        assert_in_delta 100000/7.0, v, 1000
+      end
+    end
+  end
+
+  def test_distro_random
+    TDB::HASHES.each do |name,_|
+      next if :default == name
+      m = method "tdb_hash_#{name}"
+      tmp = Hash.new { |h,k| h[k] = 0 }
+      100000.times do
+        tmp[m.call(rand.to_s) % 7] += 1
+      end
+      assert_equal 7, tmp.size
+      tmp.each_value do |v|
+        assert_in_delta 100000/7.0, v, 1000
+      end
+    end
+  end
 end