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

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

Към профила на Николета Янкова

Резултати

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

Код

# first task
def convert_between_temperature_units(degree, x, y)
if x == 'C' && y == 'F'
degree * 1.8 + 32
elsif x == 'F' && y == 'C'
(degree - 32) / 1.8
elsif x == 'C' && y == 'K'
degree + 273.15
elsif x == 'K' && y == 'C'
degree - 273.15
elsif x == 'F' && y == 'K'
(degree + 459.67) / 1.8
elsif x == 'K' && y == 'F'
degree * 1.8 - 459.67
else puts "Wrong input!"
end
end
# second task
MELTING =
{
"water" => 0,
"ethanol" => -144,
"gold" => 1_064,
"silver" => 961.8,
"copper" => 1_085
}
def melting_point_of_substance(substance, unit)
if MELTING.key?(substance)
if unit == 'C'
puts MELTING[substance]
elsif unit == 'K' || unit == 'F'
temp = MELTING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end
# third task
BOILING =
{
"water" => 100,
"ethanol" => 78.37,
"gold" => 2_700,
"silver" => 2_162,
"copper" => 2_567
}
def boiling_point_of_substance(substance, unit)
if BOILING.key?(substance)
if unit == 'C'
puts BOILING[substance]
elsif unit == 'K' || unit == 'F'
temp = BOILING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end

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

Wrong input!
F......0
F-144
F1064
F961.8
F1085
F100
F78.37
F2700
F2162
F2567
F

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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1pfa2pk/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) #melting_point_of_substance knows the melting point of water
     Failure/Error: expect(melting_point_of_substance(substance, units)).to be_within(0.01).of(expected_degrees)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:63: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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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)>'

  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)
     ArgumentError:
       The actual value (nil) must respond to `-`
     # /tmp/d20161018-13513-1pfa2pk/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1pfa2pk/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.00806 seconds
17 examples, 11 failures

Failed examples:

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

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

Николета обнови решението на 17.10.2016 00:05 (преди около 8 години)

+# first task
+def convert_between_temperature_units(degree, x, y)
+ if x == 'C' && y == 'F'
+ degree * 1.8 + 32
+ elsif x == 'F' && y == 'C'
+ (degree - 32) / 1.8
+ elsif x == 'C' && y == 'K'
+ degree + 273.15
+ elsif x == 'K' && y == 'C'
+ degree - 273.15
+ elsif x == 'F' && y == 'K'
+ (degree + 459.67) / 1.8
+ elsif x == 'K' && y == 'F'
+ degree * 1.8 - 459.67
+ else puts "Wrong input!"
+ end
+end
+
+# second task
+MELTING =
+ {
+ "water" => 0,
+ "ethanol" => -144,
+ "gold" => 1_064,
+ "silver" => 961.8,
+ "copper" => 1_085
+ }
+
+def melting_point_of_substance(substance, unit)
+ if MELTING.key?(substance)
+ if unit == 'C' then puts MELTING[substance]
+ elsif unit == 'K' || unit == 'F'
+ temp = MELTING[substance]
+ puts convert_between_temperature_units(temp, 'C', unit)
+ else puts "Wrong input!"
+ end
+ else puts "Wrong input!"
+ end
+end
+
+# third task
+BOILING =
+ {
+ "water" => 100,
+ "ethanol" => 78.37,
+ "gold" => 2_700,
+ "silver" => 2_162,
+ "copper" => 2_567
+ }
+
+def boiling_point_of_substance(substance, unit)
+ if BOILING.key?(substance)
+ if unit == 'C' then puts BOILING[substance]
+ elsif unit == 'K' || unit == 'F'
+ temp = BOILING[substance]
+ puts convert_between_temperature_units(temp, 'C', unit)
+ else puts "Wrong input!"
+ end
+ else puts "Wrong input!"
+ end
+end

Николета обнови решението на 17.10.2016 00:08 (преди около 8 години)

# first task
def convert_between_temperature_units(degree, x, y)
if x == 'C' && y == 'F'
degree * 1.8 + 32
elsif x == 'F' && y == 'C'
(degree - 32) / 1.8
elsif x == 'C' && y == 'K'
degree + 273.15
elsif x == 'K' && y == 'C'
degree - 273.15
elsif x == 'F' && y == 'K'
(degree + 459.67) / 1.8
elsif x == 'K' && y == 'F'
degree * 1.8 - 459.67
else puts "Wrong input!"
end
end
# second task
MELTING =
{
"water" => 0,
"ethanol" => -144,
"gold" => 1_064,
"silver" => 961.8,
"copper" => 1_085
}
def melting_point_of_substance(substance, unit)
if MELTING.key?(substance)
- if unit == 'C' then puts MELTING[substance]
+ if unit == 'C'
+ puts MELTING[substance]
elsif unit == 'K' || unit == 'F'
temp = MELTING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end
# third task
BOILING =
{
"water" => 100,
"ethanol" => 78.37,
"gold" => 2_700,
"silver" => 2_162,
"copper" => 2_567
}
def boiling_point_of_substance(substance, unit)
if BOILING.key?(substance)
- if unit == 'C' then puts BOILING[substance]
+ if unit == 'C'
+ puts BOILING[substance]
elsif unit == 'K' || unit == 'F'
temp = BOILING[substance]
puts convert_between_temperature_units(temp, 'C', unit)
else puts "Wrong input!"
end
else puts "Wrong input!"
end
end