Решение на Първа задача - температура и химични елементи от Димитър Стефанов

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

Към профила на Димитър Стефанов

Резултати

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

Код

def convert_between_temperature_units(temperature, convert_from, convert_to)
scale_convertions = {
"F" => {
"F" => temperature,
"C" => ((temperature - 32.0) * 0.56),
"K" => (((temperature - 32.0) * 0.56) + 273.15)
},
"C" => {
"F" => ((temperature * 1.8) + 32),
"C" => temperature,
"K" => (temperature + 273.15)
},
"K" => {
"F" => ((temperature - 273.15) * 1.8 + 32.0),
"C" => (temperature - 273.15),
"K" => temperature
}
}
( scale_convertions[convert_from][convert_to] ).round(2)
end
def melting_point_of_substance(substance, scale)
substance_melting_points_in_celsius = {
"water" => 0.0,
"ethanol" => -114.0,
"gold" => 1064.0,
"silver" => 961.8,
"copper" => 1085.0
}
convert_between_temperature_units(substance_melting_points_in_celsius[substance], 'C', scale)
end
def boiling_point_of_substance(substance, scale)
substance_boiling_points_in_celsius = {
"water" => 100.0,
"ethanol" => 78.37,
"gold" => 2700.0,
"silver" => 2162.0,
"copper" => 2567.0
}
convert_between_temperature_units(substance_boiling_points_in_celsius[substance], 'C', scale)
end

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

....F.F..........

Failures:

  1) #convert_between_temperature_units can convert Fahrenheit to Celsius
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected 1.01 to be within 0.0001 of 1
     # /tmp/d20161018-13513-1t0wfor/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1t0wfor/spec.rb:31: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 274.16 to be within 0.0001 of 274.15
     # /tmp/d20161018-13513-1t0wfor/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1t0wfor/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.00834 seconds
17 examples, 2 failures

Failed examples:

rspec /tmp/d20161018-13513-1t0wfor/spec.rb:30 # #convert_between_temperature_units can convert Fahrenheit to Celsius
rspec /tmp/d20161018-13513-1t0wfor/spec.rb:46 # #convert_between_temperature_units can convert Fahrenheit to Kelvin

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

Димитър обнови решението на 17.10.2016 00:10 (преди над 7 години)

+def convert_between_temperature_units(temperature, convert_from, convert_to)
+ scale_convertions = {
+ "F" => {
+ "F" => temperature,
+ "C" => ((temperature - 32.0) * 0.56),
+ "K" => (((temperature - 32.0) * 0.56) + 273.15)
+ },
+ "C" => {
+ "F" => ((temperature * 1.8) + 32),
+ "C" => temperature,
+ "K" => (temperature + 273.15)
+ },
+ "K" => {
+ "F" => ((temperature - 273.15) * 1.8 + 32.0),
+ "C" => (temperature - 273.15),
+ "K" => temperature
+ }
+ }
+ ( scale_convertions[convert_from][convert_to] ).round(2)
+end
+
+def melting_point_of_substance(substance, scale)
+ substance_melting_points_in_celsius = {
+ "water" => 0.0,
+ "ethanol" => -114.0,
+ "gold" => 1064.0,
+ "silver" => 961.8,
+ "copper" => 1085.0
+ }
+ convert_between_temperature_units(substance_melting_points_in_celsius[substance], 'C', scale)
+end
+
+def boiling_point_of_substance(substance, scale)
+ substance_boiling_points_in_celsius = {
+ "water" => 100.0,
+ "ethanol" => 78.37,
+ "gold" => 2700.0,
+ "silver" => 2162.0,
+ "copper" => 2567.0
+ }
+ convert_between_temperature_units(substance_boiling_points_in_celsius[substance], 'C', scale)
+end