From 06e7f3f22341193e3a81bb6a13793a2705f3975c Mon Sep 17 00:00:00 2001 From: Lilly Piri Date: Fri, 17 Mar 2017 15:37:34 +1000 Subject: [PATCH 1/3] Added age method and can drink check. --- models/human.rb | 213 +++++++++++++++++++++++++++++++++++++ specs/models/human_spec.rb | 40 ++++++- 2 files changed, 251 insertions(+), 2 deletions(-) diff --git a/models/human.rb b/models/human.rb index 92c6c1a..194b4f8 100644 --- a/models/human.rb +++ b/models/human.rb @@ -25,5 +25,218 @@ def job_title=(value) def job_title @job_title end + +attr_accessor :age + + # def age=(value) + # @age = value + # end + # + # def age + # @age + # end + + def can_drink? (country = "Australia") + @age >= AGES[country] + end end + +AGES = { + 'Benin' => 0, + 'Bolivia' => 0, + 'Burkina Faso' => 0, + 'Burundi' => 0, + 'Cambodia' => 0, + 'Cameroon' => 0, + 'China' => 0, + 'Gabon' => 0, + 'Guinea-Bissau' => 0, + 'Indonesia' => 0, + 'Kosovo' => 0, + 'Laos' => 0, + 'Mali' => 0, + 'Rwanda' => 0, + 'Sao Tome and Principe' => 0, + 'Sierra Leone' => 0, + 'Solomon Islands' => 0, + 'Timor-Leste' => 0, + 'Togo' => 0, + + 'Antigua and Barbuda' => 10, + 'Central African Republic' => 10, + + 'Austria' => 16, + 'Belgium' => 16, + 'Congo' => 16, + 'Cyprus' => 16, + 'Denmark' => 16, + 'Dominica' => 16, + 'Germany' => 16, + 'Grenada' => 16, + 'Guyana' => 16, + 'Haiti' => 16, + 'Liechtenstein' => 16, + 'Luxembourg' => 16, + 'Malta' => 16, + 'Morocco' => 16, + 'Netherlands' => 16, + 'Portugal' => 16, + 'Saint Lucia' => 16, + 'Saint Vincent and the Grenadines' => 16, + 'San Marino' => 16, + 'Spain' => 16, + 'Switzerland' => 16, + + 'Albania' => 18, + 'Algeria' => 18, + 'Andorra' => 18, + 'Angola' => 18, + 'Argentina' => 18, + 'Armenia' => 18, + 'Australia' => 18, + 'Azerbaijan' => 18, + 'Bahamas' => 18, + 'Barbados' => 18, + 'Belarus' => 18, + 'Belize' => 18, + 'Bhutan' => 18, + 'Bosnia and Herzegovina' => 18, + 'Botswana' => 18, + 'Brazil' => 18, + 'Bulgaria' => 18, + 'Canada' => 18, + 'Cape Verde' => 18, + 'Chad' => 18, + 'Chile' => 18, + 'Colombia' => 18, + 'Comoros' => 18, + 'Costa Rica' => 18, + 'Croatia' => 18, + 'Cuba' => 18, + 'Czech Republic' => 18, + 'Democratic Republic of the Congo' => 18, + 'Dominican Republic' => 18, + 'Ecuador' => 18, + 'Egypt' => 18, + 'El Salvador' => 18, + 'Eritrea' => 18, + 'Estonia' => 18, + 'Ethiopia' => 18, + 'Fiji' => 18, + 'Finland' => 18, + 'France' => 18, + 'Gambia' => 18, + 'Georgia' => 18, + 'Ghana' => 18, + 'Greece' => 18, + 'Guatemala' => 18, + 'Guinea' => 18, + 'Honduras' => 18, + 'Hungary' => 18, + 'India' => 18, + 'Ireland' => 18, + 'Israel' => 18, + 'Italy' => 18, + 'Jamaica' => 18, + 'Jordan' => 18, + 'Kazakhstan' => 18, + 'Kenya' => 18, + 'Kyrgyzstan' => 18, + 'Latvia' => 18, + 'Lesotho' => 18, + 'Liberia' => 18, + 'Lithuania' => 18, + 'Macedonia' => 18, + 'Madagascar' => 18, + 'Malawi' => 18, + 'Malaysia' => 18, + 'Mauritius' => 18, + 'Mexico' => 18, + 'Moldova' => 18, + 'Monaco' => 18, + 'Montenegro' => 18, + 'Mozambique' => 18, + 'Myanmar' => 18, + 'Namibia' => 18, + 'Nepal' => 18, + 'New Zealand' => 18, + 'Nicaragua' => 18, + 'Niger' => 18, + 'Nigeria' => 18, + 'Norway' => 18, + 'Panama' => 18, + 'Papua New Guinea' => 18, + 'Peru' => 18, + 'Philippines' => 18, + 'Poland' => 18, + 'Romania' => 18, + 'Russia' => 18, + 'Saint Kitts and Nevis' => 18, + 'Senegal' => 18, + 'Serbia' => 18, + 'Seychelles' => 18, + 'Singapore' => 18, + 'Slovakia' => 18, + 'Slovenia' => 18, + 'South Africa' => 18, + 'South Korea' => 18, + 'Suriname' => 18, + 'Swaziland' => 18, + 'Sweden' => 18, + 'Syria' => 18, + 'Tajikistan' => 18, + 'Tanzania' => 18, + 'Tonga' => 18, + 'Trinidad and Tobago' => 18, + 'Tunisia' => 18, + 'Turkey' => 18, + 'Turkmenistan' => 18, + 'Tuvalu' => 18, + 'Uganda' => 18, + 'Ukraine' => 18, + 'United Kingdom' => 18, + 'Uruguay' => 18, + 'Vanuatu' => 18, + 'Vatican City' => 18, + 'Venezuela' => 18, + 'Vietnam' => 18, + 'Zambia' => 18, + 'Zimbabwe' => 18, + + 'Iceland' => 20, + 'Japan' => 20, + 'Paraguay' => 20, + 'Thailand' => 20, + 'Uzbekistan' => 20, + + 'Côte d\'Ivoire' => 21, + 'Equatorial Guinea' => 21, + 'Iraq' => 21, + 'Kiribati' => 21, + 'Micronesia' => 21, + 'Mongolia' => 21, + 'Nauru' => 21, + 'Oman' => 21, + 'Palau' => 21, + 'Samoa' => 21, + 'Sri Lanka' => 21, + 'United States' => 21, + + 'Afghanistan' => 999, + 'Bahrain' => 999, + 'Bangladesh' => 999, + 'Brunei Darussalam' => 999, + 'Iran' => 999, + 'Kuwait' => 999, + 'Libya' => 999, + 'Maldives' => 999, + 'Mauritania' => 999, + 'Pakistan' => 999, + 'Qatar' => 999, + 'Saudi Arabia' => 999, + 'Somalia' => 999, + 'Sudan' => 999, + 'United Arab Emirates' => 999, + 'Yemen' => 999 +} diff --git a/specs/models/human_spec.rb b/specs/models/human_spec.rb index e0f705d..1ba679a 100644 --- a/specs/models/human_spec.rb +++ b/specs/models/human_spec.rb @@ -39,9 +39,45 @@ end end + describe '.age=' do + it 'sets the age for our human instance' do + human = Human.new('') + expect(human).to respond_to(:age=) + end + end + + describe '.age' do + it 'it returns the age' do + human = Human.new('') + human.age = 18 + expect(human.age).to eq(18) + end + end + + describe '.can_drink?' do + it 'returns true if human is of age' do + human = Human.new('Boris') + human.age = 35 + expect(human.can_drink?).to be true + end + + it 'returns false if human is underage' do + human = Human.new('Boris Jr') + human.age = 14 + expect(human.can_drink?).to be false + + end + + it 'checks the drinking age for a given country' do + human = Human.new('Garfield') + human.age = 18 + expect(human.can_drink? 'Australia').to be true + expect(human.can_drink? 'United States').to be false + end + end + + it 'play area' do puts Human.new('Caitlin').name end end - - From b0a24ce3797f04e2d8b05a285ab9dbf65662c665 Mon Sep 17 00:00:00 2001 From: Lilly Piri Date: Sat, 18 Mar 2017 16:43:34 +1000 Subject: [PATCH 2/3] added more tests and split out countries to a new class --- models/country.rb | 210 +++++++++++++++++++++++++++++++++++++ models/human.rb | 206 +----------------------------------- specs/models/human_spec.rb | 13 ++- 3 files changed, 226 insertions(+), 203 deletions(-) create mode 100644 models/country.rb diff --git a/models/country.rb b/models/country.rb new file mode 100644 index 0000000..cd44b4f --- /dev/null +++ b/models/country.rb @@ -0,0 +1,210 @@ +class Country + def initialize (country) + @country = country + end + + def drinking_age + return 999 unless AGES.include? @country + AGES[@country] + end + + + AGES = { + 'Benin' => 0, + 'Bolivia' => 0, + 'Burkina Faso' => 0, + 'Burundi' => 0, + 'Cambodia' => 0, + 'Cameroon' => 0, + 'China' => 0, + 'Gabon' => 0, + 'Guinea-Bissau' => 0, + 'Indonesia' => 0, + 'Kosovo' => 0, + 'Laos' => 0, + 'Mali' => 0, + 'Rwanda' => 0, + 'Sao Tome and Principe' => 0, + 'Sierra Leone' => 0, + 'Solomon Islands' => 0, + 'Timor-Leste' => 0, + 'Togo' => 0, + + 'Antigua and Barbuda' => 10, + 'Central African Republic' => 10, + + 'Austria' => 16, + 'Belgium' => 16, + 'Congo' => 16, + 'Cyprus' => 16, + 'Denmark' => 16, + 'Dominica' => 16, + 'Germany' => 16, + 'Grenada' => 16, + 'Guyana' => 16, + 'Haiti' => 16, + 'Liechtenstein' => 16, + 'Luxembourg' => 16, + 'Malta' => 16, + 'Morocco' => 16, + 'Netherlands' => 16, + 'Portugal' => 16, + 'Saint Lucia' => 16, + 'Saint Vincent and the Grenadines' => 16, + 'San Marino' => 16, + 'Spain' => 16, + 'Switzerland' => 16, + + 'Albania' => 18, + 'Algeria' => 18, + 'Andorra' => 18, + 'Angola' => 18, + 'Argentina' => 18, + 'Armenia' => 18, + 'Australia' => 18, + 'Azerbaijan' => 18, + 'Bahamas' => 18, + 'Barbados' => 18, + 'Belarus' => 18, + 'Belize' => 18, + 'Bhutan' => 18, + 'Bosnia and Herzegovina' => 18, + 'Botswana' => 18, + 'Brazil' => 18, + 'Bulgaria' => 18, + 'Canada' => 18, + 'Cape Verde' => 18, + 'Chad' => 18, + 'Chile' => 18, + 'Colombia' => 18, + 'Comoros' => 18, + 'Costa Rica' => 18, + 'Croatia' => 18, + 'Cuba' => 18, + 'Czech Republic' => 18, + 'Democratic Republic of the Congo' => 18, + 'Dominican Republic' => 18, + 'Ecuador' => 18, + 'Egypt' => 18, + 'El Salvador' => 18, + 'Eritrea' => 18, + 'Estonia' => 18, + 'Ethiopia' => 18, + 'Fiji' => 18, + 'Finland' => 18, + 'France' => 18, + 'Gambia' => 18, + 'Georgia' => 18, + 'Ghana' => 18, + 'Greece' => 18, + 'Guatemala' => 18, + 'Guinea' => 18, + 'Honduras' => 18, + 'Hungary' => 18, + 'India' => 18, + 'Ireland' => 18, + 'Israel' => 18, + 'Italy' => 18, + 'Jamaica' => 18, + 'Jordan' => 18, + 'Kazakhstan' => 18, + 'Kenya' => 18, + 'Kyrgyzstan' => 18, + 'Latvia' => 18, + 'Lesotho' => 18, + 'Liberia' => 18, + 'Lithuania' => 18, + 'Macedonia' => 18, + 'Madagascar' => 18, + 'Malawi' => 18, + 'Malaysia' => 18, + 'Mauritius' => 18, + 'Mexico' => 18, + 'Moldova' => 18, + 'Monaco' => 18, + 'Montenegro' => 18, + 'Mozambique' => 18, + 'Myanmar' => 18, + 'Namibia' => 18, + 'Nepal' => 18, + 'New Zealand' => 18, + 'Nicaragua' => 18, + 'Niger' => 18, + 'Nigeria' => 18, + 'Norway' => 18, + 'Panama' => 18, + 'Papua New Guinea' => 18, + 'Peru' => 18, + 'Philippines' => 18, + 'Poland' => 18, + 'Romania' => 18, + 'Russia' => 18, + 'Saint Kitts and Nevis' => 18, + 'Senegal' => 18, + 'Serbia' => 18, + 'Seychelles' => 18, + 'Singapore' => 18, + 'Slovakia' => 18, + 'Slovenia' => 18, + 'South Africa' => 18, + 'South Korea' => 18, + 'Suriname' => 18, + 'Swaziland' => 18, + 'Sweden' => 18, + 'Syria' => 18, + 'Tajikistan' => 18, + 'Tanzania' => 18, + 'Tonga' => 18, + 'Trinidad and Tobago' => 18, + 'Tunisia' => 18, + 'Turkey' => 18, + 'Turkmenistan' => 18, + 'Tuvalu' => 18, + 'Uganda' => 18, + 'Ukraine' => 18, + 'United Kingdom' => 18, + 'Uruguay' => 18, + 'Vanuatu' => 18, + 'Vatican City' => 18, + 'Venezuela' => 18, + 'Vietnam' => 18, + 'Zambia' => 18, + 'Zimbabwe' => 18, + + 'Iceland' => 20, + 'Japan' => 20, + 'Paraguay' => 20, + 'Thailand' => 20, + 'Uzbekistan' => 20, + + 'Côte d\'Ivoire' => 21, + 'Equatorial Guinea' => 21, + 'Iraq' => 21, + 'Kiribati' => 21, + 'Micronesia' => 21, + 'Mongolia' => 21, + 'Nauru' => 21, + 'Oman' => 21, + 'Palau' => 21, + 'Samoa' => 21, + 'Sri Lanka' => 21, + 'United States' => 21, + + 'Afghanistan' => 999, + 'Bahrain' => 999, + 'Bangladesh' => 999, + 'Brunei Darussalam' => 999, + 'Iran' => 999, + 'Kuwait' => 999, + 'Libya' => 999, + 'Maldives' => 999, + 'Mauritania' => 999, + 'Pakistan' => 999, + 'Qatar' => 999, + 'Saudi Arabia' => 999, + 'Somalia' => 999, + 'Sudan' => 999, + 'United Arab Emirates' => 999, + 'Yemen' => 999 + } +end diff --git a/models/human.rb b/models/human.rb index 194b4f8..a7b7cd0 100644 --- a/models/human.rb +++ b/models/human.rb @@ -1,3 +1,5 @@ +require_relative 'country' + class Human def initialize value @@ -37,206 +39,8 @@ def job_title # end def can_drink? (country = "Australia") - @age >= AGES[country] + return false if @age.nil? + + @age >= Country.new(country).drinking_age end end - - -AGES = { - 'Benin' => 0, - 'Bolivia' => 0, - 'Burkina Faso' => 0, - 'Burundi' => 0, - 'Cambodia' => 0, - 'Cameroon' => 0, - 'China' => 0, - 'Gabon' => 0, - 'Guinea-Bissau' => 0, - 'Indonesia' => 0, - 'Kosovo' => 0, - 'Laos' => 0, - 'Mali' => 0, - 'Rwanda' => 0, - 'Sao Tome and Principe' => 0, - 'Sierra Leone' => 0, - 'Solomon Islands' => 0, - 'Timor-Leste' => 0, - 'Togo' => 0, - - 'Antigua and Barbuda' => 10, - 'Central African Republic' => 10, - - 'Austria' => 16, - 'Belgium' => 16, - 'Congo' => 16, - 'Cyprus' => 16, - 'Denmark' => 16, - 'Dominica' => 16, - 'Germany' => 16, - 'Grenada' => 16, - 'Guyana' => 16, - 'Haiti' => 16, - 'Liechtenstein' => 16, - 'Luxembourg' => 16, - 'Malta' => 16, - 'Morocco' => 16, - 'Netherlands' => 16, - 'Portugal' => 16, - 'Saint Lucia' => 16, - 'Saint Vincent and the Grenadines' => 16, - 'San Marino' => 16, - 'Spain' => 16, - 'Switzerland' => 16, - - 'Albania' => 18, - 'Algeria' => 18, - 'Andorra' => 18, - 'Angola' => 18, - 'Argentina' => 18, - 'Armenia' => 18, - 'Australia' => 18, - 'Azerbaijan' => 18, - 'Bahamas' => 18, - 'Barbados' => 18, - 'Belarus' => 18, - 'Belize' => 18, - 'Bhutan' => 18, - 'Bosnia and Herzegovina' => 18, - 'Botswana' => 18, - 'Brazil' => 18, - 'Bulgaria' => 18, - 'Canada' => 18, - 'Cape Verde' => 18, - 'Chad' => 18, - 'Chile' => 18, - 'Colombia' => 18, - 'Comoros' => 18, - 'Costa Rica' => 18, - 'Croatia' => 18, - 'Cuba' => 18, - 'Czech Republic' => 18, - 'Democratic Republic of the Congo' => 18, - 'Dominican Republic' => 18, - 'Ecuador' => 18, - 'Egypt' => 18, - 'El Salvador' => 18, - 'Eritrea' => 18, - 'Estonia' => 18, - 'Ethiopia' => 18, - 'Fiji' => 18, - 'Finland' => 18, - 'France' => 18, - 'Gambia' => 18, - 'Georgia' => 18, - 'Ghana' => 18, - 'Greece' => 18, - 'Guatemala' => 18, - 'Guinea' => 18, - 'Honduras' => 18, - 'Hungary' => 18, - 'India' => 18, - 'Ireland' => 18, - 'Israel' => 18, - 'Italy' => 18, - 'Jamaica' => 18, - 'Jordan' => 18, - 'Kazakhstan' => 18, - 'Kenya' => 18, - 'Kyrgyzstan' => 18, - 'Latvia' => 18, - 'Lesotho' => 18, - 'Liberia' => 18, - 'Lithuania' => 18, - 'Macedonia' => 18, - 'Madagascar' => 18, - 'Malawi' => 18, - 'Malaysia' => 18, - 'Mauritius' => 18, - 'Mexico' => 18, - 'Moldova' => 18, - 'Monaco' => 18, - 'Montenegro' => 18, - 'Mozambique' => 18, - 'Myanmar' => 18, - 'Namibia' => 18, - 'Nepal' => 18, - 'New Zealand' => 18, - 'Nicaragua' => 18, - 'Niger' => 18, - 'Nigeria' => 18, - 'Norway' => 18, - 'Panama' => 18, - 'Papua New Guinea' => 18, - 'Peru' => 18, - 'Philippines' => 18, - 'Poland' => 18, - 'Romania' => 18, - 'Russia' => 18, - 'Saint Kitts and Nevis' => 18, - 'Senegal' => 18, - 'Serbia' => 18, - 'Seychelles' => 18, - 'Singapore' => 18, - 'Slovakia' => 18, - 'Slovenia' => 18, - 'South Africa' => 18, - 'South Korea' => 18, - 'Suriname' => 18, - 'Swaziland' => 18, - 'Sweden' => 18, - 'Syria' => 18, - 'Tajikistan' => 18, - 'Tanzania' => 18, - 'Tonga' => 18, - 'Trinidad and Tobago' => 18, - 'Tunisia' => 18, - 'Turkey' => 18, - 'Turkmenistan' => 18, - 'Tuvalu' => 18, - 'Uganda' => 18, - 'Ukraine' => 18, - 'United Kingdom' => 18, - 'Uruguay' => 18, - 'Vanuatu' => 18, - 'Vatican City' => 18, - 'Venezuela' => 18, - 'Vietnam' => 18, - 'Zambia' => 18, - 'Zimbabwe' => 18, - - 'Iceland' => 20, - 'Japan' => 20, - 'Paraguay' => 20, - 'Thailand' => 20, - 'Uzbekistan' => 20, - - 'Côte d\'Ivoire' => 21, - 'Equatorial Guinea' => 21, - 'Iraq' => 21, - 'Kiribati' => 21, - 'Micronesia' => 21, - 'Mongolia' => 21, - 'Nauru' => 21, - 'Oman' => 21, - 'Palau' => 21, - 'Samoa' => 21, - 'Sri Lanka' => 21, - 'United States' => 21, - - 'Afghanistan' => 999, - 'Bahrain' => 999, - 'Bangladesh' => 999, - 'Brunei Darussalam' => 999, - 'Iran' => 999, - 'Kuwait' => 999, - 'Libya' => 999, - 'Maldives' => 999, - 'Mauritania' => 999, - 'Pakistan' => 999, - 'Qatar' => 999, - 'Saudi Arabia' => 999, - 'Somalia' => 999, - 'Sudan' => 999, - 'United Arab Emirates' => 999, - 'Yemen' => 999 -} diff --git a/specs/models/human_spec.rb b/specs/models/human_spec.rb index 1ba679a..75bfcf5 100644 --- a/specs/models/human_spec.rb +++ b/specs/models/human_spec.rb @@ -65,7 +65,6 @@ human = Human.new('Boris Jr') human.age = 14 expect(human.can_drink?).to be false - end it 'checks the drinking age for a given country' do @@ -74,8 +73,18 @@ expect(human.can_drink? 'Australia').to be true expect(human.can_drink? 'United States').to be false end - end + it 'returns false if country is unknown' do + human = Human.new('Odie') + human.age = 18 + expect(human.can_drink? 'Not a Real Country').to be false + end + + it 'returns false if age is not set' do + human = Human.new('Tye M. Less') + expect(human.can_drink?).to be false + end + end it 'play area' do puts Human.new('Caitlin').name From 6deda11c401e859660abf97f4c1dca7bb7454c67 Mon Sep 17 00:00:00 2001 From: Lilly Piri Date: Fri, 24 Mar 2017 09:37:04 +1000 Subject: [PATCH 3/3] Adding classical fizzbuzz --- models/country.rb | 210 ------------------------------------- models/fizzbuzz.rb | 43 ++++++++ models/human.rb | 46 -------- specs/fizzbuzz_spec.rb | 61 +++++++++++ specs/models/human_spec.rb | 92 ---------------- 5 files changed, 104 insertions(+), 348 deletions(-) delete mode 100644 models/country.rb create mode 100644 models/fizzbuzz.rb delete mode 100644 models/human.rb create mode 100644 specs/fizzbuzz_spec.rb delete mode 100644 specs/models/human_spec.rb diff --git a/models/country.rb b/models/country.rb deleted file mode 100644 index cd44b4f..0000000 --- a/models/country.rb +++ /dev/null @@ -1,210 +0,0 @@ -class Country - def initialize (country) - @country = country - end - - def drinking_age - return 999 unless AGES.include? @country - AGES[@country] - end - - - AGES = { - 'Benin' => 0, - 'Bolivia' => 0, - 'Burkina Faso' => 0, - 'Burundi' => 0, - 'Cambodia' => 0, - 'Cameroon' => 0, - 'China' => 0, - 'Gabon' => 0, - 'Guinea-Bissau' => 0, - 'Indonesia' => 0, - 'Kosovo' => 0, - 'Laos' => 0, - 'Mali' => 0, - 'Rwanda' => 0, - 'Sao Tome and Principe' => 0, - 'Sierra Leone' => 0, - 'Solomon Islands' => 0, - 'Timor-Leste' => 0, - 'Togo' => 0, - - 'Antigua and Barbuda' => 10, - 'Central African Republic' => 10, - - 'Austria' => 16, - 'Belgium' => 16, - 'Congo' => 16, - 'Cyprus' => 16, - 'Denmark' => 16, - 'Dominica' => 16, - 'Germany' => 16, - 'Grenada' => 16, - 'Guyana' => 16, - 'Haiti' => 16, - 'Liechtenstein' => 16, - 'Luxembourg' => 16, - 'Malta' => 16, - 'Morocco' => 16, - 'Netherlands' => 16, - 'Portugal' => 16, - 'Saint Lucia' => 16, - 'Saint Vincent and the Grenadines' => 16, - 'San Marino' => 16, - 'Spain' => 16, - 'Switzerland' => 16, - - 'Albania' => 18, - 'Algeria' => 18, - 'Andorra' => 18, - 'Angola' => 18, - 'Argentina' => 18, - 'Armenia' => 18, - 'Australia' => 18, - 'Azerbaijan' => 18, - 'Bahamas' => 18, - 'Barbados' => 18, - 'Belarus' => 18, - 'Belize' => 18, - 'Bhutan' => 18, - 'Bosnia and Herzegovina' => 18, - 'Botswana' => 18, - 'Brazil' => 18, - 'Bulgaria' => 18, - 'Canada' => 18, - 'Cape Verde' => 18, - 'Chad' => 18, - 'Chile' => 18, - 'Colombia' => 18, - 'Comoros' => 18, - 'Costa Rica' => 18, - 'Croatia' => 18, - 'Cuba' => 18, - 'Czech Republic' => 18, - 'Democratic Republic of the Congo' => 18, - 'Dominican Republic' => 18, - 'Ecuador' => 18, - 'Egypt' => 18, - 'El Salvador' => 18, - 'Eritrea' => 18, - 'Estonia' => 18, - 'Ethiopia' => 18, - 'Fiji' => 18, - 'Finland' => 18, - 'France' => 18, - 'Gambia' => 18, - 'Georgia' => 18, - 'Ghana' => 18, - 'Greece' => 18, - 'Guatemala' => 18, - 'Guinea' => 18, - 'Honduras' => 18, - 'Hungary' => 18, - 'India' => 18, - 'Ireland' => 18, - 'Israel' => 18, - 'Italy' => 18, - 'Jamaica' => 18, - 'Jordan' => 18, - 'Kazakhstan' => 18, - 'Kenya' => 18, - 'Kyrgyzstan' => 18, - 'Latvia' => 18, - 'Lesotho' => 18, - 'Liberia' => 18, - 'Lithuania' => 18, - 'Macedonia' => 18, - 'Madagascar' => 18, - 'Malawi' => 18, - 'Malaysia' => 18, - 'Mauritius' => 18, - 'Mexico' => 18, - 'Moldova' => 18, - 'Monaco' => 18, - 'Montenegro' => 18, - 'Mozambique' => 18, - 'Myanmar' => 18, - 'Namibia' => 18, - 'Nepal' => 18, - 'New Zealand' => 18, - 'Nicaragua' => 18, - 'Niger' => 18, - 'Nigeria' => 18, - 'Norway' => 18, - 'Panama' => 18, - 'Papua New Guinea' => 18, - 'Peru' => 18, - 'Philippines' => 18, - 'Poland' => 18, - 'Romania' => 18, - 'Russia' => 18, - 'Saint Kitts and Nevis' => 18, - 'Senegal' => 18, - 'Serbia' => 18, - 'Seychelles' => 18, - 'Singapore' => 18, - 'Slovakia' => 18, - 'Slovenia' => 18, - 'South Africa' => 18, - 'South Korea' => 18, - 'Suriname' => 18, - 'Swaziland' => 18, - 'Sweden' => 18, - 'Syria' => 18, - 'Tajikistan' => 18, - 'Tanzania' => 18, - 'Tonga' => 18, - 'Trinidad and Tobago' => 18, - 'Tunisia' => 18, - 'Turkey' => 18, - 'Turkmenistan' => 18, - 'Tuvalu' => 18, - 'Uganda' => 18, - 'Ukraine' => 18, - 'United Kingdom' => 18, - 'Uruguay' => 18, - 'Vanuatu' => 18, - 'Vatican City' => 18, - 'Venezuela' => 18, - 'Vietnam' => 18, - 'Zambia' => 18, - 'Zimbabwe' => 18, - - 'Iceland' => 20, - 'Japan' => 20, - 'Paraguay' => 20, - 'Thailand' => 20, - 'Uzbekistan' => 20, - - 'Côte d\'Ivoire' => 21, - 'Equatorial Guinea' => 21, - 'Iraq' => 21, - 'Kiribati' => 21, - 'Micronesia' => 21, - 'Mongolia' => 21, - 'Nauru' => 21, - 'Oman' => 21, - 'Palau' => 21, - 'Samoa' => 21, - 'Sri Lanka' => 21, - 'United States' => 21, - - 'Afghanistan' => 999, - 'Bahrain' => 999, - 'Bangladesh' => 999, - 'Brunei Darussalam' => 999, - 'Iran' => 999, - 'Kuwait' => 999, - 'Libya' => 999, - 'Maldives' => 999, - 'Mauritania' => 999, - 'Pakistan' => 999, - 'Qatar' => 999, - 'Saudi Arabia' => 999, - 'Somalia' => 999, - 'Sudan' => 999, - 'United Arab Emirates' => 999, - 'Yemen' => 999 - } -end diff --git a/models/fizzbuzz.rb b/models/fizzbuzz.rb new file mode 100644 index 0000000..6389fec --- /dev/null +++ b/models/fizzbuzz.rb @@ -0,0 +1,43 @@ +# count to 100 +class FizzBuzz + + # Counts to 100. + # Makes an array of length 100 where each value is the fizzbuzz value. + def to_array + # Start with an empty array. + array = [] + # Count from 1 to 100. + (1..100).each do |x| + # If the number matches any of the fizzbuzz numbers, add the string. + if fizzbuzz? (x) + array.push "fizzbuzz" + elsif fizz? (x) + array.push "fizz" + elsif buzz? (x) + array.push "buzz" + # Otherwise just add the number to our array. + else + array.push x + end + end + # Return the finished array of 100 values. + array + end + + # FizzBuzz divisible by 3 and 5 + # % is modulo division. It divides a number and returns the remainder. + # If the remainder is 0, the number was equally divisible. + def fizzbuzz?(x) + x % 3 == 0 && x % 5 == 0 + end + + # Fizz divisible by 3 + def fizz?(x) + x % 3 == 0 + end + + # Buzz divisible by 5 + def buzz?(x) + x % 5 == 0 + end +end diff --git a/models/human.rb b/models/human.rb deleted file mode 100644 index a7b7cd0..0000000 --- a/models/human.rb +++ /dev/null @@ -1,46 +0,0 @@ -require_relative 'country' - -class Human - - def initialize value - @name = value - end - - def name - @name - end - - def legal_name - first_name = @name.split.first - last_name = @name.split.last - - last_name + ", " + first_name - - # @name.split(' ', 2).reverse.join(', ') - end - - # attr_accessor :job_title - def job_title=(value) - @job_title = value - end - - def job_title - @job_title - end - -attr_accessor :age - - # def age=(value) - # @age = value - # end - # - # def age - # @age - # end - - def can_drink? (country = "Australia") - return false if @age.nil? - - @age >= Country.new(country).drinking_age - end -end diff --git a/specs/fizzbuzz_spec.rb b/specs/fizzbuzz_spec.rb new file mode 100644 index 0000000..747fd93 --- /dev/null +++ b/specs/fizzbuzz_spec.rb @@ -0,0 +1,61 @@ +require 'rspec' +require_relative "../models/fizzbuzz" + + +describe FizzBuzz do + describe '.fizzbuzz' do + it 'returns FizzBuzz on numbers divisible by 3 and 5' do + fizzbuzz = FizzBuzz.new + expect(fizzbuzz.fizzbuzz?(15)).to be true + expect(fizzbuzz.fizzbuzz?(16)).to be false + end + end + + describe '.fizz' do + it 'returns fizz on numbers divisible by 3' do + fizz = FizzBuzz.new + expect(fizz.fizz?(3)).to be true + expect(fizz.fizz?(4)).to be false + end + end + + describe '.buzz' do + it 'returns buzz on numbers divisible by 5' do + buzz = FizzBuzz.new + expect(buzz.buzz?(5)).to be true + expect(buzz.buzz?(74)).to be false + end + end + + describe '.to_array' do + it 'makes a fizzbuzz array' do + fizzbuzz = FizzBuzz.new + array = fizzbuzz.to_array + expect(array.count).to eq(100) + # These tests will work because counting of the array starts at 0. + # Eg. 88 is the key, 89 is the value. + expect(array[88]).to eq(89) + expect(array[77]).to eq('fizz') + expect(array[79]).to eq('buzz') + expect(array[74]).to eq('fizzbuzz') + end + end + + # Unused play area + # describe 'play area' do + # it 'returns 1 - 100 with fizzbuzz, fizz and buzz' do + # count = FizzBuzz.new + # (1..100).each do |x| + # if count.fizzbuzz (x) + # puts "fizzbuzz" + # elsif count.fizz (x) + # puts "fizz" + # elsif count.buzz (x) + # puts "buzz" + # else + # puts x + # end + # end + # end + # end +end diff --git a/specs/models/human_spec.rb b/specs/models/human_spec.rb deleted file mode 100644 index 75bfcf5..0000000 --- a/specs/models/human_spec.rb +++ /dev/null @@ -1,92 +0,0 @@ -require 'rspec' -require_relative "../../models/human" - -describe Human do - - describe '#new' do - it 'initializes a new instance of Human' do - human = Human.new('Fred') - expect(human).to be_instance_of Human - end - end - - describe '.name' do - it 'has a name of Fred' do - human = Human.new('Fred') - expect(human.name).to eq('Fred') - end - end - - describe '.legal_name' do - it 'that "Fred Frog" returns "Frog, Fred"' do - human = Human.new('Fred Frog') - expect(human.legal_name).to eq('Frog, Fred') - end - end - - describe '.job_title=' do - it 'sets the job title for our human instance' do - human = Human.new('') - expect(human).to respond_to(:job_title=) - end - end - - describe '.job_title' do - it 'it returns the job title' do - human = Human.new('') - human.job_title = 'Guru' - expect(human.job_title).to eq('Guru') - end - end - - describe '.age=' do - it 'sets the age for our human instance' do - human = Human.new('') - expect(human).to respond_to(:age=) - end - end - - describe '.age' do - it 'it returns the age' do - human = Human.new('') - human.age = 18 - expect(human.age).to eq(18) - end - end - - describe '.can_drink?' do - it 'returns true if human is of age' do - human = Human.new('Boris') - human.age = 35 - expect(human.can_drink?).to be true - end - - it 'returns false if human is underage' do - human = Human.new('Boris Jr') - human.age = 14 - expect(human.can_drink?).to be false - end - - it 'checks the drinking age for a given country' do - human = Human.new('Garfield') - human.age = 18 - expect(human.can_drink? 'Australia').to be true - expect(human.can_drink? 'United States').to be false - end - - it 'returns false if country is unknown' do - human = Human.new('Odie') - human.age = 18 - expect(human.can_drink? 'Not a Real Country').to be false - end - - it 'returns false if age is not set' do - human = Human.new('Tye M. Less') - expect(human.can_drink?).to be false - end - end - - it 'play area' do - puts Human.new('Caitlin').name - end -end