Sha256: e8f32000cc16f8476f70c14a23dc13e9f7ea96ca8e50100c7761d5eed1ab72d1
Contents?: true
Size: 769 Bytes
Versions: 6
Compression:
Stored size: 769 Bytes
Contents
require_relative 'test_helper' class ArrayWithTopN < Array include MemoryProfiler::TopN end class TestTopN < Minitest::Test def tn(*vals) ArrayWithTopN.new.concat(vals) end def test_top_n data = tn( 7,1,2,2,3,3,99,3 ) results = data.top_n(2) assert_equal([{data: 3, count: 3}, {data: 2, count: 2}], results) end def test_top_n_with_block data = tn( 0,3,6,1,4,2 ) results = data.top_n(2) do |r| r%3 end assert_equal([{data: 0, count: 3}, {data: 1, count: 2}], results) end def test_top_n_with_block_and_size data = tn( [1,100], [1,10], [2,1], [2,1], [2,1],[3,100] ) results = data.top_n(2) do |r| r end assert_equal([{data: 1, count: 110}, {data: 3, count: 100}], results) end end
Version data entries
6 entries across 6 versions & 1 rubygems