lemonade_stand 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,215 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe LemonadeStand::Game do
4
+
5
+ describe "creating a game" do
6
+
7
+ [
8
+ [4],
9
+ [3],
10
+ ].map { |x| Struct.new(:player_count).new *x }.each do |example|
11
+
12
+ describe "multiple examples" do
13
+
14
+ let(:game) { LemonadeStand::Game.new example.player_count }
15
+
16
+ describe "players" do
17
+
18
+ it "should require the number of players" do
19
+ game.players.count.must_equal example.player_count
20
+ end
21
+
22
+ it "should return player objects for each player" do
23
+ game.players.each { |p| p.is_a?(LemonadeStand::Player).must_equal true }
24
+ end
25
+
26
+ it "should return the same player objects each time" do
27
+ results = game.players
28
+ more_results = game.players
29
+ results.each_with_index do |player, index|
30
+ player.must_be_same_as more_results[index]
31
+ end
32
+ end
33
+
34
+ it "should set the player index on each as an incrementing index" do
35
+ game.players.each_with_index do |player, index|
36
+ player.index.must_equal index
37
+ end
38
+ end
39
+
40
+ it "should set the game on the player" do
41
+ game.players.each do |player|
42
+ player.game.must_be_same_as game
43
+ end
44
+ end
45
+
46
+ end
47
+
48
+ end
49
+
50
+ end
51
+
52
+ end
53
+
54
+ describe "making a choice" do
55
+
56
+ let(:game) { LemonadeStand::Game.new 2 }
57
+
58
+ let(:choice) { Object.new }
59
+
60
+ before do
61
+ game.start_a_new_day
62
+ game.start_a_new_day
63
+ game.start_a_new_day
64
+ end
65
+
66
+ describe "multiple days and players" do
67
+
68
+ [0, 1, 2].each do |day_index|
69
+
70
+ [0, 1].each do |player_index|
71
+
72
+ describe "day #{day_index}" do
73
+
74
+ let(:day) { game.days[day_index] }
75
+
76
+ let(:player) { game.players[player_index] }
77
+
78
+ let(:sales_results) { Struct.new(:profit).new 0 }
79
+
80
+ let(:other_day) { game.days.select { |d| d != day }.first }
81
+ let(:other_player) { game.players.select { |p| p != player }.first }
82
+
83
+ before do
84
+
85
+ other_day.stubs(:sales_for).returns Struct.new(:profit).new(0)
86
+ day.stubs(:sales_for).returns Struct.new(:profit).new(0)
87
+
88
+ # other moves have been made
89
+ game.make_choice Object.new, { player: player, day: other_day }
90
+ game.make_choice Object.new, { player: other_player, day: day }
91
+
92
+ day.stubs(:sales_for).with(choice).returns sales_results
93
+
94
+ end
95
+
96
+ it "should calculate the sales results" do
97
+ game.make_choice choice, { player: player, day: day }
98
+ game.sales_results_for(player, day).must_be_same_as sales_results
99
+ end
100
+
101
+ describe "changing the players assets after the results are made" do
102
+ [
103
+ [200, 100, 300],
104
+ [100, 221, 321],
105
+ ].map { |x| Struct.new(:assets, :profit, :expected).new(*x) }.each do |example|
106
+ describe "multiple examples" do
107
+ before do
108
+ player.assets = example.assets
109
+ sales_results.stubs(:profit).returns example.profit
110
+ day.stubs(:sales_for).with(choice).returns sales_results
111
+ end
112
+ it "should add the profit to the assets" do
113
+ game.make_choice choice, { player: player, day: day }
114
+ player.assets.must_equal example.expected
115
+ end
116
+ end
117
+ end
118
+ end
119
+
120
+ describe "sales results for" do
121
+ it "should not return the same results than the one we just checked" do
122
+ game.make_choice Object.new, { player: player, day: day }
123
+ game.sales_results_for(player, other_day).wont_be_same_as sales_results
124
+ game.sales_results_for(other_player, day).wont_be_same_as sales_results
125
+ end
126
+ end
127
+
128
+ end
129
+
130
+ end
131
+
132
+ end
133
+
134
+ describe "making a choice without defining the day" do
135
+
136
+ let(:game) { LemonadeStand::Game.new 1 }
137
+ let(:choice) { Object.new }
138
+ let(:player) { game.players.first }
139
+
140
+ let(:expected_results) { Struct.new(:profit).new 0 }
141
+
142
+ let(:day) do
143
+ d = Object.new
144
+ d.stubs(:sales_for).returns expected_results
145
+ d
146
+ end
147
+
148
+ before do
149
+ game.stubs(:days).returns Struct.new(:last).new(day)
150
+ end
151
+
152
+ it "should default to using the last day" do
153
+ game.make_choice choice, { player: player }
154
+ game.sales_results_for(player, day).must_be_same_as expected_results
155
+ end
156
+
157
+ end
158
+
159
+ end
160
+
161
+ end
162
+
163
+ describe "days" do
164
+
165
+ let(:game) { LemonadeStand::Game.new 1 }
166
+
167
+ it "should start with no days" do
168
+ game.days.count.must_equal 0
169
+ end
170
+
171
+ describe "start a new day" do
172
+
173
+ it "should create a new day" do
174
+ game.start_a_new_day
175
+ game.days.count.must_equal 1
176
+ game.days.first.is_a?(LemonadeStand::Day).must_equal true
177
+ end
178
+
179
+ it "should return the day" do
180
+ result = game.start_a_new_day
181
+ result.must_be_same_as game.days.first
182
+ end
183
+
184
+ it "should set the day number to 1" do
185
+ game.start_a_new_day
186
+ game.days.first.number.must_equal 1
187
+ end
188
+
189
+ describe "starting a new day" do
190
+ it "should create two new days" do
191
+ game.start_a_new_day
192
+ game.start_a_new_day
193
+ game.days.count.must_equal 2
194
+ game.days.first.is_a?(LemonadeStand::Day).must_equal true
195
+ game.days.last.is_a?(LemonadeStand::Day).must_equal true
196
+ end
197
+
198
+ it "should return the latest day" do
199
+ game.start_a_new_day
200
+ result = game.start_a_new_day
201
+ result.must_be_same_as game.days.last
202
+ end
203
+
204
+ it "should set the day numbers" do
205
+ game.start_a_new_day
206
+ game.start_a_new_day
207
+ game.days.first.number.must_equal 1
208
+ game.days.last.number.must_equal 2
209
+ end
210
+ end
211
+ end
212
+
213
+ end
214
+
215
+ end
@@ -0,0 +1,27 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe LemonadeStand::Player do
4
+
5
+ let(:player) { LemonadeStand::Player.new }
6
+
7
+ it "should default the assets to 200 pennies" do
8
+ player.assets.must_equal 200
9
+ end
10
+
11
+ describe "making a choice" do
12
+
13
+ let(:game) { Object.new }
14
+ let(:choice) { Object.new }
15
+
16
+ before do
17
+ player.game = game
18
+ end
19
+
20
+ it "should pass the choice up to the game" do
21
+ game.expects(:make_choice).with choice, { player: player }
22
+ player.choose choice
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,84 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe LemonadeStand::Result do
4
+
5
+ let(:result) { LemonadeStand::Result.new( { glasses_sold: glasses_sold,
6
+ choice: choice,
7
+ day: day } ) }
8
+ let(:choice) { LemonadeStand::Choice.new }
9
+ let(:day) { LemonadeStand::Day.new }
10
+ let(:glasses_sold) { nil }
11
+
12
+ describe "expenses" do
13
+ [
14
+ [1, 2, 0, 2],
15
+ [1, 2, 2, 32],
16
+ [2, 2, 0, 4],
17
+ [3, 4, 0, 12],
18
+ [3, 4, 1, 27],
19
+ [50, 15, 9, 885],
20
+ [1.001, 2, 0, 2],
21
+ ].map { |x| Struct.new(:cost_per_glass, :glasses_made, :signs, :expected).new(*x) }.each do |example|
22
+
23
+ describe "multiple examples" do
24
+
25
+ before do
26
+ choice.signs = example.signs
27
+ choice.glasses_made = example.glasses_made
28
+ day.stubs(:cost_per_glass).returns example.cost_per_glass
29
+ end
30
+
31
+ it "should be the cost per glass times the number of glasses made" do
32
+ result.expenses.must_equal example.expected
33
+ end
34
+
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ describe "income" do
42
+ [
43
+ [1, 2, 2],
44
+ [2, 2, 4],
45
+ [3, 8, 24],
46
+ [3, 8.0001, 24],
47
+ ].map { |x| Struct.new(:price_per_glass, :glasses_sold, :expected).new(*x) }.each do |example|
48
+
49
+ describe "multiple examples" do
50
+
51
+ let(:glasses_sold) { example.glasses_sold }
52
+
53
+ before do
54
+ choice.price_per_glass = example.price_per_glass
55
+ end
56
+
57
+ it "should be the price of the glass " do
58
+ result.income.must_equal example.expected
59
+ end
60
+
61
+ end
62
+
63
+ end
64
+ end
65
+
66
+ describe "profit" do
67
+ [
68
+ [200, 100, 100],
69
+ [401, 500, -99],
70
+ [400.001, 500, -100],
71
+ ].map { |x| Struct.new(:income, :expenses, :expected).new *x }.each do |example|
72
+ describe "so many tests" do
73
+ before do
74
+ result.stubs(:income).returns example.income
75
+ result.stubs(:expenses).returns example.expenses
76
+ end
77
+ it "should be the income minus expenses" do
78
+ result.profit.must_equal example.expected
79
+ end
80
+ end
81
+ end
82
+ end
83
+
84
+ end
@@ -0,0 +1,70 @@
1
+ require_relative '../spec_helper'
2
+
3
+ describe LemonadeStand::Weather do
4
+
5
+ describe "weather for a day" do
6
+
7
+ let(:day) { Object.new }
8
+
9
+ (1..2).to_a.each do |day_number|
10
+ describe "and the day is #{day_number}" do
11
+ before { day.stubs(:number).returns day_number }
12
+ it "should return that the day is sunny" do
13
+ result = LemonadeStand::Weather.weather_for day
14
+ result.sunny?.must_equal true
15
+ result.cloudy?.must_equal false
16
+ result.hot_and_dry?.must_equal false
17
+ end
18
+ end
19
+ end
20
+
21
+ (3..10).to_a.each do |day_number|
22
+ describe "and the day is #{day_number}" do
23
+ before { day.stubs(:number).returns day_number }
24
+ (1..5).each do |random_value|
25
+ describe "random 0-9 is #{random_value}" do
26
+ before { LemonadeStand::Weather.stubs(:rand).returns random_value }
27
+ it "should be sunny" do
28
+ result = LemonadeStand::Weather.weather_for day
29
+ result.cloudy?.must_equal false
30
+ result.sunny?.must_equal true
31
+ result.hot_and_dry?.must_equal false
32
+ end
33
+ end
34
+ end
35
+ (6..7).each do |random_value|
36
+ describe "random 0-9 is #{random_value}" do
37
+ before { LemonadeStand::Weather.stubs(:rand).returns random_value }
38
+ it "should be cloudy" do
39
+ result = LemonadeStand::Weather.weather_for day
40
+ result.cloudy?.must_equal true
41
+ result.sunny?.must_equal false
42
+ result.hot_and_dry?.must_equal false
43
+ end
44
+ end
45
+ end
46
+ (8..9).each do |random_value|
47
+ describe "random 0-9 is #{random_value}" do
48
+ before { LemonadeStand::Weather.stubs(:rand).returns random_value }
49
+ it "should be cloudy" do
50
+ result = LemonadeStand::Weather.weather_for day
51
+ result.cloudy?.must_equal false
52
+ result.sunny?.must_equal false
53
+ result.hot_and_dry?.must_equal true
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ describe "to string" do
62
+ it "should return the type as a capitalized string" do
63
+ LemonadeStand::Weather.new(:sunny).to_s.must_equal "Sunny"
64
+ LemonadeStand::Weather.new(:rainy).to_s.must_equal "Rainy"
65
+ LemonadeStand::Weather.new('stormy').to_s.must_equal "Stormy"
66
+ LemonadeStand::Weather.new(:hot_and_dry).to_s.must_equal "Hot and Dry"
67
+ end
68
+ end
69
+
70
+ end
@@ -0,0 +1,4 @@
1
+ require_relative '../lib/lemonade_stand'
2
+ require 'minitest/autorun'
3
+ require 'minitest/spec'
4
+ require 'mocha/setup'
metadata ADDED
@@ -0,0 +1,141 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lemonade_stand
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Darren Cauthon
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-03-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: money
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.7'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.7'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '10.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '10.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mocha
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: This is a ruby implementation of the old Lemonade Stand game.
70
+ email:
71
+ - darren@cauthon.com
72
+ executables:
73
+ - play_ls
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - .gitignore
78
+ - Gemfile
79
+ - LICENSE.txt
80
+ - README.md
81
+ - Rakefile
82
+ - bin/play_ls
83
+ - lemonade_stand.gemspec
84
+ - lib/lemonade_stand.rb
85
+ - lib/lemonade_stand/choice.rb
86
+ - lib/lemonade_stand/day.rb
87
+ - lib/lemonade_stand/display.rb
88
+ - lib/lemonade_stand/event.rb
89
+ - lib/lemonade_stand/events/heat_wave_event.rb
90
+ - lib/lemonade_stand/events/normal_event.rb
91
+ - lib/lemonade_stand/events/rain_event.rb
92
+ - lib/lemonade_stand/events/storm_event.rb
93
+ - lib/lemonade_stand/events/street_work_event.rb
94
+ - lib/lemonade_stand/game.rb
95
+ - lib/lemonade_stand/player.rb
96
+ - lib/lemonade_stand/result.rb
97
+ - lib/lemonade_stand/version.rb
98
+ - lib/lemonade_stand/weather.rb
99
+ - spec/lemonade_stand/choice_spec.rb
100
+ - spec/lemonade_stand/day_spec.rb
101
+ - spec/lemonade_stand/display_spec.rb
102
+ - spec/lemonade_stand/event_spec.rb
103
+ - spec/lemonade_stand/game_spec.rb
104
+ - spec/lemonade_stand/player_spec.rb
105
+ - spec/lemonade_stand/result_spec.rb
106
+ - spec/lemonade_stand/weather_spec.rb
107
+ - spec/spec_helper.rb
108
+ homepage: ''
109
+ licenses:
110
+ - MIT
111
+ metadata: {}
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - '>='
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.4.5
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: The Lemonade Stand game.
132
+ test_files:
133
+ - spec/lemonade_stand/choice_spec.rb
134
+ - spec/lemonade_stand/day_spec.rb
135
+ - spec/lemonade_stand/display_spec.rb
136
+ - spec/lemonade_stand/event_spec.rb
137
+ - spec/lemonade_stand/game_spec.rb
138
+ - spec/lemonade_stand/player_spec.rb
139
+ - spec/lemonade_stand/result_spec.rb
140
+ - spec/lemonade_stand/weather_spec.rb
141
+ - spec/spec_helper.rb