Skip to content

Commit

Permalink
Merge pull request #1017 from AI-Mozi/add_tests_for_Enumerator_product
Browse files Browse the repository at this point in the history
Add spec for `Enumerator#product`
  • Loading branch information
andrykonchin authored May 9, 2023
2 parents b5498bf + f460d9a commit aca4695
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions core/enumerator/product_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
require_relative '../../spec_helper'

ruby_version_is "3.2" do
describe "Enumerator.product" do
it "creates an infinite enumerator" do
enum = Enumerator.product(1.., ["A", "B"])
enum.take(5).should == [[1, "A"], [1, "B"], [2, "A"], [2, "B"], [3, "A"]]
end

it "accepts a block" do
elems = []
enum = Enumerator.product(1..2, ["X", "Y"]) { elems << _1 }

elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
end

it "accepts infinite enumerator and uknown enumerator" do
enum = Enumerator.product(1.., Enumerator.new { |y| y << "X" << "Y" })
enum.take(4).should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]]
end
end
end

0 comments on commit aca4695

Please sign in to comment.