Skip to content

Commit

Permalink
Handle different lset elements in lset#group_count
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Tan authored and Anthony Tan committed Nov 8, 2017
1 parent 507ee8d commit 4a980c0
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/bud/lattice-lib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,15 @@ def inspect
# Assume key_cols for now gives indices
rv = Hash.new(Bud::MaxLattice.new(0))
@v.each do |t|
unless t.class == Array
raise Bud::TypeError, "group_count only works if lset elements are type Array"
end

key = []
key_cols.each do |ind|
if ind >= t.length
raise Bud::Error, "lset element in group_count does not have column index #{ind}"
end
key << t[ind]
end
rv[key] += 1
Expand Down
17 changes: 17 additions & 0 deletions test/tc_lattice.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,23 @@ def test_set_multiple_groupcnt
assert_equal(expected, i.res.current_value.reveal)
end

def test_set_error_groupcnt
i = SetSimpleGroupCnt.new
i.tick

i.s1 <+ ['a1']
assert_raises(Bud::TypeError) do
i.tick
end

i = SetSimpleGroupCnt.new
i.tick
i.s1 <+ [['a1', 1], []]
assert_raises(Bud::Error) do
i.tick
end
end

def test_set_product
i = SetProduct.new
i.tick
Expand Down

0 comments on commit 4a980c0

Please sign in to comment.