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

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

Към профила на Сияна Плачкова

Резултати

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

Код

MELTING_POINTS = {'water' => 0, 'ethanol' => -114, 'gold' => 1064, 'silver' => 961.8, 'copper' => 1085, }
BOILING_POINTS = {'water' => 100, 'ethanol' => 78.37, 'gold' => 2700, 'silver' => 2162, 'copper' => 2567, }
CONVERSIONS = {
'CtoC' => ->(degrees) { degrees },
'CtoF' => ->(degrees) { degrees * 1.8 + 32 },
'CtoK' => ->(degrees) { degrees + 273.15 },
'FtoC' => ->(degrees) { (degrees - 32) / 1.8 },
'FtoF' => ->(degrees) { degrees },
'FtoK' => ->(degrees) { (degrees + 459.67) * 0.6 },
'KtoC' => ->(degrees) { degrees - 273.15 },
'KtoF' => ->(degrees) { degrees * 1.8 },
'KtoK' => ->(degrees) { degrees },
}
def convert_between_temperature_units(degrees, input_unit, output_unit)
CONVERSIONS[input_unit + 'to' + output_unit].call(degrees)
end
def melting_point_of_substance(substance, unit)
CONVERSIONS['C' + 'to' + unit].call(MELTING_POINTS[substance])
end
def boiling_point_of_substance(substance, unit)
CONVERSIONS['C' + 'to' + unit].call(BOILING_POINTS[substance])
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 493.46999999999997 to be within 0.0001 of 33.8
     # /tmp/d20161018-13513-qn1061/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-qn1061/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 296.082 to be within 0.0001 of 274.15
     # /tmp/d20161018-13513-qn1061/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-qn1061/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.00777 seconds
17 examples, 2 failures

Failed examples:

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

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

Сияна обнови решението на 17.10.2016 16:33 (преди над 7 години)

+MELTING_POINTS = {'water' => 0, 'ethanol' => -114, 'gold' => 1064, 'silver' => 961.8, 'copper' => 1085, }
+BOILING_POINTS = {'water' => 100, 'ethanol' => 78.37, 'gold' => 2700, 'silver' => 2162, 'copper' => 2567, }
+
+CONVERSIONS = {
+ 'CtoC' => ->(degrees) { degrees },
+ 'CtoF' => ->(degrees) { degrees * 1.8 + 32 },
+ 'CtoK' => ->(degrees) { degrees + 273.15 },
+ 'FtoC' => ->(degrees) { (degrees - 32) / 1.8 },
+ 'FtoF' => ->(degrees) { degrees },
+ 'FtoK' => ->(degrees) { (degrees + 459.67) * 0.6 },
+ 'KtoC' => ->(degrees) { degrees - 273.15 },
+ 'KtoF' => ->(degrees) { degrees * 1.8 },
+ 'KtoK' => ->(degrees) { degrees },
+}
+
+def convert_between_temperature_units(degrees, input_unit, output_unit)
+ CONVERSIONS[input_unit + 'to' + output_unit].call(degrees)
+end
+
+def melting_point_of_substance(substance, unit)
+ CONVERSIONS['C' + 'to' + unit].call(MELTING_POINTS[substance])
+end
+
+def boiling_point_of_substance(substance, unit)
+ CONVERSIONS['C' + 'to' + unit].call(BOILING_POINTS[substance])
+end