Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
omkarmoghe committed Apr 8, 2024
1 parent 78a1417 commit a600900
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 9 deletions.
26 changes: 17 additions & 9 deletions test/correctness/test_elo.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TestElo < Minitest::Test
def setup
@env = PortableExpressions::Environment.new(
Expand All @@ -9,7 +11,7 @@ def setup
)
end

def test_elo
def test_elo # rubocop:disable Metrics/AbcSize,Metrics/MethodLength
# starting ratings of 2 players
rating_a = PortableExpressions::Variable.new("rating_a")
rating_b = PortableExpressions::Variable.new("rating_b")
Expand Down Expand Up @@ -37,20 +39,26 @@ def test_elo
def test_elo_no_local_variables
rating_a_new = @env.evaluate(
# starting ratings of 2 players
PortableExpressions::Expression.new(:-, PortableExpressions::Variable.new("rating_b"), PortableExpressions::Variable.new("rating_a"), output: "rating_difference"),
PortableExpressions::Expression.new(:/, PortableExpressions::Variable.new("rating_difference"), PortableExpressions::Variable.new("scale_factor"), output: "exponent"),
PortableExpressions::Expression.new(:-, PortableExpressions::Variable.new("rating_b"),
PortableExpressions::Variable.new("rating_a"), output: "rating_difference"),
PortableExpressions::Expression.new(:/, PortableExpressions::Variable.new("rating_difference"),
PortableExpressions::Variable.new("scale_factor"), output: "exponent"),
PortableExpressions::Expression.new(
:+,
PortableExpressions::Scalar.new(1),
PortableExpressions::Expression.new(:**, PortableExpressions::Scalar.new(10), PortableExpressions::Variable.new("exponent")),
PortableExpressions::Expression.new(:**, PortableExpressions::Scalar.new(10),
PortableExpressions::Variable.new("exponent")),
output: "denominator"
),
PortableExpressions::Expression.new(:/, PortableExpressions::Scalar.new(1), PortableExpressions::Variable.new("denominator"), output: "expected_probability_a"),

PortableExpressions::Expression.new(:/, PortableExpressions::Scalar.new(1),
PortableExpressions::Variable.new("denominator"), output: "expected_probability_a"),
# [0, 1] where 0 is loss, 1 is win, 0.5 is draw
PortableExpressions::Expression.new(:-, PortableExpressions::Variable.new("score_a"), PortableExpressions::Variable.new("expected_probability_a"), output: "k_multiplier"),
PortableExpressions::Expression.new(:*, PortableExpressions::Variable.new("k_factor"), PortableExpressions::Variable.new("k_multiplier"), output: "rating_delta"),
PortableExpressions::Expression.new(:+, PortableExpressions::Variable.new("rating_a"), PortableExpressions::Variable.new("rating_delta"), output: "rating_a_new")
PortableExpressions::Expression.new(:-, PortableExpressions::Variable.new("score_a"),
PortableExpressions::Variable.new("expected_probability_a"), output: "k_multiplier"),
PortableExpressions::Expression.new(:*, PortableExpressions::Variable.new("k_factor"),
PortableExpressions::Variable.new("k_multiplier"), output: "rating_delta"),
PortableExpressions::Expression.new(:+, PortableExpressions::Variable.new("rating_a"),
PortableExpressions::Variable.new("rating_delta"), output: "rating_a_new")
)

assert_equal(1016.0, rating_a_new)
Expand Down
2 changes: 2 additions & 0 deletions test/correctness/test_logical_methods.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TestLogicalMethods < Minitest::Test
def setup
@env = PortableExpressions::Environment.new(
Expand Down
2 changes: 2 additions & 0 deletions test/correctness/test_parsing.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

class TestParser < Minitest::Test
def test_variable
json = <<~JSON
Expand Down

0 comments on commit a600900

Please sign in to comment.