diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-04-16 16:13:19 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2024-04-16 16:13:19 +0900 |
commit | 29110fe18d8f10f649cbcd43a9726069bfff1c54 (patch) | |
tree | 4a135d8a0d6e8cf20fe61555500f13c9f0a2db0e /test | |
parent | 53a8ad151bf2a5a986f294027178659aad1a5bd5 (diff) |
[Bug #20325] `Enumerator.product.size` is 0 if any size is 0
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_enumerator.rb | 17 |
1 files changed, 8 insertions, 9 deletions
diff --git a/test/ruby/test_enumerator.rb b/test/ruby/test_enumerator.rb index 825c191d87..7599d43463 100644 --- a/test/ruby/test_enumerator.rb +++ b/test/ruby/test_enumerator.rb @@ -953,11 +953,7 @@ class TestEnumerator < Test::Unit::TestCase assert_equal(true, e.is_lambda) end - def test_product - ## - ## Enumerator::Product - ## - + def test_product_new # 0-dimensional e = Enumerator::Product.new assert_instance_of(Enumerator::Product, e) @@ -994,15 +990,16 @@ class TestEnumerator < Test::Unit::TestCase e.each { |x,| heads << x } assert_equal [1, 1, 2, 2, 3, 3], heads + # Any enumerable is 0 size + assert_equal(0, Enumerator::Product.new([], 1..).size) + # Reject keyword arguments assert_raise(ArgumentError) { Enumerator::Product.new(1..3, foo: 1, bar: 2) } + end - ## - ## Enumerator.product - ## - + def test_s_product # without a block e = Enumerator.product(1..3, %w[a b]) assert_instance_of(Enumerator::Product, e) @@ -1029,6 +1026,8 @@ class TestEnumerator < Test::Unit::TestCase assert_equal(nil, e.size) assert_equal [[1, "a"], [1, "b"], [2, "a"], [2, "b"]], e.take(4) + assert_equal(0, Enumerator.product([], 1..).size) + # Reject keyword arguments assert_raise(ArgumentError) { Enumerator.product(1..3, foo: 1, bar: 2) |