Skip to content

Commit

Permalink
Fix Indexable#each_repeated_combination(n) when n > size (crystal…
Browse files Browse the repository at this point in the history
  • Loading branch information
HertzDevil authored Dec 15, 2023
1 parent c53dd72 commit 1c8a68a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions spec/std/indexable_spec.cr
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require "spec"
require "spec/helpers/iterate"

private class SafeIndexable
include Indexable(Int32)
Expand Down Expand Up @@ -811,5 +812,10 @@ describe Indexable do
end
iter.next.should be_a(Iterator::Stop)
end

describe "n > size (#14088)" do
it_iterates "#each_repeated_combination", [[1, 1, 1], [1, 1, 2], [1, 2, 2], [2, 2, 2]], SafeIndexable.new(2, 1).each_repeated_combination(3)
it_iterates "#each_repeated_combination", [[1, 1, 1, 1], [1, 1, 1, 2], [1, 1, 2, 2], [1, 2, 2, 2], [2, 2, 2, 2]], SafeIndexable.new(2, 1).each_repeated_combination(4)
end
end
end
2 changes: 1 addition & 1 deletion src/indexable.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1483,7 +1483,7 @@ module Indexable(T)
@copy = array.dup
@indices = Array.new(@size, 0)
@pool = @indices.map { |i| @copy[i] }
@stop = @size > @n
@stop = false
@i = @size - 1
@first = true
end
Expand Down

0 comments on commit 1c8a68a

Please sign in to comment.