Clearer tests for sorting and limits on queries

This commit is contained in:
Adrian Madrid 2009-01-06 16:49:48 -07:00
parent df7c7eaf43
commit e34e404bd9
1 changed files with 13 additions and 12 deletions

View File

@ -111,12 +111,14 @@ class DBAPITest < Test::Unit::TestCase
# Sorting (ascending)
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'a' => 1}]).map{ |x| x }
assert_equal 2, docs.size
assert_equal 1, docs.first['a']
assert_equal 1, docs[0]['a']
assert_equal 2, docs[1]['a']
# Sorting (descending)
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'a' => -1}]).map{ |x| x }
assert_equal 2, docs.size
assert_equal 2, docs.first['a']
assert_equal 2, docs[0]['a']
assert_equal 1, docs[1]['a']
# Sorting using array of names; assumes ascending order.
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => ['a']).map{ |x| x }
@ -133,26 +135,25 @@ class DBAPITest < Test::Unit::TestCase
oh['a'] = -1
docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => oh).map{ |x| x }
assert_equal 2, docs.size
assert_equal 2, docs.first['a']
assert_equal 2, docs[0]['a']
assert_equal 1, docs[1]['a']
end
def test_find_limits
@coll.insert('a' => 2)
@coll.insert('b' => 3)
@coll.insert('c' => 4)
@coll.insert('b' => 2)
@coll.insert('c' => 3)
@coll.insert('d' => 4)
docs = @coll.find({}, :limit => 1).map{ |x| x }
puts "docs : #{docs.size}"
assert_equal 1, docs.size
docs = @coll.find({}, :limit => 2).map{ |x| x }
puts "docs : #{docs.size}"
assert_equal 2, docs.size
docs = @coll.find({}, :limit => 3).map{ |x| x }
puts "docs : #{docs.size}"
assert_equal 3, docs.size
docs = @coll.find({}, :limit => 4).map{ |x| x }
assert_equal 4, docs.size
docs = @coll.find({}).map{ |x| x }
puts "docs : #{docs.size}"
assert_equal 3, docs.size
assert_equal 4, docs.size
end
def test_close