-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.rb
111 lines (90 loc) · 3.03 KB
/
run.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
system 'rm Gemfile' if File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'pry-rescue'
GEMFILE
system 'bundle install'
require 'bundler'
Bundler.setup(:default)
require 'minitest/autorun'
require 'pry-rescue/minitest'
require 'logger'
require './league_table.rb'
describe LeagueTable do
before do
@lt = LeagueTable.new
@lt.matches.push("Man Utd 3 - 0 Liverpool",
"Real Mad 4 - 3 Liverpool",
"Real Mad 3 - 1 Man Utd",
"Chelsea 4 - 3 Bayern",
"Real Mad 2 - 0 Chelsea",
"Liverpool 2 - 2 Chelsea",
"Man Utd 2 - 3 Bayern")
end
describe "find_matches" do
before do
@scores = @lt.find_matches("Liverpool")
end
it "takes correct amount of results" do
@scores.size.must_equal(3)
end
it "takes proper results" do
@scores.must_include("Liverpool 2 - 2 Chelsea")
@scores.must_include("Man Utd 3 - 0 Liverpool")
@scores.must_include("Real Mad 4 - 3 Liverpool")
end
it "do not takes unassociated results" do
@scores.wont_include("Real Mad 2 - 0 Chelsea")
@scores.wont_include("Man Utd 3 - 2 Bayern")
@scores.wont_include("Chelsea 4 - 3 Bayern")
end
end
describe "get_scores" do
before do
@goals_gained = @lt.get_scores("Man Utd")
@goals_lost = @lt.get_scores("Man Utd", false)
end
it "gets goals earned for team" do
@goals_gained.must_equal(["Man Utd 3", "1 Man Utd", "Man Utd 2"])
end
it "gets goals lost for opponent" do
@goals_lost.must_equal(["0 Liverpool", "Real Mad 3", "3 Bayern"])
end
end
it "get_goals_for returns sum of goals earned" do
@lt.get_goals_for("Bayern").must_equal(6)
@lt.get_goals_for("Foo").must_equal(0)
end
it "get_goals_against returns sum of goals conceeded" do
@lt.get_goals_against("Bayern").must_equal(6)
@lt.get_goals_against("Foo").must_equal(0)
end
it "get_goal_difference returns difference between earned and conceeded goals" do
@lt.get_goals_difference("Chelsea").must_equal(-1)
@lt.get_goals_difference("Foo").must_equal(0)
end
it "check_winner should return score of winning team" do
match1 = @lt.matches.first
match2 = @lt.matches.last
@lt.check_winner(match1).must_equal("Man Utd")
@lt.check_winner(match2).must_equal("Bayern")
end
it "get_wins returns correct amount of winned matches" do
@lt.get_wins("Real Mad").must_equal(3)
@lt.get_wins("Foo").must_equal(0)
end
it "get_losses returns correct amount of lost matches" do
@lt.get_losses("Liverpool").must_equal(2)
@lt.get_losses("Foo").must_equal(0)
end
it "get_draws returns correct amount of lost matches" do
@lt.get_draws("Liverpool").must_equal(1)
@lt.get_draws("Foo").must_equal(0)
end
it "get_points returns corrent amount of points earned by team" do
@lt.get_points("Liverpool").must_equal(1)
@lt.get_points("Man Utd").must_equal(3)
@lt.get_points("Real Mad").must_equal(9)
@lt.get_points("Foo").must_equal(0)
end
end