Skip to content
Browse files

Allow ranges for column and row access.

  • Loading branch information...
1 parent 81fd1d9 commit cf53db12b73e4fb7fb60eb7c27728cbe4f3d68b6 @wtaysom committed Nov 3, 2010
Showing with 10 additions and 6 deletions.
  1. +4 −6 lib/rglpk.rb
  2. +6 −0 test/test_basic.rb
View
10 lib/rglpk.rb
@@ -24,15 +24,13 @@ def each(&block)
end
def [](i)
- if i.kind_of?(Numeric)
- @array[i]
- elsif i.kind_of?(String)
- raise RuntimeError if self[1].nil?
+ if i.kind_of?(String)
+ raise RuntimeError, "no rows" if self[1].nil?
idx = Glpk_wrapper.send(glp_find_method, self[1].p.lp, i)
- raise ArgumentError if idx == 0
+ raise ArgumentError, "no row with name #{i.inspect}" if idx == 0
@array[idx - 1]
else
- raise ArgumentError
+ @array[i]
end
end
View
6 test/test_basic.rb
@@ -151,6 +151,12 @@ def test_row_get_by_name
p.rows[0].name = 'test'
assert_equal [1, 2], p.rows['test'].get
end
+
+ def test_get_row_range
+ p = Rglpk::Problem.new
+ p.add_rows(5)
+ assert_equal 2, p.rows[3..-1].size
+ end
def test_col_get_by_name
p = Rglpk::Problem.new

0 comments on commit cf53db1

Please sign in to comment.
Something went wrong with that request. Please try again.