Решение на Първа задача - температура и химични елементи от Анелия Благоева

Обратно към всички решения

Към профила на Анелия Благоева

Резултати

  • 5 точки от тестове
  • 0 бонус точки
  • 5 точки общо
  • 15 успешни тест(а)
  • 2 неуспешни тест(а)

Код

def convert_between_temperature_units(temp, src, dest)
if src == 'C' && dest == 'F'
temp * 1.8 + 32.0
elsif src == 'C' && dest == 'K'
temp + 273.15
elsif src == 'F' && dest == 'C'
(temp - 32.0) / 1.8
elsif src == 'F' && dest == 'K'
temp + 255.37
elsif src == 'K' && dest == 'C'
temp - 273.15
elsif src == 'K' && dest == 'F'
temp - 459.67
else
temp
end
end
def melting_point_of_substance(substance, scale)
if substance == 'water'
convert_between_temperature_units(0, 'C', scale)
elsif substance == 'ethanol'
convert_between_temperature_units(-114, 'C', scale)
elsif substance == 'gold'
convert_between_temperature_units(1064, 'C', scale)
elsif substance == 'silver'
convert_between_temperature_units(961.8, 'C', scale)
else
convert_between_temperature_units(1085, 'C', scale)
end
end
def boiling_point_of_substance(substance, scale)
if substance == 'water'
convert_between_temperature_units(100, 'C', scale)
elsif substance == 'ethanol'
convert_between_temperature_units(78.37, 'C', scale)
elsif substance == 'gold'
convert_between_temperature_units(2700, 'C', scale)
elsif substance == 'silver'
convert_between_temperature_units(2162, 'C', scale)
else
convert_between_temperature_units(2567, 'C', scale)
end
end

Лог от изпълнението

.....FF..........

Failures:

  1) #convert_between_temperature_units can convert Kelvin to Fahrenheit
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected -185.52000000000004 to be within 0.0001 of 33.8
     # /tmp/d20161018-13513-qr4rc7/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-qr4rc7/spec.rb:39:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

  2) #convert_between_temperature_units can convert Fahrenheit to Kelvin
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected 289.17 to be within 0.0001 of 274.15
     # /tmp/d20161018-13513-qr4rc7/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-qr4rc7/spec.rb:47:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:7:in `block (2 levels) in <top (required)>'

Finished in 0.00787 seconds
17 examples, 2 failures

Failed examples:

rspec /tmp/d20161018-13513-qr4rc7/spec.rb:38 # #convert_between_temperature_units can convert Kelvin to Fahrenheit
rspec /tmp/d20161018-13513-qr4rc7/spec.rb:46 # #convert_between_temperature_units can convert Fahrenheit to Kelvin

История (1 версия и 2 коментара)

Анелия обнови решението на 16.10.2016 12:25 (преди около 8 години)

+def convert_between_temperature_units(temp, src, dest)
+ if src == 'C' && dest == 'F'
+ temp * 1.8 + 32.0
+ elsif src == 'C' && dest == 'K'
+ temp + 273.15
+ elsif src == 'F' && dest == 'C'
+ (temp - 32.0) / 1.8
+ elsif src == 'F' && dest == 'K'
+ temp + 255.37
+ elsif src == 'K' && dest == 'C'
+ temp - 273.15
+ elsif src == 'K' && dest == 'F'
+ temp - 459.67
+ else
+ temp
+ end
+end
+
+def melting_point_of_substance(substance, scale)
+ if substance == 'water'
+ convert_between_temperature_units(0, 'C', scale)
+ elsif substance == 'ethanol'
+ convert_between_temperature_units(-114, 'C', scale)
+ elsif substance == 'gold'
+ convert_between_temperature_units(1064, 'C', scale)
+ elsif substance == 'silver'
+ convert_between_temperature_units(961.8, 'C', scale)
+ else
+ convert_between_temperature_units(1085, 'C', scale)
+ end
+end
+
+def boiling_point_of_substance(substance, scale)
+ if substance == 'water'
+ convert_between_temperature_units(100, 'C', scale)
+ elsif substance == 'ethanol'
+ convert_between_temperature_units(78.37, 'C', scale)
+ elsif substance == 'gold'
+ convert_between_temperature_units(2700, 'C', scale)
+ elsif substance == 'silver'
+ convert_between_temperature_units(2162, 'C', scale)
+ else
+ convert_between_temperature_units(2567, 'C', scale)
+ end
+end