lucy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nwelln...@apache.org
Subject [lucy-commits] git commit: refs/heads/sortfieldwriter - Port t/015-sort_external.t to C
Date Thu, 17 Oct 2013 16:57:01 GMT
Updated Branches:
  refs/heads/sortfieldwriter cf6cc5631 -> 1f986bf19


Port t/015-sort_external.t to C


Project: http://git-wip-us.apache.org/repos/asf/lucy/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucy/commit/1f986bf1
Tree: http://git-wip-us.apache.org/repos/asf/lucy/tree/1f986bf1
Diff: http://git-wip-us.apache.org/repos/asf/lucy/diff/1f986bf1

Branch: refs/heads/sortfieldwriter
Commit: 1f986bf19e77aefb7fcbdbe04e3ab60e43d78040
Parents: cf6cc56
Author: Nick Wellnhofer <wellnhofer@aevum.de>
Authored: Thu Oct 17 18:56:40 2013 +0200
Committer: Nick Wellnhofer <wellnhofer@aevum.de>
Committed: Thu Oct 17 18:56:40 2013 +0200

----------------------------------------------------------------------
 core/Lucy/Test.c                         |   2 +
 core/Lucy/Test/Util/TestSortExternal.c   | 295 ++++++++++++++++++++++++++
 core/Lucy/Test/Util/TestSortExternal.cfh |  29 +++
 core/Lucy/Util/BBSortEx.c                |  20 ++
 core/Lucy/Util/BBSortEx.cfh              |   6 +
 perl/buildlib/Lucy/Build/Binding/Util.pm |  60 ------
 perl/lib/Lucy/Util/BBSortEx.pm           |  25 ---
 perl/t/015-sort_external.t               | 165 --------------
 perl/t/core/015-sort_external.t          |  23 ++
 9 files changed, 375 insertions(+), 250 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/core/Lucy/Test.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test.c b/core/Lucy/Test.c
index 62c9bdf..196ae6a 100644
--- a/core/Lucy/Test.c
+++ b/core/Lucy/Test.c
@@ -81,6 +81,7 @@
 #include "Lucy/Test/Util/TestJson.h"
 #include "Lucy/Test/Util/TestMemoryPool.h"
 #include "Lucy/Test/Util/TestPriorityQueue.h"
+#include "Lucy/Test/Util/TestSortExternal.h"
 
 TestSuite*
 Test_create_test_suite() {
@@ -88,6 +89,7 @@ Test_create_test_suite() {
 
     TestSuite_Add_Batch(suite, (TestBatch*)TestPriQ_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestBitVector_new());
+    TestSuite_Add_Batch(suite, (TestBatch*)TestSortExternal_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestMemPool_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestIxFileNames_new());
     TestSuite_Add_Batch(suite, (TestBatch*)TestJson_new());

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/core/Lucy/Test/Util/TestSortExternal.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestSortExternal.c b/core/Lucy/Test/Util/TestSortExternal.c
new file mode 100644
index 0000000..26f10ea
--- /dev/null
+++ b/core/Lucy/Test/Util/TestSortExternal.c
@@ -0,0 +1,295 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+#define TESTLUCY_USE_SHORT_NAMES
+#include "Lucy/Util/ToolSet.h"
+#include "Lucy/Test/Util/TestSortExternal.h"
+
+#include "Clownfish/TestHarness/TestBatchRunner.h"
+#include "Lucy/Util/BBSortEx.h"
+#include "Lucy/Util/SortExternal.h"
+
+static ByteBuf *a_bb;
+static ByteBuf *b_bb;
+static ByteBuf *c_bb;
+static ByteBuf *d_bb;
+static ByteBuf *x_bb;
+static ByteBuf *y_bb;
+static ByteBuf *z_bb;
+
+TestSortExternal*
+TestSortExternal_new() {
+    return (TestSortExternal*)VTable_Make_Obj(TESTSORTEXTERNAL);
+}
+
+static void
+S_init_bytebufs() {
+    a_bb = BB_new_bytes("a", 1);
+    b_bb = BB_new_bytes("b", 1);
+    c_bb = BB_new_bytes("c", 1);
+    d_bb = BB_new_bytes("d", 1);
+    x_bb = BB_new_bytes("x", 1);
+    y_bb = BB_new_bytes("y", 1);
+    z_bb = BB_new_bytes("z", 1);
+}
+
+static void
+S_destroy_bytebufs() {
+    DECREF(a_bb);
+    DECREF(b_bb);
+    DECREF(c_bb);
+    DECREF(d_bb);
+    DECREF(x_bb);
+    DECREF(y_bb);
+    DECREF(z_bb);
+}
+
+static void
+test_bbsortex(TestBatchRunner *runner) {
+    BBSortEx *sortex = BBSortEx_new(4, NULL);
+
+    INCREF(c_bb);
+    BBSortEx_Feed(sortex, &c_bb);
+    TEST_INT_EQ(runner, BBSortEx_Cache_Count(sortex), 1,
+                "feed elem into cache");
+
+    INCREF(b_bb);
+    INCREF(d_bb);
+    BBSortEx_Feed(sortex, &b_bb);
+    BBSortEx_Feed(sortex, &d_bb);
+    BBSortEx_Sort_Cache(sortex);
+
+    {
+        VArray *cache  = BBSortEx_Peek_Cache(sortex);
+        VArray *wanted = VA_new(3);
+        VA_Push(wanted, INCREF(b_bb));
+        VA_Push(wanted, INCREF(c_bb));
+        VA_Push(wanted, INCREF(d_bb));
+        TEST_TRUE(runner, VA_Equals(cache, (Obj*)wanted), "sort cache");
+        DECREF(wanted);
+        DECREF(cache);
+    }
+
+    INCREF(a_bb);
+    BBSortEx_Feed(sortex, &a_bb);
+    TEST_INT_EQ(runner, BBSortEx_Cache_Count(sortex), 0,
+                "cache flushed automatically when mem_thresh crossed");
+    TEST_INT_EQ(runner, BBSortEx_Get_Num_Runs(sortex), 1, "run added");
+
+    VArray *external = VA_new(3);
+    VA_Push(external, INCREF(x_bb));
+    VA_Push(external, INCREF(y_bb));
+    VA_Push(external, INCREF(z_bb));
+    BBSortEx *run = BBSortEx_new(0x1000000, external);
+    BBSortEx_Add_Run(sortex, (SortExternal*)run);
+    BBSortEx_Flip(sortex);
+
+    {
+        VArray *got = VA_new(7);
+        void *data;
+        while (NULL != (data = BBSortEx_Fetch(sortex))) {
+            VA_Push(got, *(Obj**)data);
+        }
+
+        VArray *wanted = VA_new(7);
+        VA_Push(wanted, INCREF(a_bb));
+        VA_Push(wanted, INCREF(b_bb));
+        VA_Push(wanted, INCREF(c_bb));
+        VA_Push(wanted, INCREF(d_bb));
+        VA_Push(wanted, INCREF(x_bb));
+        VA_Push(wanted, INCREF(y_bb));
+        VA_Push(wanted, INCREF(z_bb));
+
+        TEST_TRUE(runner, VA_Equals(got, (Obj*)wanted), "Add_Run");
+
+        DECREF(wanted);
+        DECREF(got);
+    }
+
+    DECREF(external);
+    DECREF(sortex);
+}
+
+static void
+test_clear_cache(TestBatchRunner *runner) {
+    BBSortEx *sortex = BBSortEx_new(4, NULL);
+
+    INCREF(c_bb);
+    BBSortEx_Feed(sortex, &c_bb);
+    BBSortEx_Clear_Cache(sortex);
+    TEST_INT_EQ(runner, BBSortEx_Cache_Count(sortex), 0, "Clear_Cache");
+
+    INCREF(b_bb);
+    INCREF(a_bb);
+    BBSortEx_Feed(sortex, &b_bb);
+    BBSortEx_Feed(sortex, &a_bb);
+    BBSortEx_Flush(sortex);
+    BBSortEx_Flip(sortex);
+    void *data = BBSortEx_Peek(sortex);
+    TEST_TRUE(runner, BB_Equals(a_bb, *(Obj**)data), "Peek");
+
+    VArray *got = VA_new(2);
+    while (NULL != (data = BBSortEx_Fetch(sortex))) {
+        VA_Push(got, *(Obj**)data);
+    }
+    VArray *wanted = VA_new(2);
+    VA_Push(wanted, INCREF(a_bb));
+    VA_Push(wanted, INCREF(b_bb));
+    TEST_TRUE(runner, VA_Equals(got, (Obj*)wanted),
+              "elements cleared via Clear_Cache truly cleared");
+
+    DECREF(wanted);
+    DECREF(got);
+    DECREF(sortex);
+}
+
+static void
+S_test_sort(TestBatchRunner *runner, VArray *bytebufs, uint32_t mem_thresh,
+            const char *test_name) {
+    uint32_t   size     = VA_Get_Size(bytebufs);
+    BBSortEx  *sortex   = BBSortEx_new(mem_thresh, NULL);
+    ByteBuf  **shuffled = (ByteBuf**)MALLOCATE(size * sizeof(ByteBuf*));
+
+    for (int i = 0; i < size; ++i) {
+        shuffled[i] = (ByteBuf*)CERTIFY(VA_Fetch(bytebufs, i), BYTEBUF);
+    }
+    for (int i = size - 1; i > 0; --i) {
+        int shuffle_pos = rand() % (i + 1);
+        ByteBuf *temp = shuffled[shuffle_pos];
+        shuffled[shuffle_pos] = shuffled[i];
+        shuffled[i] = temp;
+    }
+    for (int i = 0; i < size; ++i) {
+        INCREF(shuffled[i]);
+        BBSortEx_Feed(sortex, &shuffled[i]);
+    }
+
+    BBSortEx_Flip(sortex);
+    VArray *got = VA_new(size);
+    void *data;
+    while (NULL != (data = BBSortEx_Fetch(sortex))) {
+        VA_Push(got, *(Obj**)data);
+    }
+    TEST_TRUE(runner, VA_Equals(got, (Obj*)bytebufs), test_name);
+
+    FREEMEM(shuffled);
+    DECREF(got);
+    DECREF(sortex);
+}
+
+static void
+S_test_sort_letters(TestBatchRunner *runner, const char *letters,
+                    uint32_t mem_thresh, const char *test_name) {
+    size_t  num_letters = strlen(letters);
+    VArray *bytebufs    = VA_new(num_letters);
+
+    for (int i = 0; i < num_letters; ++i) {
+        char ch = letters[i];
+        size_t size = ch == '_' ? 0 : 1;
+        ByteBuf *bytebuf = BB_new_bytes(&ch, size);
+        VA_Push(bytebufs, (Obj*)bytebuf);
+    }
+
+    S_test_sort(runner, bytebufs, mem_thresh, test_name);
+
+    DECREF(bytebufs);
+}
+
+static void
+test_sort_letters(TestBatchRunner *runner) {
+    S_test_sort_letters(runner, "abcdefghijklmnopqrstuvwxyz", 0x1000000,
+                        "sort letters");
+    S_test_sort_letters(runner, "aaabcdxxxxxxyy", 0x1000000,
+                        "sort repeated letters");
+    S_test_sort_letters(runner, "__abcdefghijklmnopqrstuvwxyz", 0x1000000,
+                        "sort letters and empty strings");
+    S_test_sort_letters(runner, "abcdefghijklmnopqrstuvwxyz", 30,
+                        "... with an absurdly low mem_thresh");
+    S_test_sort_letters(runner, "abcdefghijklmnopqrstuvwxyz", 1,
+                        "... with an even lower mem_thresh");
+}
+
+static void
+test_sort_nothing(TestBatchRunner *runner) {
+    BBSortEx *sortex = BBSortEx_new(0x1000000, NULL);
+    BBSortEx_Flip(sortex);
+    TEST_TRUE(runner, BBSortEx_Fetch(sortex) == NULL,
+              "Sorting nothing returns undef");
+    DECREF(sortex);
+}
+
+static void
+test_sort_packed_ints(TestBatchRunner *runner) {
+    size_t  num_ints = 11001;
+    VArray *bytebufs = VA_new(num_ints);
+
+    for (uint32_t i = 0; i < num_ints; ++i) {
+        char buf[4];
+        buf[0] = i >> 24;
+        buf[1] = i >> 16;
+        buf[2] = i >> 8;
+        buf[3] = i;
+        ByteBuf *bytebuf = BB_new_bytes(&buf, 4);
+        VA_Push(bytebufs, (Obj*)bytebuf);
+    }
+
+    S_test_sort(runner, bytebufs, 5000, "Sorting packed integers...");
+
+    DECREF(bytebufs);
+}
+
+static void
+test_sort_random_strings(TestBatchRunner *runner) {
+    size_t  num_strings = 1001;
+    VArray *bytebufs    = VA_new(num_strings);
+
+    for (uint32_t i = 0; i < num_strings; ++i) {
+        char buf[1201];
+        int size = rand() % 1200 + 1;
+        for (int i = 0; i < size; ++i) {
+            buf[i] = rand();
+        }
+        ByteBuf *bytebuf = BB_new_bytes(&buf, size);
+        VA_Push(bytebufs, (Obj*)bytebuf);
+    }
+
+    VA_Sort(bytebufs, NULL, NULL);
+    S_test_sort(runner, bytebufs, 15000,
+                "Random binary strings of random length");
+
+    DECREF(bytebufs);
+}
+
+void
+TestSortExternal_Run_IMP(TestSortExternal *self, TestBatchRunner *runner) {
+    TestBatchRunner_Plan(runner, (TestBatch*)self, 16);
+
+    srand((unsigned int)time((time_t*)NULL));
+    S_init_bytebufs();
+    test_bbsortex(runner);
+    test_clear_cache(runner);
+    test_sort_letters(runner);
+    test_sort_nothing(runner);
+    test_sort_packed_ints(runner);
+    test_sort_random_strings(runner);
+    S_destroy_bytebufs();
+}
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/core/Lucy/Test/Util/TestSortExternal.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Test/Util/TestSortExternal.cfh b/core/Lucy/Test/Util/TestSortExternal.cfh
new file mode 100644
index 0000000..028b322
--- /dev/null
+++ b/core/Lucy/Test/Util/TestSortExternal.cfh
@@ -0,0 +1,29 @@
+/* Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+parcel TestLucy;
+
+class Lucy::Test::Util::TestSortExternal
+    inherits Clownfish::TestHarness::TestBatch {
+
+    inert incremented TestSortExternal*
+    new();
+
+    void
+    Run(TestSortExternal *self, TestBatchRunner *runner);
+}
+
+

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/core/Lucy/Util/BBSortEx.c
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.c b/core/Lucy/Util/BBSortEx.c
index 92d80a5..622cca4 100644
--- a/core/Lucy/Util/BBSortEx.c
+++ b/core/Lucy/Util/BBSortEx.c
@@ -173,4 +173,24 @@ BBSortEx_Compare_IMP(BBSortEx *self, void *va, void *vb) {
     return BB_compare((ByteBuf**)va, (ByteBuf**)vb);
 }
 
+VArray*
+BBSortEx_Peek_Cache_IMP(BBSortEx *self) {
+    BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+    uint32_t   count  = ivars->cache_max - ivars->cache_tick;
+    Obj      **cache  = (Obj**)ivars->cache;
+    VArray    *retval = VA_new(count);
+
+    for (uint32_t i = ivars->cache_tick; i < ivars->cache_max; ++i) {
+        VA_Push(retval, INCREF(cache[i]));
+    }
+
+    return retval;
+}
+
+uint32_t
+BBSortEx_Get_Num_Runs_IMP(BBSortEx *self) {
+    BBSortExIVARS *const ivars = BBSortEx_IVARS(self);
+    return VA_Get_Size(ivars->runs);
+}
+
 

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/core/Lucy/Util/BBSortEx.cfh
----------------------------------------------------------------------
diff --git a/core/Lucy/Util/BBSortEx.cfh b/core/Lucy/Util/BBSortEx.cfh
index 41f72ea..b4c11ae 100644
--- a/core/Lucy/Util/BBSortEx.cfh
+++ b/core/Lucy/Util/BBSortEx.cfh
@@ -51,6 +51,12 @@ class Lucy::Util::BBSortEx
     int
     Compare(BBSortEx *self, void *va, void *vb);
 
+    incremented VArray*
+    Peek_Cache(BBSortEx *self);
+
+    uint32_t
+    Get_Num_Runs(BBSortEx *self);
+
     public void
     Destroy(BBSortEx *self);
 }

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/perl/buildlib/Lucy/Build/Binding/Util.pm
----------------------------------------------------------------------
diff --git a/perl/buildlib/Lucy/Build/Binding/Util.pm b/perl/buildlib/Lucy/Build/Binding/Util.pm
index 1561b48..cd8a70e 100644
--- a/perl/buildlib/Lucy/Build/Binding/Util.pm
+++ b/perl/buildlib/Lucy/Build/Binding/Util.pm
@@ -21,72 +21,12 @@ $VERSION = eval $VERSION;
 
 sub bind_all {
     my $class = shift;
-    $class->bind_bbsortex;
     $class->bind_debug;
     $class->bind_freezer;
     $class->bind_indexfilenames;
     $class->bind_sortexternal;
 }
 
-sub bind_bbsortex {
-    my @hand_rolled = qw(
-        Fetch
-        Peek
-        Feed
-    );
-    my $xs_code = <<'END_XS_CODE';
-MODULE = Lucy    PACKAGE = Lucy::Util::BBSortEx
-
-SV*
-fetch(self)
-    lucy_BBSortEx *self;
-CODE:
-{
-    void *address = LUCY_BBSortEx_Fetch(self);
-    if (address) {
-        RETVAL = XSBind_cfish_to_perl(*(cfish_Obj**)address);
-        CFISH_DECREF(*(cfish_Obj**)address);
-    }
-    else {
-        RETVAL = newSV(0);
-    }
-}
-OUTPUT: RETVAL
-
-SV*
-peek(self)
-    lucy_BBSortEx *self;
-CODE:
-{
-    void *address = LUCY_BBSortEx_Peek(self);
-    if (address) {
-        RETVAL = XSBind_cfish_to_perl(*(cfish_Obj**)address);
-    }
-    else {
-        RETVAL = newSV(0);
-    }
-}
-OUTPUT: RETVAL
-
-void
-feed(self, bb)
-    lucy_BBSortEx *self;
-    cfish_ByteBuf *bb;
-CODE:
-    CFISH_INCREF(bb);
-    LUCY_BBSortEx_Feed(self, &bb);
-
-END_XS_CODE
-
-    my $binding = Clownfish::CFC::Binding::Perl::Class->new(
-        parcel     => "Lucy",
-        class_name => "Lucy::Util::BBSortEx",
-    );
-    $binding->append_xs($xs_code);
-
-    Clownfish::CFC::Binding::Perl::Class->register($binding);
-}
-
 sub bind_debug {
     my $xs_code = <<'END_XS_CODE';
 MODULE = Lucy   PACKAGE = Lucy::Util::Debug

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/perl/lib/Lucy/Util/BBSortEx.pm
----------------------------------------------------------------------
diff --git a/perl/lib/Lucy/Util/BBSortEx.pm b/perl/lib/Lucy/Util/BBSortEx.pm
deleted file mode 100644
index cbba688..0000000
--- a/perl/lib/Lucy/Util/BBSortEx.pm
+++ /dev/null
@@ -1,25 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-package Lucy::Util::BBSortEx;
-use Lucy;
-our $VERSION = '0.003000';
-$VERSION = eval $VERSION;
-
-1;
-
-__END__
-
-

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/perl/t/015-sort_external.t
----------------------------------------------------------------------
diff --git a/perl/t/015-sort_external.t b/perl/t/015-sort_external.t
deleted file mode 100644
index 134e7c7..0000000
--- a/perl/t/015-sort_external.t
+++ /dev/null
@@ -1,165 +0,0 @@
-# Licensed to the Apache Software Foundation (ASF) under one or more
-# contributor license agreements.  See the NOTICE file distributed with
-# this work for additional information regarding copyright ownership.
-# The ASF licenses this file to You under the Apache License, Version 2.0
-# (the "License"); you may not use this file except in compliance with
-# the License.  You may obtain a copy of the License at
-#
-#     http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-use strict;
-use warnings;
-
-use Test::More tests => 15;
-use List::Util qw( shuffle );
-use Lucy::Test;
-use bytes qw();
-
-my ( $sortex, $cache, @orig, @sort_output );
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 4 );
-$sortex->feed( new_bytebuf('c') );
-is( $sortex->cache_count, 1, "feed elem into cache" );
-
-$sortex->feed( new_bytebuf('b') );
-$sortex->feed( new_bytebuf('d') );
-$sortex->sort_cache;
-SKIP: {
-    skip( "Restore when porting test to C", 1 );
-    $cache = $sortex->_peek_cache;
-    is_deeply( $cache, [qw( b c d )], "sort cache" );
-}
-
-$sortex->feed( new_bytebuf('a') );
-is( $sortex->cache_count, 0,
-    "cache flushed automatically when mem_thresh crossed" );
-#is( $sortex->get_num_runs, 1, "run added" );
-
-my @bytebufs = map { new_bytebuf($_) } qw( x y z );
-my $run = Lucy::Util::BBSortEx->new( external => \@bytebufs );
-$sortex->add_run($run);
-$sortex->flip;
-@orig = qw( a b c d x y z );
-while ( my $result = $sortex->fetch ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "Add_Run" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 4 );
-$sortex->feed( new_bytebuf('c') );
-$sortex->clear_cache;
-is( $sortex->cache_count, 0, "Clear_Cache" );
-$sortex->feed( new_bytebuf('b') );
-$sortex->feed( new_bytebuf('a') );
-$sortex->flush;
-$sortex->flip;
-@orig = qw( a b );
-is( $sortex->peek, 'a', "Peek" );
-
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig,
-    "elements cleared via Clear_Cache truly cleared" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new;
-@orig   = ( 'a' .. 'z' );
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "sort letters" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new;
-@orig   = qw( a a a b c d x x x x x x y y );
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "sort repeated letters" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new;
-@orig = ( '', '', 'a' .. 'z' );
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "sort letters and empty strings" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 30 );
-@orig = 'a' .. 'z';
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "... with an absurdly low mem_thresh" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 1 );
-@orig = 'a' .. 'z';
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $result = $sortex->fetch ) ) {
-    push @sort_output, $result;
-}
-is_deeply( \@sort_output, \@orig, "... with an even lower mem_thresh" );
-@orig        = ();
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new;
-$sortex->flip;
-@sort_output = $sortex->fetch;
-is_deeply( \@sort_output, [undef], "Sorting nothing returns undef" );
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 5_000 );
-@orig = map { pack( 'N', $_ ) } ( 0 .. 11_000 );
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-$sortex->flip;
-while ( defined( my $item = $sortex->fetch ) ) {
-    push @sort_output, $item;
-}
-is_deeply( \@sort_output, \@orig, "Sorting packed integers..." );
-@sort_output = ();
-
-$sortex = Lucy::Util::BBSortEx->new( mem_thresh => 15_000 );
-@orig = ();
-for my $iter ( 0 .. 1_000 ) {
-    my $string = '';
-    for my $string_len ( 0 .. int( rand(1200) ) ) {
-        $string .= pack( 'C', int( rand(256) ) );
-    }
-    push @orig, $string;
-}
-$sortex->feed( new_bytebuf($_) ) for shuffle(@orig);
-@orig = sort @orig;
-$sortex->flip;
-while ( defined( my $item = $sortex->fetch ) ) {
-    push @sort_output, $item;
-}
-is_deeply( \@sort_output, \@orig, "Random binary strings of random length" );
-@sort_output = ();
-
-sub new_bytebuf { Clownfish::ByteBuf->new(shift) }
-

http://git-wip-us.apache.org/repos/asf/lucy/blob/1f986bf1/perl/t/core/015-sort_external.t
----------------------------------------------------------------------
diff --git a/perl/t/core/015-sort_external.t b/perl/t/core/015-sort_external.t
new file mode 100644
index 0000000..6d966bb
--- /dev/null
+++ b/perl/t/core/015-sort_external.t
@@ -0,0 +1,23 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+use strict;
+use warnings;
+
+use Lucy::Test;
+my $success = Lucy::Test::run_tests("Lucy::Test::Util::TestSortExternal");
+
+exit($success ? 0 : 1);
+


Mime
View raw message