Permalink
Browse files

DRY up factor_graph_spec

  • Loading branch information...
1 parent 1e35371 commit d1e339aae1a984d730141919a929ec31c5c4ce12 Chris Lundquist committed with mk Oct 10, 2012
Showing with 71 additions and 65 deletions.
  1. +71 −65 spec/saulabs/trueskill/factor_graph_spec.rb
@@ -32,99 +32,105 @@
end
-end
-
-describe Saulabs::TrueSkill::FactorGraph, "two players" do
- before :each do
- team1 = [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
- team2 = [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
- @teams = [team1,team2]
- @results = { team1 => 1, team2 => 2 }
- end
+ context "When there are two teams" do
+ let :team1 do
+ [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
+ end
- describe 'win with standard rating' do
+ let :team2 do
+ [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
+ end
- before :each do
- TrueSkill::FactorGraph.new(@results).update_skills
+ let :teams do
+ [team1,team2]
end
- it "should change first players rating to [29.395832, 7.1714755]" do
- @teams[0][0].should eql_rating(29.395832, 7.1714755)
+ let :results do
+ { team1 => 1, team2 => 2 }
end
- it "should change second players rating to [20.6041679, 7.1714755]" do
- @teams[1][0].should eql_rating(20.6041679, 7.1714755)
+ let(:draw_results) do
+ { team1 => 1, team2 => 1 }
end
+ context "and exactly two players" do
- end
+ describe 'team1 win with standard rating' do
- describe 'draw with standard rating' do
+ before :each do
+ TrueSkill::FactorGraph.new(results).update_skills
+ end
- before :each do
- team1 = [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
- team2 = [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
- @teams = [ team1, team2]
- results = { team1 => 1, team2 => 1 }
- TrueSkill::FactorGraph.new(results).update_skills
- end
+ it "should change first players rating to [29.395832, 7.1714755]" do
+ teams[0][0].should eql_rating(29.395832, 7.1714755)
+ end
- it "should change first players rating to [25.0, 6.4575196]" do
- @teams[0][0].should eql_rating(25.0, 6.4575196)
- end
+ it "should change second players rating to [20.6041679, 7.1714755]" do
+ teams[1][0].should eql_rating(20.6041679, 7.1714755)
+ end
- it "should change second players rating to [25.0, 6.4575196]" do
- @teams[1][0].should eql_rating(25.0, 6.4575196)
+ end
end
- end
+ describe 'draw with standard rating' do
- describe 'draw with different ratings' do
+ before :each do
+ TrueSkill::FactorGraph.new(draw_results).update_skills
+ end
- before :each do
- team1 = [TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)]
- team2 = [TrueSkill::Rating.new(50.0, 12.5, 1.0, 25.0/300.0)]
- @teams = [team1,team2]
- results = { team1 => 1, team2 => 1 }
- TrueSkill::FactorGraph.new(results).update_skills
- end
+ it "should change first players rating to [25.0, 6.4575196]" do
+ teams[0][0].should eql_rating(25.0, 6.4575196)
+ end
- it "should change first players rating to [31.6623, 7.1374]" do
- @teams[0][0].should eql_rating(31.662301, 7.1374459)
- end
+ it "should change second players rating to [25.0, 6.4575196]" do
+ teams[1][0].should eql_rating(25.0, 6.4575196)
+ end
- it "should change second players mean to [35.0107, 7.9101]" do
- @teams[1][0].should eql_rating(35.010653, 7.910077)
end
- end
+ describe 'draw with different ratings' do
+ let :team2 do
+ [TrueSkill::Rating.new(50.0, 12.5, 1.0, 25.0/300.0)]
+ end
-end
+ before :each do
+ TrueSkill::FactorGraph.new(draw_results).update_skills
+ end
-describe Saulabs::TrueSkill::FactorGraph, "1 vs 2, skills are additive, standard rating" do
+ it "should change first players rating to [31.6623, 7.1374]" do
+ teams[0][0].should eql_rating(31.662301, 7.1374459)
+ end
- before :each do
- team1 = [ TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0), ]
- team2 = [
- TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0),
- TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)
- ]
-
- @teams = [team1, team2]
- @results = { team1 => 1, team2 => 1 }
- end
+ it "should change second players mean to [35.0107, 7.9101]" do
+ teams[1][0].should eql_rating(35.010653, 7.910077)
+ end
- describe "#@skill_update" do
- it "should have a Boolean @skills_additive = false" do
- @graph = TrueSkill::FactorGraph.new(@results, {:skills_additive => false})
- @graph.skills_additive.should be_false
end
- it "should update the mean of the first player in team1 to 25.0 after draw" do
- @graph = TrueSkill::FactorGraph.new(@results, {:skills_additive => false})
- @graph.update_skills
- @teams[0][0].mean.should be_within(tolerance).of(25.0)
+ context "when it is a 1 vs 2" do
+ let :team2 do
+ [
+ TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0),
+ TrueSkill::Rating.new(25.0, 25.0/3.0, 1.0, 25.0/300.0)
+ ]
+ end
+
+ context "and the skills are additive" do
+ describe "#@skill_update" do
+ it "should have a Boolean @skills_additive = false" do
+ @graph = TrueSkill::FactorGraph.new(draw_results, {:skills_additive => false})
+ @graph.skills_additive.should be_false
+ end
+
+ it "should update the mean of the first player in team1 to 25.0 after draw" do
+ @graph = TrueSkill::FactorGraph.new(draw_results, {:skills_additive => false})
+
+ @graph.update_skills
+ teams[0][0].mean.should be_within(tolerance).of(25.0)
+ end
+ end
+ end
end
end
end

0 comments on commit d1e339a

Please sign in to comment.