related tag calculator: fix unstable sorting of related tags.
Fix this test failure:
1) Failure:
RelatedTagCalculatorTest#test_: A related tag calculator should convert a hash into string format.
[test/unit/related_tag_calculator_test.rb:65]:
Expected: "aaa 3 bbb 3 ccc 2 ddd 1"
Actual: "bbb 3 aaa 3 ccc 2 ddd 1"
The related tag string didn't use a stable sort. Sort first by tag
count, then by tag name.
This commit is contained in:
@@ -69,7 +69,7 @@ class RelatedTagCalculator
|
||||
end
|
||||
|
||||
def self.convert_hash_to_array(hash, limit = MAX_RESULTS)
|
||||
hash.to_a.sort_by {|x| -x[1]}.slice(0, limit)
|
||||
hash.to_a.sort_by {|x| [-x[1], x[0]] }.slice(0, limit)
|
||||
end
|
||||
|
||||
def self.convert_hash_to_string(hash)
|
||||
|
||||
Reference in New Issue
Block a user