From f5f13afb43e96b224fa46983f9cf602d369fbd75 Mon Sep 17 00:00:00 2001 From: Aaron Dawson Date: Thu, 7 Jan 2016 16:33:03 -0500 Subject: [PATCH] no failures and no offenses --- .DS_Store | Bin 0 -> 6148 bytes GemCity.rb | 56 ----------------------------------------------- Gemfile | 2 +- gem_city.rb | 47 +++++++++++++++++++++++++++++++++++++++ gem_city_spec.rb | 6 ++--- 5 files changed, 51 insertions(+), 60 deletions(-) create mode 100644 .DS_Store delete mode 100644 GemCity.rb create mode 100644 gem_city.rb diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 5, - :Officers => 1}, - 50 - end - - def thieves thieves_number=@people[:thieves] - return @people[:thieves] = thieves_number - end - - def officers - return @people[:Officers] - end - - def population; return @population; end - - def setOfficers officers - @people[:Officers] = officers - end - - def happiness_of_town - #happiness is random... people don't know what they want! - happinessVals = Array.new - happiness = 0 - for index in (1..@population) - happinessVals.push(rand((100 - successful_crime_rate) .. 100)) - index += 1 - end - happinessVals.each do |value| - happiness += value - end - return happiness / 100 - end - - def successful_crime_rate - thieves = @people[:thieves] - officers = @people[:Officers] - if thieves <= 0 - odds_percent = 0 - elsif officers > thieves - odds_percent = 0 - else - odds = 1 \ - - officers.to_f / thieves.to_f - odds_percent = odds * 100 - end - return odds_percent - end -end \ No newline at end of file diff --git a/Gemfile b/Gemfile index 94b6f8c..6fd63b3 100644 --- a/Gemfile +++ b/Gemfile @@ -1,4 +1,4 @@ source 'https://rubygems.org' gem 'rubocop', require: false -gem 'rspec' \ No newline at end of file +gem 'rspec' diff --git a/gem_city.rb b/gem_city.rb new file mode 100644 index 0000000..0bae080 --- /dev/null +++ b/gem_city.rb @@ -0,0 +1,47 @@ +# 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 } + @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 + + 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] + if thieves <= 0 || officers > thieves + odds_percent = 0 + else + odds = 1 - officers.to_f / thieves.to_f + odds_percent = odds * 100 + end + odds_percent + end +end diff --git a/gem_city_spec.rb b/gem_city_spec.rb index 884b3cb..3433322 100644 --- a/gem_city_spec.rb +++ b/gem_city_spec.rb @@ -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 } @@ -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 expect(city.successful_crime_rate).to eq(0) end @@ -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