grosser/sort_alphabetical — Issue #5: Sorting with multiples columns
Author: jeromelefeuvre
Created: 2012-01-11 18:03:30+00:00
State: open

Hi,

When I try to sort with multiples columns, results is not what I expect

Here is my test:

[
["FLAM / 00870000", "LYON"],
["CARIBOU SPORTS/00485 000", "LYON"],
["AU VIEUX CAMPEUR", "LYON"],
["GO SPORT (53) PART DIEU", "LYON CEDEX 03"],
["GO SPORT", "LYON CEDEX 03"]
].sort_alphabetical_by{|x| [x[1], x[0]]}.should eql [
["AU VIEUX CAMPEUR", "LYON"],
["CARIBOU SPORTS/00485 000", "LYON"],
["FLAM / 00870000", "LYON"],
["GO SPORT", "LYON CEDEX 03"],
["GO SPORT (53) PART DIEU", "LYON CEDEX 03"]
]

Failures:

1) SortAlphabetical sort_alphabetical_by sorts when multiple columns
Failure/Error: [["FLAM / 00870000", "LYON"], ["CARIBOU SPORTS/00485 000", "LYON"], ["AU VIEUX CAMPEUR", "LYON"], ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"], ["GO SPORT", "LYON CEDEX 03"]].sort_alphabetical_by{|x| [x[1], x[0]]}.should == [["AU VIEUX CAMPEUR", "LYON"], ["CARIBOU SPORTS/00485 000", "LYON"], ["FLAM / 00870000", "LYON"], ["GO SPORT", "LYON CEDEX 03"], ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"]]
expected: [["AU VIEUX CAMPEUR", "LYON"], ["CARIBOU SPORTS/00485 000", "LYON"], ["FLAM / 00870000", "LYON"], ["GO SPORT", "LYON CEDEX 03"], ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"]]
got: [["GO SPORT", "LYON CEDEX 03"], ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"], ["AU VIEUX CAMPEUR", "LYON"], ["CARIBOU SPORTS/00485 000", "LYON"], ["FLAM / 00870000", "LYON"]] (using ==)
Diff:

@@ -1,6 +1,6 @@
-[["AU VIEUX CAMPEUR", "LYON"],
+[["GO SPORT", "LYON CEDEX 03"],
+ ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"],
+ ["AU VIEUX CAMPEUR", "LYON"],
["CARIBOU SPORTS/00485 000", "LYON"],
- ["FLAM / 00870000", "LYON"],
- ["GO SPORT", "LYON CEDEX 03"],
- ["GO SPORT (53) PART DIEU", "LYON CEDEX 03"]]
+ ["FLAM / 00870000", "LYON"]]

Am I wrong ?

Thanks