-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseriensieger_spec.rb
153 lines (137 loc) · 4.47 KB
/
seriensieger_spec.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
require "./seriensieger"
require "time"
def a_match (options = {})
{
match_is_finished: false,
group_id: 1,
id_team1: 1,
id_team2: 2,
league_id: 1,
match_date_time:"2012-01-30T17:30:00+00:00",
}.merge(options)
end
def finished_match (options = {})
a_match({
match_is_finished: true,
points_team1: 1,
points_team2: 0,
match_date_time: "2011-01-30T17:30:00+00:00",
}.merge(options))
end
def match_data (data)
cnt = 0
data.map do |match|
cnt += 1
{match_id: cnt}.merge(match)
end
end
RSpec.configure do |config|
config.mock_framework = :rspec
end
describe Seriensieger do
describe "#generate_guess" do
it "returns 2:1 on first game" do
sieger = Seriensieger.new
sieger.match_data = match_data([a_match])
sieger.generate_guess(sieger.match_data.first[:match_id]).should == [2, 1]
end
it "returns 2:0 on previous 1:0, 0:1" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3),
finished_match(id_team1: 3, id_team2: 2),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [2, 0]
end
it "returns 1:0 on previous 1:0, 0:0" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3),
finished_match(id_team1: 3, id_team2: 2, points_team1: 0),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [1, 0]
end
it "returns 2:1 on previous 2:0, 2:1" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3, points_team1: 2),
finished_match(id_team1: 3, id_team2: 2, points_team2: 2),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [2, 1]
end
it "returns 3:0 on previous 2:0, 0:2" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3, points_team1: 2),
finished_match(id_team1: 3, id_team2: 2, points_team1: 2, points_team2: 0),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [3, 0]
end
it "returns 3:0 on previous 4:0, 0:0" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3, points_team1: 4),
finished_match(id_team1: 3, id_team2: 2, points_team2: 0),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [3, 0]
end
it "returns 2:1 on previous 4:2, 1:0" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match(id_team1: 1, id_team2: 3, points_team1: 4, points_team2: 2),
finished_match(id_team1: 3, id_team2: 2, points_team1: 0, points_team2: 1),
a_match
])
sieger.generate_guess(sieger.match_data.last[:match_id]).should == [2, 1]
end
end
describe "#matches_to_guess" do
it "returns the match in the next 24 hours" do
sieger = Seriensieger.new
sieger.match_data = match_data([
finished_match,
a_match(match_date_time: Time.at(Time.now + 60*60*2).iso8601),
a_match(match_date_time: Time.at(Time.now + 60*60*24*5).iso8601)
])
sieger.matches_to_guess.length.should == 1
sieger.matches_to_guess.should == [sieger.match_data[1][:match_id]]
end
end
describe "#guess_next" do
it "sends one guess for each next match" do
sieger = Seriensieger.new
sieger.match_data = match_data([
a_match(match_date_time: Time.at(Time.now + 60*60*2).iso8601)
])
mock_submitter = double('submitter')
mock_submitter.should_receive(:submit)
sieger.guess_next(mock_submitter)
end
end
describe "#guess_all" do
it "sends one guess for each match" do
sieger = Seriensieger.new
sieger.match_data = match_data([
a_match
])
mock_submitter = double('submitter')
mock_submitter.should_receive(:submit)
sieger.guess_all(mock_submitter)
end
end
describe "#load" do
it "sends a load request and updates match_data" do
sieger = Seriensieger.new
mock_loader = double('loader')
mock_loader.should_receive(:get).with(2010).and_return([{match_id: 1}])
sieger.load(2010, mock_loader)
sieger.match_data.length.should == 1
end
end
end
# vim: ai sw=2 expandtab smarttab ts=2