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

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

Към профила на Иван Илиев

Резултати

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

Код

def convert_between_temperature_units(num, unit1, unit2)
if unit1 == 'C' && unit2 == 'K'
return num + 273.15
elsif unit1 == 'C' && unit2 == 'F'
return 9 / 5 * num + 32
elsif unit1 == 'C' && unit2 == 'C'
return num
elsif unit1 == 'F' && unit2 == 'K'
return 5 / 9 * (num - 32) + 273
elsif unit1 == 'F' && unit2 == 'C'
return (num - 32) * 5 / 9
elsif unit1 == 'F' && unit2 == 'F'
return num
elsif unit1 == 'K' && unit2 == 'C'
return num - 273.15
elsif unit1 == 'K' && unit2 == 'F'
return (num - 273.15) * 9 / 5 + 32
elsif unit1 == 'K' && unit2 == 'K'
return num
end
end
def melting_point_of_substance(substance, temperature)
if temperature == 'C' && substance == 'water'
return 0
elsif temperature == 'C' && substance == 'ethanol'
return -144
elsif temperature == 'C' && substance == 'gold'
return 1064
elsif temperature == 'C' && substance == 'silver'
return 961.8
elsif temperature == 'C' && substance == 'copper'
return 1085
elsif temperature == 'K' && substance == 'water'
return convert_between_temperature_units(0, 'C', 'K')
elsif temperature == 'K' && substance == 'ethanol'
return convert_between_temperature_units(-144, 'C', 'K')
elsif temperature == 'K' && substance == 'gold'
return convert_between_temperature_units(1064, 'C', 'K')
elsif temperature == 'K' && substance == 'silver'
return convert_between_temperature_units(961.8, 'C', 'K')
elsif temperature == 'K' && substance == 'copper'
return convert_between_temperature_units(1085, 'C', 'K')
elsif temperature == 'F' && substance == 'water'
return convert_between_temperature_units(0, 'C', 'F')
elsif temperature == 'F' && substance == 'ethanol'
return convert_between_temperature_units(-144, 'C', 'F')
elsif temperature == 'F' && substance == 'gold'
return convert_between_temperature_units(1064, 'C', 'F')
elsif temperature == 'F' && substance == 'silver'
return convert_between_temperature_units(961.8, 'C', 'F')
elsif temperature == 'F' && substance == 'copper'
return convert_between_temperature_units(1085, 'C', 'F')
end
end
def boiling_point_of_substance(substance, temperature)
if temperature == 'C' && substance == 'water'
return 100
elsif temperature == 'C' && substance == 'ethanol'
return 78.37
elsif temperature == 'C' && substance == 'gold'
return 2700
elsif temperature == 'C' && substance == 'silver'
return 2162
elsif temperature == 'C' && substance == 'copper'
return 2567
elsif temperature == 'K' && substance == 'water'
return convert_between_temperature_units(100, 'C', 'K')
elsif temperature == 'K' && substance == 'ethanol'
return convert_between_temperature_units(78.37, 'C', 'K')
elsif temperature == 'K' && substance == 'gold'
return convert_between_temperature_units(2700, 'C', 'K')
elsif temperature == 'K' && substance == 'silver'
return convert_between_temperature_units(2162, 'C', 'K')
elsif temperature == 'K' && substance == 'copper'
return convert_between_temperature_units(2567, 'C', 'K')
elsif temperature == 'F' && substance == 'water'
return convert_between_temperature_units(100, 'C', 'F')
elsif temperature == 'F' && substance == 'ethanol'
return convert_between_temperature_units(78.37, 'C', 'F')
elsif temperature == 'F' && substance == 'gold'
return convert_between_temperature_units(2700, 'C', 'F')
elsif temperature == 'F' && substance == 'silver'
return convert_between_temperature_units(2162, 'C', 'F')
elsif temperature == 'F' && substance == 'copper'
return convert_between_temperature_units(2567, 'C', 'F')
end
end

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

...F..F.FFFFFFFFF

Failures:

  1) #convert_between_temperature_units can convert Celsius to Fahrenheit
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected 33.0 to be within 0.0001 of 33.8
     # /tmp/d20161018-13513-ak87u2/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-ak87u2/spec.rb:23: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 273.0 to be within 0.0001 of 274.15
     # /tmp/d20161018-13513-ak87u2/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-ak87u2/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)>'

  3) #melting_point_of_substance knows the melting point of ethanol
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected -144 to be within 0.01 of -114
     # /tmp/d20161018-13513-ak87u2/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:69: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)>'

  4) #melting_point_of_substance knows the melting point of gold
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 1096 to be within 0.01 of 1947.2
     # /tmp/d20161018-13513-ak87u2/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:77: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)>'

  5) #melting_point_of_substance knows the melting point of silver
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 993.8 to be within 0.01 of 1763.24
     # /tmp/d20161018-13513-ak87u2/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:83: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)>'

  6) #melting_point_of_substance knows the melting point of copper
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 1117 to be within 0.01 of 1985.0
     # /tmp/d20161018-13513-ak87u2/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:89: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)>'

  7) #boiling_point_of_substance knows the boiling point of water
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 132 to be within 0.01 of 212.0
     # /tmp/d20161018-13513-ak87u2/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:101: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)>'

  8) #boiling_point_of_substance knows the boiling point of ethanol
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 110.37 to be within 0.01 of 173.066
     # /tmp/d20161018-13513-ak87u2/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:107: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)>'

  9) #boiling_point_of_substance knows the boiling point of gold
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 2732 to be within 0.01 of 4892.0
     # /tmp/d20161018-13513-ak87u2/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:113: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)>'

  10) #boiling_point_of_substance knows the boiling point of silver
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 2194 to be within 0.01 of 3923.6
     # /tmp/d20161018-13513-ak87u2/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:119: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)>'

  11) #boiling_point_of_substance knows the boiling point of copper
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 2599 to be within 0.01 of 4652.6
     # /tmp/d20161018-13513-ak87u2/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-ak87u2/spec.rb:125: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.00858 seconds
17 examples, 11 failures

Failed examples:

rspec /tmp/d20161018-13513-ak87u2/spec.rb:22 # #convert_between_temperature_units can convert Celsius to Fahrenheit
rspec /tmp/d20161018-13513-ak87u2/spec.rb:46 # #convert_between_temperature_units can convert Fahrenheit to Kelvin
rspec /tmp/d20161018-13513-ak87u2/spec.rb:68 # #melting_point_of_substance knows the melting point of ethanol
rspec /tmp/d20161018-13513-ak87u2/spec.rb:74 # #melting_point_of_substance knows the melting point of gold
rspec /tmp/d20161018-13513-ak87u2/spec.rb:80 # #melting_point_of_substance knows the melting point of silver
rspec /tmp/d20161018-13513-ak87u2/spec.rb:86 # #melting_point_of_substance knows the melting point of copper
rspec /tmp/d20161018-13513-ak87u2/spec.rb:98 # #boiling_point_of_substance knows the boiling point of water
rspec /tmp/d20161018-13513-ak87u2/spec.rb:104 # #boiling_point_of_substance knows the boiling point of ethanol
rspec /tmp/d20161018-13513-ak87u2/spec.rb:110 # #boiling_point_of_substance knows the boiling point of gold
rspec /tmp/d20161018-13513-ak87u2/spec.rb:116 # #boiling_point_of_substance knows the boiling point of silver
rspec /tmp/d20161018-13513-ak87u2/spec.rb:122 # #boiling_point_of_substance knows the boiling point of copper

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

Иван обнови решението на 17.10.2016 15:01 (преди над 7 години)

+def convert_between_temperature_units(num, unit1, unit2)
+
+ if unit1 == 'C' && unit2 == 'K'
+
+ return num + 273.15
+
+ elsif unit1 == 'C' && unit2 == 'F'
+
+ return 9 / 5 * num + 32
+
+ elsif unit1 == 'C' && unit2 == 'C'
+
+ return num
+
+ elsif unit1 == 'F' && unit2 == 'K'
+
+ return 5 / 9 * (num - 32) + 273
+
+ elsif unit1 == 'F' && unit2 == 'C'
+
+ return (num - 32) * 5 / 9
+
+ elsif unit1 == 'F' && unit2 == 'F'
+
+ return num
+
+ elsif unit1 == 'K' && unit2 == 'C'
+
+ return num - 273.15
+
+ elsif unit1 == 'K' && unit2 == 'F'
+
+ return (num - 273.15) * 9 / 5 + 32
+
+ elsif unit1 == 'K' && unit2 == 'K'
+
+ return num
+
+ end
+
+end
+
+def melting_point_of_substance(substance, temperature)
+
+ if temperature == 'C' && substance == 'water'
+
+ return 0
+
+ elsif temperature == 'C' && substance == 'ethanol'
+
+ return -144
+
+ elsif temperature == 'C' && substance == 'gold'
+
+ return 1064
+
+ elsif temperature == 'C' && substance == 'silver'
+
+ return 961.8
+
+ elsif temperature == 'C' && substance == 'copper'
+
+ return 1085
+
+ elsif temperature == 'K' && substance == 'water'
+
+ return convert_between_temperature_units(0, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'ethanol'
+
+ return convert_between_temperature_units(-144, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'gold'
+
+ return convert_between_temperature_units(1064, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'silver'
+
+ return convert_between_temperature_units(961.8, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'copper'
+
+ return convert_between_temperature_units(1085, 'C', 'K')
+
+ elsif temperature == 'F' && substance == 'water'
+
+ return convert_between_temperature_units(0, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'ethanol'
+
+ return convert_between_temperature_units(-144, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'gold'
+
+ return convert_between_temperature_units(1064, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'silver'
+
+ return convert_between_temperature_units(961.8, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'copper'
+
+ return convert_between_temperature_units(1085, 'C', 'F')
+
+ end
+
+end
+
+def boiling_point_of_substance(substance, temperature)
+
+ if temperature == 'C' && substance == 'water'
+
+ return 100
+
+ elsif temperature == 'C' && substance == 'ethanol'
+
+ return 78.37
+
+ elsif temperature == 'C' && substance == 'gold'
+
+ return 2700
+
+ elsif temperature == 'C' && substance == 'silver'
+
+ return 2162
+
+ elsif temperature == 'C' && substance == 'copper'
+
+ return 2567
+
+ elsif temperature == 'K' && substance == 'water'
+
+ return convert_between_temperature_units(100, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'ethanol'
+
+ return convert_between_temperature_units(78.37, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'gold'
+
+ return convert_between_temperature_units(2700, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'silver'
+
+ return convert_between_temperature_units(2162, 'C', 'K')
+
+ elsif temperature == 'K' && substance == 'copper'
+
+ return convert_between_temperature_units(2567, 'C', 'K')
+
+ elsif temperature == 'F' && substance == 'water'
+
+ return convert_between_temperature_units(100, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'ethanol'
+
+ return convert_between_temperature_units(78.37, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'gold'
+
+ return convert_between_temperature_units(2700, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'silver'
+
+ return convert_between_temperature_units(2162, 'C', 'F')
+
+ elsif temperature == 'F' && substance == 'copper'
+
+ return convert_between_temperature_units(2567, 'C', 'F')
+
+ end
+
+end