This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch prototype/views
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 768004aeac2ad32fdabb38bc3bfef447da204f54
Author: Paul J. Davis <[email protected]>
AuthorDate: Tue Jul 23 16:38:44 2019 -0500

    Change encoding test to use the standard values from the Elixir tests
---
 src/couch_views/test/couch_views_encoding_test.erl | 62 ++++++++++++++++------
 1 file changed, 47 insertions(+), 15 deletions(-)

diff --git a/src/couch_views/test/couch_views_encoding_test.erl 
b/src/couch_views/test/couch_views_encoding_test.erl
index 9282265..30617c9 100644
--- a/src/couch_views/test/couch_views_encoding_test.erl
+++ b/src/couch_views/test/couch_views_encoding_test.erl
@@ -29,6 +29,10 @@ val_encoding_test() ->
 
 
 correct_ordering_test() ->
+    % Load the ICU driver for couch_util:get_sort_key/1
+    {ok, CfgPid} = gen_server:start_link(config, [], []),
+    {ok, DrvPid} = gen_server:start_link(couch_drv, [], []),
+
     Ordered = [
         %  Special values sort before all other types
         null,
@@ -36,11 +40,22 @@ correct_ordering_test() ->
         true,
 
         % Then numbers
-        1.0,
-        2.0,
+        1,
+        2,
         3.0,
-        4.0,
+        4,
 
+        % Then text, case sensitive
+        <<"a">>,
+        <<"A">>,
+        <<"aa">>,
+        <<"b">>,
+        <<"B">>,
+        <<"ba">>,
+        <<"bb">>,
+
+        % Then arrays, compared element by element until different.
+        % Longer arrays sort after their prefixes
         [<<"a">>],
         [<<"b">>],
         [<<"b">>, <<"c">>],
@@ -50,19 +65,36 @@ correct_ordering_test() ->
 
         % Then objects, compared each key value in the list until different.
         % Larger objects sort after their subset objects
-        {[{<<"a">>, 1.0}]},
-        {[{<<"a">>, 2.0}]},
-        {[{<<"b">>, 1.0}]},
-        {[{<<"b">>, 2.0}]},
+        {[{<<"a">>, 1}]},
+        {[{<<"a">>, 2}]},
+        {[{<<"b">>, 1}]},
+        {[{<<"b">>, 2}]},
 
         % Member order does matter for collation
-        {[{<<"b">>, 2.0}, {<<"a">>, 1.0}]},
-        {[{<<"b">>, 2.0}, {<<"c">>, 2.0}]}
+        {[{<<"b">>, 2}, {<<"a">>, 1}]},
+        {[{<<"b">>, 2}, {<<"c">>, 2}]}
     ],
 
-    BinList = [couch_views_encoding:encode(O, key) || O <- Ordered],
-    Random = [{rand:uniform(), Bin} || Bin <- BinList],
-    {_, Unsorted} = lists:unzip(lists:sort(Random)),
-    Sorted = lists:sort(Unsorted),
-    Decoded = [couch_views_encoding:decode(O) || O <- Sorted],
-    ?assertEqual(Ordered, Decoded).
+    Encoded = lists:map(fun(Elem) ->
+        K = couch_views_encoding:encode(Elem, key),
+        V = couch_views_encoding:encode(Elem, value),
+        {K, V}
+    end, Ordered),
+    Shuffled = shuffle(Encoded),
+    Reordered = lists:sort(Shuffled),
+
+    io:format(standard_error, "~n~n", []),
+    lists:foreach(fun({O, {_, VE}}) ->
+        io:format(standard_error, "~p == ~p~n", [O, 
couch_views_encoding:decode(VE)])
+    end, lists:zip(Ordered, Reordered)),
+
+    lists:foreach(fun({Original, {_K, ViewEncoded}}) ->
+        ?assertEqual(Original, couch_views_encoding:decode(ViewEncoded))
+    end, lists:zip(Ordered, Reordered)).
+
+
+shuffle(List) when is_list(List) ->
+    Tagged = [{rand:uniform(), Item} || Item <- List],
+    {_, Randomized} = lists:unzip(lists:sort(Tagged)),
+    Randomized.
+

Reply via email to