Skip to content

Commit

Permalink
Testing Againts to Tie Ranking Leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
robertomiranda committed Dec 9, 2014
1 parent cad621c commit 9cf2d88
Showing 1 changed file with 64 additions and 1 deletion.
65 changes: 64 additions & 1 deletion spec/tie_ranking_leaderboard_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,69 @@
end
end

it 'should allow you to retrieve a given set of members from the leaderboard in a rank range' do
@leaderboard = TieRankingLeaderboard.new('ties', Leaderboard::DEFAULT_OPTIONS, {:host => "127.0.0.1", :db => 15})
rank_members_in_leaderboard(25)

members = @leaderboard.members_from_rank_range(5, 9)
expect(members.size).to be(5)
expect(members[0][:member]).to eql('member_21')
expect(members[0][:score].to_i).to be(21)
expect(members[4][:member]).to eql('member_17')

members = @leaderboard.members_from_rank_range(1, 1)
expect(members.size).to be(1)
expect(members[0][:member]).to eql('member_25')

members = @leaderboard.members_from_rank_range(-1, 26)
expect(members.size).to be(25)
expect(members[0][:member]).to eql('member_25')
expect(members[0][:score].to_i).to be(25)
expect(members[24][:member]).to eql('member_1')
end

it 'should allow you to retrieve a given set of members from the leaderboard in a range from 1 to the number given' do
@leaderboard = TieRankingLeaderboard.new('ties', Leaderboard::DEFAULT_OPTIONS, {:host => "127.0.0.1", :db => 15})
rank_members_in_leaderboard(25)

members = @leaderboard.top(5)
expect(members.size).to be(5)
expect(members[0][:member]).to eql('member_25')
expect(members[0][:score].to_i).to be(25)
expect(members[4][:member]).to eql('member_21')

members = @leaderboard.top(1)
expect(members.size).to be(1)
expect(members[0][:member]).to eql('member_25')

members = @leaderboard.top(26)
expect(members.size).to be(25)
expect(members[0][:member]).to eql('member_25')
expect(members[0][:score].to_i).to be(25)
expect(members[24][:member]).to eql('member_1')
end

it 'should allow you to retrieve a given set of members from the named leaderboard in a range from 1 to the number given' do
@leaderboard = TieRankingLeaderboard.new('name', Leaderboard::DEFAULT_OPTIONS, {:host => "127.0.0.1", :db => 15})
rank_members_in_leaderboard(25)

members = @leaderboard.top_in("name", 5)
expect(members.size).to be(5)
expect(members[0][:member]).to eql('member_25')
expect(members[0][:score].to_i).to be(25)
expect(members[4][:member]).to eql('member_21')

members = @leaderboard.top(1)
expect(members.size).to be(1)
expect(members[0][:member]).to eql('member_25')

members = @leaderboard.top(26)
expect(members.size).to be(25)
expect(members[0][:member]).to eql('member_25')
expect(members[0][:score].to_i).to be(25)
expect(members[24][:member]).to eql('member_1')
end

it 'should expire the ties leaderboard in a given number of seconds' do
@leaderboard = TieRankingLeaderboard.new('ties', Leaderboard::DEFAULT_OPTIONS, {:host => "127.0.0.1", :db => 15})

Expand Down Expand Up @@ -238,4 +301,4 @@
end
end
end
end
end

0 comments on commit 9cf2d88

Please sign in to comment.