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
30 changes: 30 additions & 0 deletions dog.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class Dog
attr_accessor :age, :breed, :name, :gender, :spayed_or_neutered, :cost_to_adopt, :owner_name
def initialize(age, breed, name, gender, spayed, cost, owner)
@age = age
@breed = breed
@name = name
@gender = gender
@spayed_or_neutered = spayed
@cost_to_adopt = cost
@owner_name = owner
end

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

def bark
return "woof"
end

def adopt!(owner_name)
@owner_name = owner_name
@spayed_or_neutered = true
@cost_to_adopt = nil
end
end
27 changes: 27 additions & 0 deletions lecture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
def multiples(max_number)
sum = []
range = (0..max_number-1).to_a
range.each do |x|
if x%3 == 0
sum << x
elsif x%5 == 0
sum << x
else
end
end
sum.inject(:+)

end

describe 'multiples' do
it 'sums the multiples of 3 and 5' do
expect(multiples(10)).to eq 23
end
end

describe 'multiples' do
it 'sums the multiples of 3 and 5' do
expect(multiples(1000)).to eq 233168
end
end

45 changes: 45 additions & 0 deletions spec/dog_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require_relative '../dog.rb'

describe Dog do
let(:spot) {Dog.new(5, "Husky", "Spot", "Male", true, 405, "")}

it '#init age' do
expect(spot.age).to eq 5
end

it '#init breed' do
expect(spot.breed).to eq "Husky"
end

it '#init name' do
expect(spot.name).to eq "Spot"
end

it '#init gender' do
expect(spot.gender).to eq "Male"
end

it '#init spayed_or_neutered' do
expect(spot.spayed_or_neutered).to eq true
end

it '#init cost_to_adopt' do
expect(spot.cost_to_adopt).to eq 405
end

it '#init owner_name' do
expect(spot.owner_name).to eq ""
end

it 'tells if dog is in shelter' do
expect(spot.in_shelter?).to eq true
end

it 'prints woof' do
expect(spot.bark).to eq 'woof'
end

it 'John adopts spot' do
expect { spot.adopt!("John") }.to change(spot, :owner_name).from("").to("John")
end
end
2 changes: 1 addition & 1 deletion testing_lecture.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#Testing Lecture Live Code

#Testing Lecture Live Code
1. Multiples of 3 and 5
=======================

Expand Down