From f2eea735dbdbe6a336cbc70f37fbff90b76bec21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jean-Fran=C3=A7ois=20Geyelin?= Date: Mon, 30 Apr 2018 19:14:32 +0200 Subject: [PATCH] ran gofmt. --- elogo.go | 17 +++++++++-------- elogo_test.go | 15 +++++++-------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/elogo.go b/elogo.go index 96e0251..f199e6b 100644 --- a/elogo.go +++ b/elogo.go @@ -19,13 +19,13 @@ type Elo struct { // Outcome is a match result data for a single player. type Outcome struct { - Delta int + Delta int Rating int } // NewElo instantiates the Elo object with default factors. // Default K-Factor is 32 -// Default deviation is 400 +// Default deviation is 400 func NewElo() *Elo { return &Elo{K, D} } @@ -42,7 +42,7 @@ func (e *Elo) ExpectedScore(ratingA, ratingB int) float64 { // ExpectedScoreWithFactors overrides default factors and gives the expected chance that the first player wins func (e *Elo) ExpectedScoreWithFactors(ratingA, ratingB, d int) float64 { - return 1 / (1 + math.Pow(10, float64(ratingB - ratingA) / float64(d))) + return 1 / (1 + math.Pow(10, float64(ratingB-ratingA)/float64(d))) } // RatingDelta gives the ratings change for the first player for the given score @@ -51,7 +51,7 @@ func (e *Elo) RatingDelta(ratingA, ratingB int, score float64) int { } // RatingDeltaWithFactors overrides default factors and gives the ratings change for the first player for the given score -func (e *Elo) RatingDeltaWithFactors(ratingA, ratingB int, score float64, k, d int ) int { +func (e *Elo) RatingDeltaWithFactors(ratingA, ratingB int, score float64, k, d int) int { return int(float64(k) * (score - e.ExpectedScoreWithFactors(ratingA, ratingB, d))) } @@ -59,8 +59,9 @@ func (e *Elo) RatingDeltaWithFactors(ratingA, ratingB int, score float64, k, d i func (e *Elo) Rating(ratingA, ratingB int, score float64) int { return e.RatingWithFactors(ratingA, ratingB, score, e.K, e.D) } + // RatingWithFactors overrides default factors and gives the new rating for the first player for the given score -func (e *Elo) RatingWithFactors(ratingA, ratingB int, score float64, k, d int ) int { +func (e *Elo) RatingWithFactors(ratingA, ratingB int, score float64, k, d int) int { return ratingA + e.RatingDeltaWithFactors(ratingA, ratingB, score, k, d) } @@ -70,7 +71,7 @@ func (e *Elo) Outcome(ratingA, ratingB int, score float64) (Outcome, Outcome) { } // OutcomeWithFactors overrides default factors and gives an Outcome object for each player for the given score -func (e *Elo) OutcomeWithFactors(ratingA, ratingB int, score float64, k, d int ) (Outcome, Outcome) { +func (e *Elo) OutcomeWithFactors(ratingA, ratingB int, score float64, k, d int) (Outcome, Outcome) { delta := e.RatingDeltaWithFactors(ratingA, ratingB, score, k, d) - return Outcome{ delta, ratingA + delta }, Outcome{ -delta, ratingB - delta } -} \ No newline at end of file + return Outcome{delta, ratingA + delta}, Outcome{-delta, ratingB - delta} +} diff --git a/elogo_test.go b/elogo_test.go index 64c81d6..3992f90 100644 --- a/elogo_test.go +++ b/elogo_test.go @@ -43,19 +43,18 @@ func TestElo(t *testing.T) { t.Fatalf("Expected rating if draw %v, but got %v", 1504, rating3) } - outcomeA1, outcomeB1 := elo.Outcome(A, B, 1) + outcomeA1, outcomeB1 := elo.Outcome(A, B, 1) if outcomeA1.Rating != 1520 || outcomeA1.Delta != 20 { t.Fatalf("Expected rating %v and delta %v if A wins, but got outcome %v", 1520, 20, outcomeA1) - } + } if outcomeB1.Rating != 1580 || outcomeB1.Delta != -20 { t.Fatalf("Expected rating %v and delta %v if B loses, but got outcome %v", 1580, -20, outcomeB1) - } + } } func TestEloWithFactors(t *testing.T) { elo := NewEloWithFactors(40, 800) - expected := elo.ExpectedScore(A, B) if expected != 0.4285368825916186 { t.Fatalf("Expected chance %v, but got %v", 0.4285368825916186, expected) @@ -87,11 +86,11 @@ func TestEloWithFactors(t *testing.T) { t.Fatalf("Expected rating if draw %v, but got %v", 1502, rating3) } - outcomeA1, outcomeB1 := elo.Outcome(A, B, 1) + outcomeA1, outcomeB1 := elo.Outcome(A, B, 1) if outcomeA1.Rating != 1522 || outcomeA1.Delta != 22 { t.Fatalf("Expected rating %v and delta %v if A wins, but got outcome %v", 1522, 22, outcomeA1) - } + } if outcomeB1.Rating != 1578 || outcomeB1.Delta != -22 { t.Fatalf("Expected rating %v and delta %v if B loses, but got outcome %v", 1578, -22, outcomeB1) - } -} \ No newline at end of file + } +}