Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 0 additions & 56 deletions GemCity.rb

This file was deleted.

49 changes: 49 additions & 0 deletions gem_city.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# This class represents the town of GemCity
# This is a town riddled with crime but we can find out how happy the town is
class GemCity
attr_reader :population

def initialize
@people = {
thieves: 5,
officers: 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although Rubocop doesn't complain about it, this class could be simplified a bunch by dropping this hash and using @theives & @officers.

}
@population = 50
end

def thieves(thieves_number = @people[:thieves])
@people[:thieves] = thieves_number
end

def officers
@people[:officers]
end

def officers=(officers)
@people[:officers] = officers
end
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mikegee @gwadej @jaybobo I did not change this to the default setter. I'm not supposed to do so right? I will need to change the call in the spec as well.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once you use the attr_accessor form, this doesn't do anything new. (It also does two different things, so is probably a bad method.

I would change the test to use theives= so that the attribute handling is consistent.


def happiness_of_town
# happiness is random... people don't know what they want!
happiness_vals = []
happiness = 0
(1..@population).each do
happiness_vals.push(rand((100 - successful_crime_rate)..100))
end
happiness_vals.each do |value|
happiness += value
end
happiness / 100
end

def successful_crime_rate
thieves = @people[:thieves]
officers = @people[:officers]
odds_percent = 0
if thieves > 0 && officers <= thieves
odds = 1 - officers.to_f / thieves.to_f
odds_percent = odds * 100
end
odds_percent
end
end
6 changes: 3 additions & 3 deletions gem_city_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require 'rspec'
require_relative 'GemCity' # This line may need to be changed
require_relative 'gem_city' # This line may need to be changed

describe 'Gem City' do
let(:city) { GemCity.new }
Expand All @@ -16,7 +16,7 @@

it 'officers = thieves' do
city.thieves 1
city.setOfficers 1 # This line may need to be changed
city.officers=1 # This line may need to be changed
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm surprised Rubocop didn't make you put spaces around this =.

expect(city.successful_crime_rate).to eq(0)
end

Expand All @@ -27,7 +27,7 @@

it 'officers > thieves' do
city.thieves 1
city.setOfficers 2 # This line may need to be changed
city.officers=2 # This line may need to be changed
expect(city.successful_crime_rate).to eq(0)
end
end
Expand Down