Skip to content

Commit

Permalink
T-19 Update == (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
marian13 committed Mar 4, 2020
1 parent 84d2716 commit 828bbaf
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 21 deletions.
6 changes: 5 additions & 1 deletion lib/basic_temperature.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,11 @@ def to_kelvin
def ==(other)
return false unless other.instance_of?(BasicTemperature)

self.degrees == other.degrees && self.scale == other.scale
if self.scale == other.scale
self.degrees == other.degrees
else
self.to_scale(other.scale).degrees == other.degrees
end
end

def +(other)
Expand Down
50 changes: 30 additions & 20 deletions spec/basic_temperature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -309,39 +309,49 @@
it 'returns false' do
temperature = BasicTemperature.new(0, 'celcius')

other_temperature = nil
other = nil

expect(temperature == other_temperature).to eq(false)
expect(temperature == other).to eq(false)
end
end

context 'when temperature and other temperature do NOT have equal degrees' do
it 'returns false' do
temperature = BasicTemperature.new(0, 'celcius')

other_temperature = BasicTemperature.new(15, 'celcius')
context 'when temperatures have the same scale' do
context 'when temperatures have different degrees' do
it 'returns false' do
temperature = BasicTemperature.new(0, 'celcius')
other = BasicTemperature.new(15, 'celcius')

expect(temperature == other_temperature).to eq(false)
expect(temperature == other).to eq(false)
end
end
end

context 'when temperature and other temperature do NOT have equal scales' do
it 'returns false' do
temperature = BasicTemperature.new(0, 'celcius')

other_temperature = BasicTemperature.new(0, 'kelvin')
context 'when temperatures have the same degrees' do
it 'returns true' do
temperature = BasicTemperature.new(0, 'celcius')
other = BasicTemperature.new(0, 'celcius')

expect(temperature == other_temperature).to eq(false)
expect(temperature == other).to eq(true)
end
end
end

context 'when temperature and other temperature have equal degrees and scales' do
it 'returns true' do
temperature = BasicTemperature.new(0, 'celcius')
context 'when temperatures have different scales' do
context 'when converted first temperature does NOT have the same degrees as second temperature' do
it 'returns false' do
temperature = BasicTemperature.new(0, 'celcius')
other = BasicTemperature.new(0, 'kelvin')

other_temperature = BasicTemperature.new(0, 'celcius')
expect(temperature == other).to eq(false)
end
end

context 'when converted first temperature has the same degrees as second temperature' do
it 'returns true' do
temperature = BasicTemperature.new(0, 'celcius')
other = BasicTemperature.new(273.15, 'kelvin')

expect(temperature == other_temperature).to eq(true)
expect(temperature == other).to eq(true)
end
end
end
end
Expand Down

0 comments on commit 828bbaf

Please sign in to comment.