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

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

Към профила на Стоян Томицин

Резултати

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

Код

def convert_between_temperature_units(degree, unit1, unit2)
if unit1 == 'C' && unit2 == 'F'
degree = degree * 1.8000 + 32
elsif unit1 == 'C' && unit2 == 'K'
degree += 273.15
elsif unit1 == 'C' && unit2 == 'C'
degree
elsif unit1 == 'F' && unit2 == 'K'
degree = (degree + 459.67) / 1.8000
elsif unit1 == 'K' && unit2 == 'F'
degree = degree * 1.8000 - 459.67
elsif unit1 == 'K' && unit2 == 'C'
degree -= 273.15
elsif unit1 == 'F' && unit2 == 'C'
degree = (degree - 32) / 1.8000
elsif unit1 == 'F' && unit2 == 'F'
degree
elsif unit1 == 'K' && unit2 == 'K'
degree
end
end
def melting_point_of_substance(name, unit)
if name == 'water' && unit == 'C'
0
elsif name == 'water' && unit == 'K'
273.15
elsif name == 'water' && unit == 'F'
32
elsif name == 'ethanol' && unit == 'C'
-114
elsif name == 'ethanol' && unit == 'K'
159.14
elsif name == 'ethanol' && unit == 'F'
-173.20
elsif name == 'gold' && unit == 'C'
1064
elsif name == 'gold' && unit == 'K'
1337.15
elsif name == 'gold' && unit == 'F'
1947.2
elsif name == 'silver' && unit == 'C'
961.8
elsif name == 'silver' && unit == 'K'
1234.94
elsif name == 'silver' && unit == 'F'
1763.24
elsif name == 'copper' && unit == 'C'
1085
elsif name == 'copper' && unit == 'K'
1358.15
elsif name == 'copper' && unit == 'F'
1985
end
end
def boiling_point_of_substance(name, unit)
if name == 'water' && unit == 'C'
100
elsif name == 'water' && unit == 'K'
373.15
elsif name == 'water' && unit == 'F'
212
elsif name == 'ethanol' && unit == 'C'
78.37
elsif name == 'ethanol' && unit == 'K'
351.52
elsif name == 'ethanol' && unit == 'F'
173.06
elsif name == 'gold' && unit == 'C'
2700
elsif name == 'gold' && unit == 'K'
2973.15
elsif name == 'gold' && unit == 'F'
4892
elsif name == 'silver' && unit == 'C'
2162
elsif name == 'silver' && unit == 'K'
2435.15
elsif name == 'silver' && unit == 'F'
3923.6
elsif name == 'copper' && unit == 'C'
2567
elsif name == 'copper' && unit == 'K'
2840.15
elsif name == 'copper' && unit == 'F'
4652.6
end
end

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

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

Failures:

  1) #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 159.14 to be within 0.01 of 159.15
     # /tmp/d20161018-13513-1t0n8v3/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1t0n8v3/spec.rb:70: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.00785 seconds
17 examples, 1 failure

Failed examples:

rspec /tmp/d20161018-13513-1t0n8v3/spec.rb:68 # #melting_point_of_substance knows the melting point of ethanol

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

Стоян обнови решението на 16.10.2016 23:38 (преди около 8 години)

+def convert_between_temperature_units(degree, unit1, unit2)
+ if unit1 == 'C' && unit2 == 'F'
+ degree = degree * 1.8000 + 32
+ elsif unit1 == 'C' && unit2 == 'K'
+ degree += 273.15
+ elsif unit1 == 'C' && unit2 == 'C'
+ degree
+ elsif unit1 == 'F' && unit2 == 'K'
+ degree = (degree + 459.67) / 1.8000
+ elsif unit1 == 'K' && unit2 == 'F'
+ degree = degree * 1.8000 - 459.67
+ elsif unit1 == 'K' && unit2 == 'C'
+ degree -= 273.15
+ elsif unit1 == 'F' && unit2 == 'C'
+ degree = (degree - 32) / 1.8000
+ elsif unit1 == 'F' && unit2 == 'F'
+ degree
+ elsif unit1 == 'K' && unit2 == 'K'
+ degree
+ end
+end
+
+def melting_point_of_substance(name, unit)
+ if name == 'water' && unit == 'C'
+ 0
+ elsif name == 'water' && unit == 'K'
+ 273.15
+ elsif name == 'water' && unit == 'F'
+ 32
+ elsif name == 'ethanol' && unit == 'C'
+ -114
+ elsif name == 'ethanol' && unit == 'K'
+ 159.14
+ elsif name == 'ethanol' && unit == 'F'
+ -173.20
+ elsif name == 'gold' && unit == 'C'
+ 1064
+ elsif name == 'gold' && unit == 'K'
+ 1337.15
+ elsif name == 'gold' && unit == 'F'
+ 1947.2
+ elsif name == 'silver' && unit == 'C'
+ 961.8
+ elsif name == 'silver' && unit == 'K'
+ 1234.94
+ elsif name == 'silver' && unit == 'F'
+ 1763.24
+ elsif name == 'copper' && unit == 'C'
+ 1085
+ elsif name == 'copper' && unit == 'K'
+ 1358.15
+ elsif name == 'copper' && unit == 'F'
+ 1985
+ end
+end
+
+def boiling_point_of_substance(name, unit)
+ if name == 'water' && unit == 'C'
+ 100
+ elsif name == 'water' && unit == 'K'
+ 373.15
+ elsif name == 'water' && unit == 'F'
+ 212
+ elsif name == 'ethanol' && unit == 'C'
+ 78.37
+ elsif name == 'ethanol' && unit == 'K'
+ 351.52
+ elsif name == 'ethanol' && unit == 'F'
+ 173.06
+ elsif name == 'gold' && unit == 'C'
+ 2700
+ elsif name == 'gold' && unit == 'K'
+ 2973.15
+ elsif name == 'gold' && unit == 'F'
+ 4892
+ elsif name == 'silver' && unit == 'C'
+ 2162
+ elsif name == 'silver' && unit == 'K'
+ 2435.15
+ elsif name == 'silver' && unit == 'F'
+ 3923.6
+ elsif name == 'copper' && unit == 'C'
+ 2567
+ elsif name == 'copper' && unit == 'K'
+ 2840.15
+ elsif name == 'copper' && unit == 'F'
+ 4652.6
+ end
+end