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
46 changes: 46 additions & 0 deletions dog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
class Dog

attr_reader :owner_name, :spayed_or_neutered, :cost_to_adopt, :BARK_TYPES



def initialize(age, breed, name, gender, spayed_or_neutered, cost_to_adopt, owner_name)
@age = age
@breed = breed
@name = name
@gender = gender
@spayed_or_neutered = spayed_or_neutered
@cost_to_adopt = cost_to_adopt
@owner_name = owner_name
@BARK_TYPES = ["Bark!", "Woof!", "Meow!"]
end

def in_shelter?
if @owner_name == "" || @owner_name == nil
true
else
false
end
end

def bark

@BARK_TYPES.sample
end

def adopt!(owner_name)
if owner_name == "" || owner_name == nil
raise
else
@owner_name = owner_name
@spayed_or_neutered = true
@cost_to_adopt = nil
end
end

end

# dog = Dog.new(1, "Poodle", "Max", "M", true, 200, "Kevin")

# test init
# actually raise error in line 29?
43 changes: 43 additions & 0 deletions dog_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require_relative 'dog'

describe 'dog' do


context 'in_shelter?' do
it 'determines whether dog has owner or is in shelter' do
dog = Dog.new(1, "Poodle", "Max", "M", true, 200, "Kevin")
expect(dog.in_shelter?).to be false
end
end

context 'bark' do
it 'barks' do
dog = Dog.new(1, "Poodle", "Max", "M", true, 200, "Kevin")
expect(dog.BARK_TYPES.include? dog.bark).to be true
end
end

context 'adopt!' do
it 'adopts the dog' do
dog = Dog.new(1, "Poodle", "Max", "M", true, 200, "Kevin")
expect(dog.owner_name).to eq "Kevin"
expect(dog.spayed_or_neutered).to be true
expect(dog.cost_to_adopt).to eq 200

dog.adopt!("Bruce")

expect(dog.owner_name).to eq "Bruce"
expect(dog.spayed_or_neutered).to be true
expect(dog.cost_to_adopt).to eq nil
end
end

context 'adopt!' do
it 'throws an error without an owner_name' do
dog = Dog.new(1, "Poodle", "Max", "M", true, 200, "Kevin")
expect{ dog.adopt!("") }.to raise_error(RuntimeError)

end
end

end
12 changes: 12 additions & 0 deletions find_multiples.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
def find_multiples(input)
sum = 0
for i in 1...input
if i%3 == 0 || i%5 == 0
sum += i
end

end
sum
end


9 changes: 9 additions & 0 deletions find_multiples_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
require_relative 'find_multiples'

describe 'find_multiples' do

it 'finds and sums the multiples of 3 and 5 in integers up to the input' do
expect(find_multiples(10)).to eq 23
end

end