Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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.

3 changes: 2 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'

gem 'rubocop', require: false
gem 'rspec'
gem 'rspec'
gem 'pry'
11 changes: 11 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ GEM
ast (2.0.0)
astrolabe (1.3.1)
parser (~> 2.2)
coderay (1.1.1)
diff-lcs (1.2.5)
method_source (0.8.2)
parser (2.2.2.6)
ast (>= 1.1, < 3.0)
powerpack (0.1.1)
pry (0.10.3)
coderay (~> 1.1.0)
method_source (~> 0.8.1)
slop (~> 3.4)
rainbow (2.0.0)
rspec (3.3.0)
rspec-core (~> 3.3.0)
Expand All @@ -29,10 +35,15 @@ GEM
rainbow (>= 1.99.1, < 3.0)
ruby-progressbar (~> 1.4)
ruby-progressbar (1.7.5)
slop (3.6.0)

PLATFORMS
ruby

DEPENDENCIES
pry
rspec
rubocop

BUNDLED WITH
1.11.2
48 changes: 48 additions & 0 deletions gem_city.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# 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
attr_accessor :thieves, :officers

def initialize
@thieves = 5
@officers = 1
@population = 50
end

def civilians
@population - @officers - @thieves
end

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
return 0 if @thieves <= 0 || @officers > @thieves
odds = 1 - @officers.to_f / @thieves.to_f
odds * 100
end

def city_demographics
{ thieves: percentage(@thieves),
officers: percentage(@officers),
civilians: percentage(civilians)
}
end

private

def percentage(number_in_group)
"#{(100.0 * number_in_group / @population).round}%"
end
end
49 changes: 25 additions & 24 deletions gem_city_spec.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'rspec'
require_relative 'GemCity' # This line may need to be changed
require 'pry'
require_relative 'gem_city' # This line may need to be changed

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

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

it 'thieves = 0' do
city.thieves 0
city.thieves = 0
expect(city.successful_crime_rate).to eq(0)
end

it 'officers > thieves' do
city.thieves 1
city.setOfficers 2 # This line may need to be changed
city.thieves = 1
city.officers = 2 # This line may need to be changed
expect(city.successful_crime_rate).to eq(0)
end
end
Expand All @@ -38,26 +39,26 @@
end

it 'successful_crime_rate = 0' do
city.thieves 0
city.thieves = 0
expect(city.happiness_of_town).to eq(50)
end
end

# context 'city_demographics' do
# it 'initialize' do
# demographics = city.city_demographics
# expect(demographics[:thieves]).to eq('10%')
# expect(demographics[:officers]).to eq('2%')
# expect(demographics[:civilians]).to eq('88%')
# end

# it 'thieves = 10, officers = 25' do
# city.thieves = 10
# city.officers = 25
# demographics = city.city_demographics
# expect(demographics[:thieves]).to eq('20%')
# expect(demographics[:officers]).to eq('50%')
# expect(demographics[:civilians]).to eq('30%')
# end
# end
context 'city_demographics' do
it 'initialize' do
demographics = city.city_demographics
expect(demographics[:thieves]).to eq('10%')
expect(demographics[:officers]).to eq('2%')
expect(demographics[:civilians]).to eq('88%')
end

it 'thieves = 10, officers = 25' do
city.thieves = 10
city.officers = 25
demographics = city.city_demographics
expect(demographics[:thieves]).to eq('20%')
expect(demographics[:officers]).to eq('50%')
expect(demographics[:civilians]).to eq('30%')
end
end
end