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

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

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

Резултати

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

Код

def convert_between_temperature_units(degrees, unit_degrees, unit_result)
if unit_result == 'C' && unit_degrees == 'F'
((degrees - 32) / 1.8).round(2)
elsif unit_result == 'F' && unit_degrees == 'C'
(degrees * 1.8 + 32).round(2)
elsif unit_result == 'K' && unit_degrees == 'C'
(degrees + 273.15).round(2)
else
(degrees - 273.15).round(2)
end
end
def melting_point_of_substance(substance, unit_degrees)
substances = { water: 0, ethanol: -114, gold: 1064, silver: 961.8, copper: 1085 }
if unit_degrees == 'C'
substances[substance].to_i
else
convert_between_temperature_units(substances[substance].to_i, 'C', unit_degrees)
end
end
def boiling_point_of_substance(substance, unit_degrees)
substances = { water: 100, ethanol: 78.37, gold: 2700, silver: 2162, copper: 2567 }
if unit_degrees == 'C'
substances[substance].to_i
else
convert_between_temperature_units(substances[substance].to_i, 'C', unit_degrees)
end
end

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

F....FF.FFFFFFFFF

Failures:

  1) #convert_between_temperature_units can convert to the same unit
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected -231.15 to be within 0.0001 of 42
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:3: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 Kelvin to Fahrenheit
     Failure/Error: expect(actual_to_value).to be_within(0.0001).of(expected_to_value)
       expected 1.0 to be within 0.0001 of 33.8
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1p3pkr5/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)>'

  3) #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 -239.35 to be within 0.0001 of 274.15
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1p3pkr5/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)>'

  4) #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 0 to be within 0.01 of -114
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1p3pkr5/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)>'

  5) #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 0 to be within 0.01 of 1064
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:75: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 silver
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 0 to be within 0.01 of 961.8
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:81: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) #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 0 to be within 0.01 of 1085
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:87: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 water
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 0 to be within 0.01 of 100
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:99: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 ethanol
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 0 to be within 0.01 of 78.37
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:105: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 gold
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 0 to be within 0.01 of 2700
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:111: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 silver
     Failure/Error: expect(boiling_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
       expected 0 to be within 0.01 of 2162
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:117: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)>'

  12) #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 0 to be within 0.01 of 2567
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1p3pkr5/spec.rb:123: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.00783 seconds
17 examples, 12 failures

Failed examples:

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

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

Малина обнови решението на 17.10.2016 13:57 (преди над 7 години)

+def convert_between_temperature_units(degrees, unit_degrees, unit_result)
+ if unit_result == 'C' && unit_degrees == 'F'
+ ((degrees - 32) / 1.8).round(2)
+ elsif unit_result == 'F' && unit_degrees == 'C'
+ (degrees * 1.8 + 32).round(2)
+ elsif unit_result == 'K' && unit_degrees == 'C'
+ (degrees + 273.15).round(2)
+ else
+ (degrees - 273.15).round(2)
+ end
+end

Малина обнови решението на 17.10.2016 14:54 (преди над 7 години)

def convert_between_temperature_units(degrees, unit_degrees, unit_result)
if unit_result == 'C' && unit_degrees == 'F'
((degrees - 32) / 1.8).round(2)
elsif unit_result == 'F' && unit_degrees == 'C'
(degrees * 1.8 + 32).round(2)
elsif unit_result == 'K' && unit_degrees == 'C'
(degrees + 273.15).round(2)
else
(degrees - 273.15).round(2)
end
+end
+
+def melting_point_of_substance(substance, unit_degrees)
+ substances = { water: 0, ethanol: -114, gold: 1064, silver: 961.8, copper: 1085 }
+
+ convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+end
+
+def boiling_point_of_substance(substance, unit_degrees)
+ substances = { water: 100, ethanol: 78.37, gold: 2700, silver: 2162, copper: 2567 }
+
+ convert_between_temperature_units(substances[substance], 'C', unit_degrees)
end

Малина обнови решението на 17.10.2016 15:16 (преди над 7 години)

def convert_between_temperature_units(degrees, unit_degrees, unit_result)
if unit_result == 'C' && unit_degrees == 'F'
((degrees - 32) / 1.8).round(2)
elsif unit_result == 'F' && unit_degrees == 'C'
(degrees * 1.8 + 32).round(2)
elsif unit_result == 'K' && unit_degrees == 'C'
(degrees + 273.15).round(2)
else
(degrees - 273.15).round(2)
end
end
def melting_point_of_substance(substance, unit_degrees)
substances = { water: 0, ethanol: -114, gold: 1064, silver: 961.8, copper: 1085 }
- convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+ if unit_degrees == 'C'
+ substances[substance].to_i
+ else
+ convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+ end
end
def boiling_point_of_substance(substance, unit_degrees)
substances = { water: 100, ethanol: 78.37, gold: 2700, silver: 2162, copper: 2567 }
-
- convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+
+ if unit_degrees == 'C'
+ substances[substance].to_i.round(2)
+ else
+ convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+ end
end

Малина обнови решението на 17.10.2016 15:33 (преди над 7 години)

def convert_between_temperature_units(degrees, unit_degrees, unit_result)
if unit_result == 'C' && unit_degrees == 'F'
((degrees - 32) / 1.8).round(2)
elsif unit_result == 'F' && unit_degrees == 'C'
(degrees * 1.8 + 32).round(2)
elsif unit_result == 'K' && unit_degrees == 'C'
(degrees + 273.15).round(2)
else
(degrees - 273.15).round(2)
end
end
def melting_point_of_substance(substance, unit_degrees)
substances = { water: 0, ethanol: -114, gold: 1064, silver: 961.8, copper: 1085 }
if unit_degrees == 'C'
substances[substance].to_i
else
- convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+ convert_between_temperature_units(substances[substance].to_i, 'C', unit_degrees)
end
end
def boiling_point_of_substance(substance, unit_degrees)
substances = { water: 100, ethanol: 78.37, gold: 2700, silver: 2162, copper: 2567 }
if unit_degrees == 'C'
- substances[substance].to_i.round(2)
+ substances[substance].to_i
else
- convert_between_temperature_units(substances[substance], 'C', unit_degrees)
+ convert_between_temperature_units(substances[substance].to_i, 'C', unit_degrees)
end
end