From 096b891755cb4c222971bc789e40031f7783f5d2 Mon Sep 17 00:00:00 2001 From: Coral Date: Wed, 11 Dec 2024 13:00:38 -0500 Subject: [PATCH 1/5] iteration 1: all tests passing --- lib/player.rb | 23 +++++++++++++++++++++++ spec/player_spec.rb | 3 ++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/player.rb b/lib/player.rb index e69de29..0fb586c 100644 --- a/lib/player.rb +++ b/lib/player.rb @@ -0,0 +1,23 @@ +class Player + attr_reader :name, :monthly_cost, :contract_length + + def initialize(name, monthly_cost, contract_length) + @name = name + @monthly_cost = monthly_cost + @contract_length = contract_length + end + + def first_name + name_array = @name.split + return name_array[0] + end + + def last_name + name_array = @name.split + return name_array[1] + end + + def total_cost + @monthly_cost * @contract_length + end +end \ No newline at end of file diff --git a/spec/player_spec.rb b/spec/player_spec.rb index 016ff62..f890124 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -1,4 +1,5 @@ require 'rspec' +require './lib/player' RSpec.describe Player do it 'exists' do @@ -34,6 +35,6 @@ it 'has a total cost' do player = Player.new("Michael Palledorous" , 1000000, 36) - expect(player.total_costg).to eq(36000000) + expect(player.total_cost).to eq(36000000) end end \ No newline at end of file From b4f8ab2a766550fd06fa9e1dd7cf3d283090f947 Mon Sep 17 00:00:00 2001 From: Coral Date: Wed, 11 Dec 2024 13:20:52 -0500 Subject: [PATCH 2/5] iteration 2: all tests passing --- lib/team.rb | 17 ++++++++++++++ spec/team_spec.rb | 60 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100644 spec/team_spec.rb diff --git a/lib/team.rb b/lib/team.rb index e69de29..15df333 100644 --- a/lib/team.rb +++ b/lib/team.rb @@ -0,0 +1,17 @@ +class Team + attr_reader :name, :location, :roster + + def initialize(name, location) + @name = name + @location = location + @roster = [] + end + + def player_count + @roster.count + end + + def add_player(player) + @roster << player + end +end \ No newline at end of file diff --git a/spec/team_spec.rb b/spec/team_spec.rb new file mode 100644 index 0000000..8f2c438 --- /dev/null +++ b/spec/team_spec.rb @@ -0,0 +1,60 @@ +require 'rspec' +require './lib/player' +require './lib/team' + +RSpec.describe Team do + it 'exists' do + team = Team.new("Dodgers", "Los Angeles") + + expect(team).to be_a Team + end + + it 'has a name' do + team = Team.new("Dodgers", "Los Angeles") + + expect(team.name).to eq("Dodgers") + end + + it 'has a location' do + team = Team.new("Dodgers", "Los Angeles") + + expect(team.location).to eq("Los Angeles") + end + + describe '#roster'do + it 'defaults an empty array' do + team = Team.new("Dodgers", "Los Angeles") + + expect(team.roster).to eq([]) + end + + it 'counts 0 as default' do + team = Team.new("Dodgers", "Los Angeles") + + expect(team.player_count).to eq(0) + end + + it 'can add_player' do + team = Team.new("Dodgers", "Los Angeles") + player_1 = Player.new("Michael Palledorous" , 1000000, 36) + player_2 = Player.new("Kenny DeNunez", 500000, 24) + + team.add_player(player_1) + team.add_player(player_2) + + expect(team.roster).to eq([player_1, player_2]) + end + + it 'can accurately count with players in roster' do + team = Team.new("Dodgers", "Los Angeles") + player_1 = Player.new("Michael Palledorous" , 1000000, 36) + player_2 = Player.new("Kenny DeNunez", 500000, 24) + + team.add_player(player_1) + team.add_player(player_2) + + expect(team.player_count).to eq(2) + end + end +end + From 5ecbc943d5ca1f2669ff7e4e0c300ed73bd94ede Mon Sep 17 00:00:00 2001 From: Coral Date: Wed, 11 Dec 2024 13:43:20 -0500 Subject: [PATCH 3/5] iteration 3: tests created --- README.md | 2 +- spec/team_spec.rb | 45 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index a46d02d..2644364 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ replaced any attributes with `...` for readability.) Notes: Contract length is in months, and the total cost is the contract length multiplied by the monthly cost. ```ruby -pry(main)> require './lib/player' +pry(main)> require git #=> true pry(main)> player = Player.new("Michael Palledorous" , 1000000, 36) diff --git a/spec/team_spec.rb b/spec/team_spec.rb index 8f2c438..1257635 100644 --- a/spec/team_spec.rb +++ b/spec/team_spec.rb @@ -56,5 +56,50 @@ expect(team.player_count).to eq(2) end end + + it 'creates array of long_term_players' do + team = Team.new("Dodgers", "Los Angeles") + player_1 = Player.new("Michael Palledorous" , 1000000, 36) + player_2 = Player.new("Kenny DeNunez", 500000, 24) + player_3 = Player.new("Alan McClennan", 750000, 48) + player_4 = Player.new("Hamilton Porter", 100000, 12) + + team.add_player(player_1) + team.add_player(player_2) + team.add_player(player_3) + team.add_player(player_4) + + expect(team.long_term_players).to eq([player_1, player_3]) + end + + it 'creates array of short_term_players' do + team = Team.new("Dodgers", "Los Angeles") + player_1 = Player.new("Michael Palledorous" , 1000000, 36) + player_2 = Player.new("Kenny DeNunez", 500000, 24) + player_3 = Player.new("Alan McClennan", 750000, 48) + player_4 = Player.new("Hamilton Porter", 100000, 12) + + team.add_player(player_1) + team.add_player(player_2) + team.add_player(player_3) + team.add_player(player_4) + + expect(team.short_term_players).to eq([player_2, player_4]) + end + + it 'accurately determines total cost of player contracts' do + team = Team.new("Dodgers", "Los Angeles") + player_1 = Player.new("Michael Palledorous" , 1000000, 36) + player_2 = Player.new("Kenny DeNunez", 500000, 24) + player_3 = Player.new("Alan McClennan", 750000, 48) + player_4 = Player.new("Hamilton Porter", 100000, 12) + + team.add_player(player_1) + team.add_player(player_2) + team.add_player(player_3) + team.add_player(player_4) + + expect(team.total_value).to eq(85200000) + end end From 7407696c3e5db376fa7ac0129d13f78fff1cb4f8 Mon Sep 17 00:00:00 2001 From: Coral Date: Wed, 11 Dec 2024 13:53:56 -0500 Subject: [PATCH 4/5] iteration 3: team updates pass testing --- lib/team.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/lib/team.rb b/lib/team.rb index 15df333..89ebe60 100644 --- a/lib/team.rb +++ b/lib/team.rb @@ -14,4 +14,32 @@ def player_count def add_player(player) @roster << player end + + def long_term_players + long_term = [] + @roster.each do |player| + if player.contract_length > 24 + long_term << player + end + end + return long_term + end + + def short_term_players + short_term = [] + @roster.each do |player| + if player.contract_length <= 24 + short_term << player + end + end + return short_term + end + + def total_value + payroll = 0 + @roster.each do |player| + payroll += player.total_cost + end + return payroll + end end \ No newline at end of file From b27381fb569eccea287c9a90b6c7bf5036474aaf Mon Sep 17 00:00:00 2001 From: Coral Date: Wed, 11 Dec 2024 14:01:25 -0500 Subject: [PATCH 5/5] Iteration 3: Pt 2 Tests Updated --- spec/player_spec.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/spec/player_spec.rb b/spec/player_spec.rb index f890124..ac2083d 100644 --- a/spec/player_spec.rb +++ b/spec/player_spec.rb @@ -37,4 +37,19 @@ expect(player.total_cost).to eq(36000000) end + + describe '#nickname' do + it 'defaults to nil' do + player = Player.new("Michael Palledorous" , 1000000, 36) + + expect(player.nickname).to eq(nil) + end + + it 'sets & reads nickname' + player = Player.new("Michael Palledorous" , 1000000, 36) + + player.set_nickname!("Squints") + + expect(player.nickname).to eq("Squints") + end end \ No newline at end of file