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

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

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

Резултати

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

Код

def convert_between_temperature_units(degree, first, last)
if first == 'C'
if last == 'K'
degree + 273.15
elsif last == 'F'
degree * 9 / 5 + 32
end
elsif first == 'K'
if last == 'C'
degree - 273.15
elsif last == 'F'
degree * 9 / 5 - 459.67
end
elsif first == 'F'
if last == 'C'
(degree - 32) * 5 / 9
elsif last == 'K'
(degree + 459.67) * 5 / 9
end
else
puts "Something went wrong!"
end
end
def melting_point_of_substance(material, deg)
if deg == 'C'
if material == 'water'
0
elsif materila == 'ethanol'
-114
elsif material == 'gold'
1064
elsif material == 'silver'
961.8
elsif material == 'copper'
1085
else
puts "That material is not in the sistem!"
end
elsif deg == 'K'
if material == 'water'
convert_between_temperature_units(0, 'C', 'K')
elsif material == 'ethanol'
convert_between_temperature_units(-114, 'C', 'K')
elsif material == 'gold'
convert_between_temperature_units(1064, 'C', 'K')
elsif material == 'silver'
convert_between_temperature_units(961.8, 'C', 'K')
elsif material == 'copper'
convert_between_temperature_units(1085, 'C', 'K')
else
puts "That material is not in the sistem!"
end
else
puts "That temperature unit is not in the sistem!"
end
end
def boiling_point_of_substance(material, deg)
if deg == 'C'
if material == 'water'
100
elsif materila == 'ethanol'
78.37
elsif material == 'gold'
2700
elsif material == 'silver'
2162
elsif material == 'copper'
2567
else
puts "That material is not in the sistem!"
end
elsif deg == 'K'
if material == 'water'
convert_between_temperature_units(100, 'C', 'K')
elsif material == 'ethanol'
convert_between_temperature_units(78.37, 'C', 'K')
elsif material == 'gold'
convert_between_temperature_units(2700, 'C', 'K')
elsif material == 'silver'
convert_between_temperature_units(2162, 'C', 'K')
elsif material == 'copper'
convert_between_temperature_units(2567, 'C', 'K')
else
puts "That material is not in the sistem!"
end
else
puts "That temperature unit is not in the sistem!"
end
end

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

F......That temperature unit is not in the sistem!
FFFFFThat temperature unit is not in the sistem!
FFFFF

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-1flkli9/spec.rb:57:in `expect_conversion'
     # /tmp/d20161018-13513-1flkli9/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-1flkli9/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1flkli9/spec.rb:65: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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f9ec37b3360>
     # /tmp/d20161018-13513-1flkli9/solution.rb:29:in `melting_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f9ec37b0a20>
     # /tmp/d20161018-13513-1flkli9/solution.rb:29:in `melting_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f9ec37ae6d0>
     # /tmp/d20161018-13513-1flkli9/solution.rb:29:in `melting_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_2:0x007f9ec36023e0>
     # /tmp/d20161018-13513-1flkli9/solution.rb:29:in `melting_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:93:in `expect_melting_point_of'
     # /tmp/d20161018-13513-1flkli9/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-1flkli9/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_3:0x007f9ec35e5740>
     # /tmp/d20161018-13513-1flkli9/solution.rb:63:in `boiling_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_3:0x007f9ec35c9d60>
     # /tmp/d20161018-13513-1flkli9/solution.rb:63:in `boiling_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_3:0x007f9ec35b9ca8>
     # /tmp/d20161018-13513-1flkli9/solution.rb:63:in `boiling_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1flkli9/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)
     NameError:
       undefined local variable or method `materila' for #<RSpec::Core::ExampleGroup::Nested_3:0x007f9ec35b36f0>
     # /tmp/d20161018-13513-1flkli9/solution.rb:63:in `boiling_point_of_substance'
     # /tmp/d20161018-13513-1flkli9/spec.rb:129:in `expect_boiling_point_of'
     # /tmp/d20161018-13513-1flkli9/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.00776 seconds
17 examples, 11 failures

Failed examples:

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

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

Калина обнови решението на 17.10.2016 11:56 (преди около 8 години)

+def convert_between_temperature_units(degree, first, last)
+ if first == 'C'
+ if last == 'K'
+ degree + 273.15
+ elsif last == 'F'
+ degree * 9 / 5 + 32
+ end
+ elsif first == 'K'
+ if last == 'C'
+ degree - 273.15
+ elsif last == 'F'
+ degree * 9 / 5 - 459.67
+ end
+ elsif first == 'F'
+ if last == 'C'
+ (degree - 32) * 5 / 9
+ elsif last == 'K'
+ (degree + 459.67) * 5 / 9
+ end
+ else
+ puts "Something went wrong!"
+ end
+end
+
+def melting_point_of_substance(material, deg)
+ if deg == 'C'
+ if material == 'water'
+ 0
+ elsif materila == 'ethanol'
+ -114
+ elsif material == 'gold'
+ 1064
+ elsif material == 'silver'
+ 961.8
+ elsif material == 'copper'
+ 1085
+ else
+ puts "That material is not in the sistem!"
+ end
+ elsif deg == 'K'
+ if material == 'water'
+ convert_between_temperature_units(0, 'C', 'K')
+ elsif material == 'ethanol'
+ convert_between_temperature_units(-114, 'C', 'K')
+ elsif material == 'gold'
+ convert_between_temperature_units(1064, 'C', 'K')
+ elsif material == 'silver'
+ convert_between_temperature_units(961.8, 'C', 'K')
+ elsif material == 'copper'
+ convert_between_temperature_units(1085, 'C', 'K')
+ else
+ puts "That material is not in the sistem!"
+ end
+ else
+ puts "That temperature unit is not in the sistem!"
+ end
+end
+
+def boiling_point_of_substance(material, deg)
+ if deg == 'C'
+ if material == 'water'
+ 100
+ elsif materila == 'ethanol'
+ 78.37
+ elsif material == 'gold'
+ 2700
+ elsif material == 'silver'
+ 2162
+ elsif material == 'copper'
+ 2567
+ else
+ puts "That material is not in the sistem!"
+ end
+ elsif deg == 'K'
+ if material == 'water'
+ convert_between_temperature_units(100, 'C', 'K')
+ elsif material == 'ethanol'
+ convert_between_temperature_units(78.37, 'C', 'K')
+ elsif material == 'gold'
+ convert_between_temperature_units(2700, 'C', 'K')
+ elsif material == 'silver'
+ convert_between_temperature_units(2162, 'C', 'K')
+ elsif material == 'copper'
+ convert_between_temperature_units(2567, 'C', 'K')
+ else
+ puts "That material is not in the sistem!"
+ end
+ else
+ puts "That temperature unit is not in the sistem!"
+ end
+end