Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require 'test/unit'
- class Score
- attr_reader :score1
- attr_reader :score2
- attr_reader :draw
- attr_reader :win1
- attr_reader :win2
- def initialize(score1 = nil, score2 = nil)
- @score1, @score2 = score1, score2
- @draw = score1 == score2
- @win2 = !@win1 = score1 > score2
- end
- end
- def compare(score1, score2)
- if score1.score1 == score2.score1 && score1.score2 == score2.score2
- 2
- elsif (score1.draw && score2.draw) || (score1.win1 == score2.win1 && score1.win2 == score2.win2)
- 1
- else
- 0
- end
- end
- class ScoreTest < Test::Unit::TestCase
- def test_exact_score
- user_score = Score.new(4,1)
- sys_score = Score.new(4,1)
- assert_equal(2, compare(user_score, sys_score))
- end
- def test_draw
- user_score = Score.new(2,2)
- sys_score = Score.new(1,1)
- assert_equal(1, compare(user_score, sys_score))
- end
- def test_win_team
- user_score = Score.new(4,1)
- sys_score = Score.new(5,1)
- assert_equal(1, compare(user_score, sys_score))
- end
- def test_lose
- user_score = Score.new(3,1)
- sys_score = Score.new(5,7)
- assert_equal(0, compare(user_score, sys_score))
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement