From d3992be6b4d8b768fc07b826d95a2ddd198e4433 Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Mon, 8 May 2023 15:59:54 +0200 Subject: [PATCH 1/2] add spec for Enumerator#product --- core/enumerator/product_spec.rb | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 core/enumerator/product_spec.rb diff --git a/core/enumerator/product_spec.rb b/core/enumerator/product_spec.rb new file mode 100644 index 000000000..3078eeb3d --- /dev/null +++ b/core/enumerator/product_spec.rb @@ -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 "cos tam" 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 From f460d9a4f90cb9a7eb2f22b2dbc0a4a48d7be0e4 Mon Sep 17 00:00:00 2001 From: AI-Mozi Date: Mon, 8 May 2023 16:11:15 +0200 Subject: [PATCH 2/2] change spec name --- core/enumerator/product_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/enumerator/product_spec.rb b/core/enumerator/product_spec.rb index 3078eeb3d..5059ad5f5 100644 --- a/core/enumerator/product_spec.rb +++ b/core/enumerator/product_spec.rb @@ -14,7 +14,7 @@ elems.should == [[1, "X"], [1, "Y"], [2, "X"], [2, "Y"]] end - it "cos tam" do + 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