Permalink
Browse files

add iteration test

  • Loading branch information...
1 parent 68b1ff2 commit 1174d1472ee8d6bdf9c65e222c750716ee36ff8a @technoweenie technoweenie committed Nov 29, 2011
Showing with 80 additions and 0 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 Rakefile
  3. +72 −0 test/iteration_test.rb
View
@@ -7,3 +7,4 @@ ext/leveldb/libleveldb.a
leveldb/libleveldb.a
leveldb/leveldb.gyp
pkg
+test/*.db
View
@@ -26,4 +26,11 @@ end
Gem::PackageTask.new spec do
end
+require 'rake/testtask'
+Rake::TestTask.new(:test) do |test|
+ test.libs << 'lib' << 'test'
+ test.pattern = 'test/**/*_test.rb'
+ test.verbose = true
+end
+
# vim: syntax=ruby
@@ -0,0 +1,72 @@
+require 'test/unit'
+require File.expand_path("../../lib/leveldb", __FILE__)
+
+class IterationTest < Test::Unit::TestCase
+ DB = LevelDB::DB.new(File.expand_path("../iteration.db", __FILE__))
+ DB.put "a/1", "1"
+ DB.put "b/1", "1"
+ DB.put "b/2", "1"
+ DB.put "b/3", "1"
+ DB.put "c/1", "1"
+
+ def test_each
+ expected = %w(a/1 b/1 b/2 b/3 c/1)
+ keys = []
+ DB.each do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+
+ def test_each_with_key_from
+ expected = %w(b/1 b/2 b/3 c/1)
+ keys = []
+ DB.each('b') do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+
+ def test_each_with_key_from_to
+ expected = %w(b/1 b/2 b/3 c/1)
+ keys = []
+ DB.each('b', 'b/4') do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+
+ def test_reverse_each
+ expected = %w(c/1 b/3 b/2 b/1 a/1)
+ keys = []
+ DB.reverse_each do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+
+ def test_reverse_each_with_key_from
+ expected = %w(b/1 a/1)
+ keys = []
+ DB.reverse_each('b') do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+
+ def test_reverse_each_with_key_from_to
+ expected = %w(c/1 b/3 b/2 b/1 a/1)
+ keys = []
+ DB.reverse_each('c', 'b') do |key, value|
+ keys << key
+ end
+
+ assert_equal expected, keys
+ end
+end
+

0 comments on commit 1174d14

Please sign in to comment.