mirror of
https://github.com/red-data-tools/YouPlot.git
synced 2025-05-07 15:41:12 +08:00
Add test count_values_non_tally
This commit is contained in:
parent
fbfcf80d25
commit
10e096d7c9
@ -6,9 +6,9 @@ module YouPlot
|
|||||||
module Processing
|
module Processing
|
||||||
module_function
|
module_function
|
||||||
|
|
||||||
def count_values(arr)
|
def count_values(arr, tally: true)
|
||||||
# tally was added in Ruby 2.7
|
# tally was added in Ruby 2.7
|
||||||
if Enumerable.method_defined? :tally
|
if tally && Enumerable.method_defined?(:tally)
|
||||||
arr.tally
|
arr.tally
|
||||||
else
|
else
|
||||||
# https://github.com/marcandre/backports
|
# https://github.com/marcandre/backports
|
||||||
|
@ -8,4 +8,10 @@ class YouPlotCommandTest < Test::Unit::TestCase
|
|||||||
assert_equal([%i[a b c], [3, 2, 1]], @m.count_values(%i[a a a b b c]))
|
assert_equal([%i[a b c], [3, 2, 1]], @m.count_values(%i[a a a b b c]))
|
||||||
assert_equal([%i[c b a], [3, 2, 1]], @m.count_values(%i[a b b c c c]))
|
assert_equal([%i[c b a], [3, 2, 1]], @m.count_values(%i[a b b c c c]))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test :count_values_non_tally do
|
||||||
|
@m = YouPlot::Backends::Processing
|
||||||
|
assert_equal([%i[a b c], [3, 2, 1]], @m.count_values(%i[a a a b b c], tally: false))
|
||||||
|
assert_equal([%i[c b a], [3, 2, 1]], @m.count_values(%i[a b b c c c], tally: false))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user