Решение на Осма задача от Малина Демирова

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

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

Резултати

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

Код

class Spreadsheet
attr_accessor :rows, :columns, :table_elements
def initialize(table_elements)
@name = 'Spreadsheet'
@rows = []
@columns = []
@table_elements = table_elements
end
def new
p ""
end
def new(table_elements)
@table_elements << table_elements.lines.map(&:chomp)
@table_elements.each do |maxes, rows|
rows.split(/(\t)/).strip do |value, column|
maxes[column] = [(maxes[column] || 0), value.to_s.length].max
#if value[0] == "="
# formula_name = value.partition('=').first
# first_element = value.match("\((\d+)\)")[1]
# second_element = value.match("\(\d+))\)")[1]
# case formula_name
# when "ADD" then add(first_element)
# when "MULTIPLY" multiply()
# end
# end
end
maxes
end
end
def to_s
"#{@table_elements.gsub(" ", "\t").strip}"
end
def empty?
if @table_elements == ""
return true
else return false
end
end
#def cell_at(cell_index)
#end
#def [](cell_index)
#end
def add(argument_one, argument_two, *optional)
if optional == nil
argument_one + argument_two
else
argument_one + argument_two +
(optional.inject(0) { |sum, number| sum + number })
end
end
def multiply(argument_one, argument_two, *optional)
if optional == nil
argument_one * argument_two
else
argument_one * argument_two *
(optional.inject(0) { |value, number| value * number })
end
end
def subtract(argument_one, argument_two)
argument_one - argument_two
end
# def divide(argument_one, argument_two)
# argument_one / argument_two
# end
end

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

FF..F...FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) Spreadsheet#new can be called with no arguments or with a single string argument
     Failure/Error: Spreadsheet.new
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-1tcao89/solution.rb:5:in `initialize'
     # /tmp/d20160121-5693-1tcao89/spec.rb:4:in `new'
     # /tmp/d20160121-5693-1tcao89/spec.rb:4:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Spreadsheet#new creates a blank sheet when no arguments are passed
     Failure/Error: expect(Spreadsheet.new).to be_empty
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-1tcao89/solution.rb:5:in `initialize'
     # /tmp/d20160121-5693-1tcao89/spec.rb:10:in `new'
     # /tmp/d20160121-5693-1tcao89/spec.rb:10:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Spreadsheet#to_s returns blank tables as blank strings
     Failure/Error: expect(Spreadsheet.new.to_s).to eq ''
     ArgumentError:
       wrong number of arguments (0 for 1)
     # /tmp/d20160121-5693-1tcao89/solution.rb:5:in `initialize'
     # /tmp/d20160121-5693-1tcao89/spec.rb:24:in `new'
     # /tmp/d20160121-5693-1tcao89/spec.rb:24:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Spreadsheet#to_s splits cells by two or more spaces
     Failure/Error: expect(Spreadsheet.new("foo  bar   42\nbaz    larodi  100").to_s).to eq "foo\tbar\t42\nbaz\tlarodi\t100"
       
       expected: "foo\tbar\t42\nbaz\tlarodi\t100"
            got: "foo\tbar\t 42\nbaz\t\tlarodi\t100"
       
       (compared using ==)
       
       Diff:
       @@ -1,3 +1,3 @@
       -foo	bar	42
       -baz	larodi	100
       +foo	bar	 42
       +baz		larodi	100
     # /tmp/d20160121-5693-1tcao89/spec.rb:40:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Spreadsheet#to_s returns the evaluated spreadsheet as a table
     Failure/Error: expect(sheet.to_s).to eq \
       
       expected: "foo\t10\t2.1\t15\nbar\t11\t2.2\t5\nbaz\t12\t2.3\t27.60"
            got: "foo\t 10\t2.1\t =ADD(B1, C1, 2.9)\n\t\t\t\tbar\t 11\t2.2\t =DIVIDE(B2, C2)\n\t\t\t\tbaz\t 12\t2.3\t =MULTIPLY(C3, B3)"
       
       (compared using ==)
       
       Diff:
       @@ -1,4 +1,4 @@
       -foo	10	2.1	15
       -bar	11	2.2	5
       -baz	12	2.3	27.60
       +foo	 10	2.1	 =ADD(B1, C1, 2.9)
       +				bar	 11	2.2	 =DIVIDE(B2, C2)
       +				baz	 12	2.3	 =MULTIPLY(C3, B3)
     # /tmp/d20160121-5693-1tcao89/spec.rb:50:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Spreadsheet#cell_at raises and exception for non-existant cells
     Failure/Error: expect { Spreadsheet.new('foo')['B10'] }.to raise_error(Spreadsheet::Error, /Cell 'B10' does not exist/)
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:59:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Spreadsheet#cell_at returns the raw value of existing cells
     Failure/Error: expect(sheet.cell_at('A1')).to eq 'foo'
     NoMethodError:
       undefined method `cell_at' for #<Spreadsheet:0x007f5472b44d08>
     # /tmp/d20160121-5693-1tcao89/spec.rb:68:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Spreadsheet#[] raises an exception for non-existant cells
     Failure/Error: expect { Spreadsheet.new()['A1'] }.to raise_error(Spreadsheet::Error, /Cell 'A1' does not exist/)
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:75:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) Spreadsheet#[] returns the value of existing cells for simple cell indexes
     Failure/Error: expect(sheet['A1']).to eq 'foo'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472b28c20>
     # /tmp/d20160121-5693-1tcao89/spec.rb:84:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) Spreadsheet#[] returns the value of existing cells for complex cell indexes
     Failure/Error: expect(sheet['AD1']).to eq 'b'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472aada70>
     # /tmp/d20160121-5693-1tcao89/spec.rb:93:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) Spreadsheet#[] returns the calculated value of formulae cells
     Failure/Error: expect(sheet['A1']).to eq 'foo'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472aa5ed8>
     # /tmp/d20160121-5693-1tcao89/spec.rb:101:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) Spreadsheet#[] adds two numbers with ADD
     Failure/Error: expect(sheet['A1']).to eq('4')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472a9a880>
     # /tmp/d20160121-5693-1tcao89/spec.rb:109:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) Spreadsheet#[] adds five numbers with ADD
     Failure/Error: expect(sheet['A1']).to eq('15')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472a960a0>
     # /tmp/d20160121-5693-1tcao89/spec.rb:115:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) Spreadsheet#[] raises an exception for less than two arguments passed to ADD
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'ADD': expected at least 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:120:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) Spreadsheet#[] adds numbers from cell references and as immediate arguments with ADD
     Failure/Error: expect(sheet['B1']).to eq('55')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472a7e978>
     # /tmp/d20160121-5693-1tcao89/spec.rb:131:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) Spreadsheet#[] adds numbers only from cell references with ADD
     Failure/Error: expect(sheet['D1']).to eq('10')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472a75eb8>
     # /tmp/d20160121-5693-1tcao89/spec.rb:137:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) Spreadsheet#[] multiplies numbers with MULTIPLY
     Failure/Error: expect(sheet1['A1']).to eq('120')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472a5c6e8>
     # /tmp/d20160121-5693-1tcao89/spec.rb:144:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) Spreadsheet#[] raises an exception for less than two arguments to MULTIPLY
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'MULTIPLY': expected at least 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:150:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) Spreadsheet#[] subtracts two numbers with SUBTRACT
     Failure/Error: expect(sheet['A1']).to eq('2')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f547286dd28>
     # /tmp/d20160121-5693-1tcao89/spec.rb:161:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  20) Spreadsheet#[] subtracts numbers via cell references
     Failure/Error: expect(sheet['D1']).to eq('4')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472867928>
     # /tmp/d20160121-5693-1tcao89/spec.rb:167:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  21) Spreadsheet#[] raises an exception when SUBTRACT is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'SUBTRACT': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:172:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  22) Spreadsheet#[] divides two numbers with DIVIDE
     Failure/Error: expect(sheet['A1']).to eq('42')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5472851790>
     # /tmp/d20160121-5693-1tcao89/spec.rb:183:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  23) Spreadsheet#[] divides numbers via cell references
     Failure/Error: expect(sheet1['C1']).to eq('42')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f547284e590>
     # /tmp/d20160121-5693-1tcao89/spec.rb:190:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  24) Spreadsheet#[] raises an exception when DIVIDE is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'DIVIDE': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:196:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  25) Spreadsheet#[] calculates the modulo of two numbers with MOD
     Failure/Error: expect(Spreadsheet.new('=MOD(42, 5)')['A1']).to eq('2')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f547283b238>
     # /tmp/d20160121-5693-1tcao89/spec.rb:205:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  26) Spreadsheet#[] calculates the modulo of two numbers with MOD via cell references
     Failure/Error: expect(sheet1['C1']).to eq('4')
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f54728310d0>
     # /tmp/d20160121-5693-1tcao89/spec.rb:214:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  27) Spreadsheet#[] raises an exception when MOD is called with a wrong number of arguments
     Failure/Error: Spreadsheet::Error, /Wrong number of arguments for 'MOD': expected 2, got 1/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:220:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  28) Spreadsheet#[] adds floating point numbers with ADD
     Failure/Error: expect(Spreadsheet.new('10  =ADD(A1, 1.1)')['B1']).to eq '11.10'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5473712608>
     # /tmp/d20160121-5693-1tcao89/spec.rb:229:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  29) Spreadsheet#[] subtracts floating point numbers with SUBTRACT
     Failure/Error: expect(Spreadsheet.new('10  =SUBTRACT(A1, 1.1)')['B1']).to eq '8.90'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f54737106f0>
     # /tmp/d20160121-5693-1tcao89/spec.rb:234:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  30) Spreadsheet#[] multiplies floating point numbers with MULTIPLY
     Failure/Error: expect(Spreadsheet.new('10  =MULTIPLY(A1, 1.1)')['B1']).to eq '11'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5473706498>
     # /tmp/d20160121-5693-1tcao89/spec.rb:239:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  31) Spreadsheet#[] divides floating point numbers with DIVIDE
     Failure/Error: expect(Spreadsheet.new('10  =DIVIDE(A1, 4)')['B1']).to eq '2.50'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f5473704878>
     # /tmp/d20160121-5693-1tcao89/spec.rb:244:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  32) Spreadsheet#[] evaluates deeply-nested cell references
     Failure/Error: expect(Spreadsheet.new('10  =ADD(5, A1)  3  =DIVIDE(B1, C1)  =MOD(D1, 4)')['E1']).to eq '1'
     NoMethodError:
       undefined method `[]' for #<Spreadsheet:0x007f54736f2560>
     # /tmp/d20160121-5693-1tcao89/spec.rb:250:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  33) Spreadsheet#[] raises an exception for unknown functions
     Failure/Error: Spreadsheet::Error, /Unknown function 'FOO'/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:255:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  34) Spreadsheet#[] raises an exception for missing cells passed as function arguments
     Failure/Error: Spreadsheet::Error, /Cell 'B4' does not exist/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:261:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  35) Spreadsheet#[] raises an exception for invalid expressions
     Failure/Error: Spreadsheet::Error, /Invalid expression 'FOO'/
     NameError:
       uninitialized constant Spreadsheet::Error
     # /tmp/d20160121-5693-1tcao89/spec.rb:267:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.03213 seconds
40 examples, 35 failures

Failed examples:

rspec /tmp/d20160121-5693-1tcao89/spec.rb:3 # Spreadsheet#new can be called with no arguments or with a single string argument
rspec /tmp/d20160121-5693-1tcao89/spec.rb:9 # Spreadsheet#new creates a blank sheet when no arguments are passed
rspec /tmp/d20160121-5693-1tcao89/spec.rb:23 # Spreadsheet#to_s returns blank tables as blank strings
rspec /tmp/d20160121-5693-1tcao89/spec.rb:39 # Spreadsheet#to_s splits cells by two or more spaces
rspec /tmp/d20160121-5693-1tcao89/spec.rb:43 # Spreadsheet#to_s returns the evaluated spreadsheet as a table
rspec /tmp/d20160121-5693-1tcao89/spec.rb:58 # Spreadsheet#cell_at raises and exception for non-existant cells
rspec /tmp/d20160121-5693-1tcao89/spec.rb:62 # Spreadsheet#cell_at returns the raw value of existing cells
rspec /tmp/d20160121-5693-1tcao89/spec.rb:74 # Spreadsheet#[] raises an exception for non-existant cells
rspec /tmp/d20160121-5693-1tcao89/spec.rb:78 # Spreadsheet#[] returns the value of existing cells for simple cell indexes
rspec /tmp/d20160121-5693-1tcao89/spec.rb:90 # Spreadsheet#[] returns the value of existing cells for complex cell indexes
rspec /tmp/d20160121-5693-1tcao89/spec.rb:98 # Spreadsheet#[] returns the calculated value of formulae cells
rspec /tmp/d20160121-5693-1tcao89/spec.rb:106 # Spreadsheet#[] adds two numbers with ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:112 # Spreadsheet#[] adds five numbers with ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:118 # Spreadsheet#[] raises an exception for less than two arguments passed to ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:128 # Spreadsheet#[] adds numbers from cell references and as immediate arguments with ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:134 # Spreadsheet#[] adds numbers only from cell references with ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:140 # Spreadsheet#[] multiplies numbers with MULTIPLY
rspec /tmp/d20160121-5693-1tcao89/spec.rb:148 # Spreadsheet#[] raises an exception for less than two arguments to MULTIPLY
rspec /tmp/d20160121-5693-1tcao89/spec.rb:158 # Spreadsheet#[] subtracts two numbers with SUBTRACT
rspec /tmp/d20160121-5693-1tcao89/spec.rb:164 # Spreadsheet#[] subtracts numbers via cell references
rspec /tmp/d20160121-5693-1tcao89/spec.rb:170 # Spreadsheet#[] raises an exception when SUBTRACT is called with a wrong number of arguments
rspec /tmp/d20160121-5693-1tcao89/spec.rb:180 # Spreadsheet#[] divides two numbers with DIVIDE
rspec /tmp/d20160121-5693-1tcao89/spec.rb:186 # Spreadsheet#[] divides numbers via cell references
rspec /tmp/d20160121-5693-1tcao89/spec.rb:194 # Spreadsheet#[] raises an exception when DIVIDE is called with a wrong number of arguments
rspec /tmp/d20160121-5693-1tcao89/spec.rb:204 # Spreadsheet#[] calculates the modulo of two numbers with MOD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:210 # Spreadsheet#[] calculates the modulo of two numbers with MOD via cell references
rspec /tmp/d20160121-5693-1tcao89/spec.rb:218 # Spreadsheet#[] raises an exception when MOD is called with a wrong number of arguments
rspec /tmp/d20160121-5693-1tcao89/spec.rb:228 # Spreadsheet#[] adds floating point numbers with ADD
rspec /tmp/d20160121-5693-1tcao89/spec.rb:233 # Spreadsheet#[] subtracts floating point numbers with SUBTRACT
rspec /tmp/d20160121-5693-1tcao89/spec.rb:238 # Spreadsheet#[] multiplies floating point numbers with MULTIPLY
rspec /tmp/d20160121-5693-1tcao89/spec.rb:243 # Spreadsheet#[] divides floating point numbers with DIVIDE
rspec /tmp/d20160121-5693-1tcao89/spec.rb:249 # Spreadsheet#[] evaluates deeply-nested cell references
rspec /tmp/d20160121-5693-1tcao89/spec.rb:253 # Spreadsheet#[] raises an exception for unknown functions
rspec /tmp/d20160121-5693-1tcao89/spec.rb:259 # Spreadsheet#[] raises an exception for missing cells passed as function arguments
rspec /tmp/d20160121-5693-1tcao89/spec.rb:265 # Spreadsheet#[] raises an exception for invalid expressions

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

Малина обнови решението на 11.01.2016 17:11 (преди над 8 години)

+class Spreadsheet
+
+attr_accessor :rows, :columns, :table_elements
+
+def initialize(table_elements)
+ @name = 'Spreadsheet'
+ @rows = []
+ @columns = []
+ @table_elements = table_elements
+end
+
+def new
+ p ""
+end
+
+def new(table_elements)
+ @table_elements << table_elements.lines.map(&:chomp)
+ @table_elements.each do |maxes, rows|
+ rows.split(/(\t)/).strip do |value, column|
+ maxes[column] = [(maxes[column] || 0), value.to_s.length].max
+ #if value[0] == "="
+ # formula_name = value.partition('=').first
+ # first_element = value.match("\((\d+)\)")[1]
+ # second_element = value.match("\(\d+))\)")[1]
+ # case formula_name
+ # when "ADD" then add(first_element)
+ # when "MULTIPLY" multiply()
+ # end
+ # end
+ end
+ maxes
+ end
+end
+
+def to_s
+ "#{@table_elements.gsub(" ", "\t").strip}"
+end
+
+def empty?
+if @table_elements == ""
+ return true
+else return false
+end
+end
+
+#def cell_at(cell_index)
+
+#end
+
+#def [](cell_index)
+
+#end
+
+ def add(argument_one, argument_two, *optional)
+ if optional == nil
+ argument_one + argument_two
+ else
+ argument_one + argument_two +
+ (optional.inject(0) { |sum, number| sum + number })
+ end
+ end
+
+ def multiply(argument_one, argument_two, *optional)
+ if optional == nil
+ argument_one * argument_two
+ else
+ argument_one * argument_two *
+ (optional.inject(0) { |value, number| value * number })
+ end
+ end
+
+ def subtract(argument_one, argument_two)
+ argument_one - argument_two
+ end
+
+ # def divide(argument_one, argument_two)
+ # argument_one / argument_two
+ # end
+end