diff options
author | Prajjwal Singh <sin@prajjwal.com> | 2019-10-07 10:42:29 +0530 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-10-07 15:59:12 +0900 |
commit | c8542ab484efb6ee0009cd081789d9a68f482483 (patch) | |
tree | f8c00b416b4ff3c7fae2cb534338162066201b17 /test/ruby | |
parent | d4ec37f69e3bd6f88725fe1075daa2e5f58c2aec (diff) | |
download | ruby-c8542ab484efb6ee0009cd081789d9a68f482483.tar.gz |
Add: Array#intersection method
Diffstat (limited to 'test/ruby')
-rw-r--r-- | test/ruby/test_array.rb | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index 955a00ad99..6d730db4ae 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -241,6 +241,23 @@ class TestArray < Test::Unit::TestCase assert_equal(@cls[], @cls[ 1, 2, 3 ]*64 & @cls[ 4, 5, 6 ]*64) end + def test_intersection + assert_equal(@cls[1, 2], @cls[1, 2, 3].intersection(@cls[1, 2])) + assert_equal(@cls[ ], @cls[1].intersection(@cls[ ])) + assert_equal(@cls[ ], @cls[ ].intersection(@cls[1])) + assert_equal(@cls[1], @cls[1, 2, 3].intersection(@cls[1, 2], @cls[1])) + assert_equal(@cls[ ], @cls[1, 2, 3].intersection(@cls[1, 2], @cls[3])) + assert_equal(@cls[ ], @cls[1, 2, 3].intersection(@cls[4, 5, 6])) + end + + def test_intersection_big_array + assert_equal(@cls[1, 2], (@cls[1, 2, 3] * 64).intersection(@cls[1, 2] * 64)) + assert_equal(@cls[ ], (@cls[1] * 64).intersection(@cls[ ])) + assert_equal(@cls[ ], @cls[ ].intersection(@cls[1] * 64)) + assert_equal(@cls[1], (@cls[1, 2, 3] * 64).intersection((@cls[1, 2] * 64), (@cls[1] * 64))) + assert_equal(@cls[ ], (@cls[1, 2, 3] * 64).intersection(@cls[4, 5, 6] * 64)) + end + def test_MUL # '*' assert_equal(@cls[], @cls[]*3) assert_equal(@cls[1, 1, 1], @cls[1]*3) |