You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucy.apache.org by ma...@apache.org on 2011/03/24 20:35:31 UTC

[lucy-commits] svn commit: r1085093 - in /incubator/lucy/trunk: core/Lucy/Test/Plan/TestFieldType.c core/Lucy/Test/Plan/TestFieldType.cfh perl/lib/Lucy/Test.pm perl/t/core/234-field_type.t

Author: marvin
Date: Thu Mar 24 19:35:31 2011
New Revision: 1085093

URL: http://svn.apache.org/viewvc?rev=1085093&view=rev
Log:
Factor tests for FieldType out of TestFullTextType.

Added:
    incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c
      - copied, changed from r1084819, incubator/lucy/trunk/core/Lucy/Test/Plan/TestFullTextType.c
    incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.cfh
    incubator/lucy/trunk/perl/t/core/234-field_type.t
Modified:
    incubator/lucy/trunk/perl/lib/Lucy/Test.pm

Copied: incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c (from r1084819, incubator/lucy/trunk/core/Lucy/Test/Plan/TestFullTextType.c)
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c?p2=incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c&p1=incubator/lucy/trunk/core/Lucy/Test/Plan/TestFullTextType.c&r1=1084819&r2=1085093&rev=1085093&view=diff
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Plan/TestFullTextType.c (original)
+++ incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.c Thu Mar 24 19:35:31 2011
@@ -14,95 +14,78 @@
  * limitations under the License.
  */
 
-#define C_LUCY_TESTFULLTEXTTYPE
+#define C_LUCY_TESTFIELDTYPE
+#define C_LUCY_DUMMYFIELDTYPE
 #include "Lucy/Util/ToolSet.h"
 
 #include "Lucy/Test.h"
-#include "Lucy/Test/Plan/TestFullTextType.h"
+#include "Lucy/Test/Plan/TestFieldType.h"
 #include "Lucy/Test/TestUtils.h"
-#include "Lucy/Plan/FullTextType.h"
-#include "Lucy/Analysis/CaseFolder.h"
-#include "Lucy/Analysis/RegexTokenizer.h"
+
+DummyFieldType*
+DummyFieldType_new()
+{
+    DummyFieldType *self = (DummyFieldType*)VTable_Make_Obj(DUMMYFIELDTYPE);
+    return (DummyFieldType*)FType_init(self);
+}
 
 static void
 test_Dump_Load_and_Equals(TestBatch *batch)
 {
-    RegexTokenizer *tokenizer     = RegexTokenizer_new(NULL);
-    CaseFolder     *case_folder   = CaseFolder_new();
-    FullTextType   *type          = FullTextType_new((Analyzer*)tokenizer);
-    FullTextType   *other         = FullTextType_new((Analyzer*)case_folder);
-    FullTextType   *boost_differs = FullTextType_new((Analyzer*)tokenizer);
-    FullTextType   *not_indexed   = FullTextType_new((Analyzer*)tokenizer);
-    FullTextType   *not_stored    = FullTextType_new((Analyzer*)tokenizer);
-    FullTextType   *highlightable = FullTextType_new((Analyzer*)tokenizer);
-    Obj            *dump          = (Obj*)FullTextType_Dump(type);
-    Obj            *clone         = Obj_Load(dump, dump);
-    Obj            *another_dump  = (Obj*)FullTextType_Dump_For_Schema(type);
-
-    FullTextType_Set_Boost(boost_differs, 1.5);
-    FullTextType_Set_Indexed(not_indexed, false);
-    FullTextType_Set_Stored(not_stored, false);
-    FullTextType_Set_Highlightable(highlightable, true);
-
-    // (This step is normally performed by Schema_Load() internally.) 
-    Hash_Store_Str((Hash*)another_dump, "analyzer", 8, INCREF(tokenizer));
-    FullTextType *another_clone = FullTextType_load(NULL, another_dump);
-
-    TEST_FALSE(batch, FullTextType_Equals(type, (Obj*)boost_differs),
+    FieldType   *type          = (FieldType*)DummyFieldType_new();
+    FieldType   *other         = (FieldType*)DummyFieldType_new();
+    FieldType   *boost_differs = (FieldType*)DummyFieldType_new();
+    FieldType   *indexed       = (FieldType*)DummyFieldType_new();
+    FieldType   *stored        = (FieldType*)DummyFieldType_new();
+
+    FType_Set_Boost(other, 1.0);
+    FType_Set_Indexed(indexed, false);
+    FType_Set_Stored(stored, false);
+
+    FType_Set_Boost(boost_differs, 1.5);
+    FType_Set_Indexed(indexed, true);
+    FType_Set_Stored(stored, true);
+
+    TEST_TRUE(batch, FType_Equals(type, (Obj*)other),
+        "Equals() true with identical stats");
+    TEST_FALSE(batch, FType_Equals(type, (Obj*)boost_differs),
         "Equals() false with different boost");
-    TEST_FALSE(batch, FullTextType_Equals(type, (Obj*)other),
-        "Equals() false with different Analyzer");
-    TEST_FALSE(batch, FullTextType_Equals(type, (Obj*)not_indexed),
-        "Equals() false with indexed => false");
-    TEST_FALSE(batch, FullTextType_Equals(type, (Obj*)not_stored),
-        "Equals() false with stored => false");
-    TEST_FALSE(batch, FullTextType_Equals(type, (Obj*)highlightable),
-        "Equals() false with highlightable => true");
-    TEST_TRUE(batch, FullTextType_Equals(type, (Obj*)clone), 
-        "Dump => Load round trip");
-    TEST_TRUE(batch, FullTextType_Equals(type, (Obj*)another_clone), 
-        "Dump_For_Schema => Load round trip");
-
-    DECREF(another_clone);
-    DECREF(dump);
-    DECREF(clone);
-    DECREF(another_dump);
-    DECREF(highlightable);
-    DECREF(not_stored);
-    DECREF(not_indexed);
+    TEST_FALSE(batch, FType_Equals(type, (Obj*)indexed),
+        "Equals() false with indexed => true");
+    TEST_FALSE(batch, FType_Equals(type, (Obj*)stored),
+        "Equals() false with stored => true");
+
+    DECREF(stored);
+    DECREF(indexed);
     DECREF(boost_differs);
     DECREF(other);
     DECREF(type);
-    DECREF(case_folder);
-    DECREF(tokenizer);
 }
 
 static void
 test_Compare_Values(TestBatch *batch)
 {
-    RegexTokenizer *tokenizer = RegexTokenizer_new(NULL);
-    FullTextType   *type      = FullTextType_new((Analyzer*)tokenizer);
-    ZombieCharBuf  *a         = ZCB_WRAP_STR("a", 1);
-    ZombieCharBuf  *b         = ZCB_WRAP_STR("b", 1);
+    FieldType     *type = (FieldType*)DummyFieldType_new();
+    ZombieCharBuf *a    = ZCB_WRAP_STR("a", 1);
+    ZombieCharBuf *b    = ZCB_WRAP_STR("b", 1);
 
     TEST_TRUE(batch, 
-        FullTextType_Compare_Values(type, (Obj*)a, (Obj*)b) < 0,
+        FType_Compare_Values(type, (Obj*)a, (Obj*)b) < 0,
         "a less than b");
     TEST_TRUE(batch, 
-        FullTextType_Compare_Values(type, (Obj*)b, (Obj*)a) > 0,
+        FType_Compare_Values(type, (Obj*)b, (Obj*)a) > 0,
         "b greater than a");
     TEST_TRUE(batch, 
-        FullTextType_Compare_Values(type, (Obj*)b, (Obj*)b) == 0,
+        FType_Compare_Values(type, (Obj*)b, (Obj*)b) == 0,
         "b equals b");
 
     DECREF(type);
-    DECREF(tokenizer);
 }
 
 void
-TestFullTextType_run_tests()
+TestFType_run_tests()
 {
-    TestBatch *batch = TestBatch_new(10);
+    TestBatch *batch = TestBatch_new(7);
     TestBatch_Plan(batch);
     test_Dump_Load_and_Equals(batch);
     test_Compare_Values(batch);

Added: incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.cfh
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.cfh?rev=1085093&view=auto
==============================================================================
--- incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.cfh (added)
+++ incubator/lucy/trunk/core/Lucy/Test/Plan/TestFieldType.cfh Thu Mar 24 19:35:31 2011
@@ -0,0 +1,28 @@
+/* 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 Lucy;
+
+inert class Lucy::Test::Plan::TestFieldType cnick TestFType {
+    inert void
+    run_tests();
+}
+
+class Lucy::Test::Plan::DummyFieldType inherits Lucy::Plan::FieldType {
+    inert incremented DummyFieldType*
+    new();
+}
+

Modified: incubator/lucy/trunk/perl/lib/Lucy/Test.pm
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/lib/Lucy/Test.pm?rev=1085093&r1=1085092&r2=1085093&view=diff
==============================================================================
--- incubator/lucy/trunk/perl/lib/Lucy/Test.pm (original)
+++ incubator/lucy/trunk/perl/lib/Lucy/Test.pm Thu Mar 24 19:35:31 2011
@@ -78,6 +78,9 @@ PPCODE:
     else if (strEQ(package, "TestBlobType")) {
         lucy_TestBlobType_run_tests();
     }
+    else if (strEQ(package, "TestFieldType")) {
+        lucy_TestFType_run_tests();
+    }
     else if (strEQ(package, "TestFullTextType")) {
         lucy_TestFullTextType_run_tests();
     }

Added: incubator/lucy/trunk/perl/t/core/234-field_type.t
URL: http://svn.apache.org/viewvc/incubator/lucy/trunk/perl/t/core/234-field_type.t?rev=1085093&view=auto
==============================================================================
--- incubator/lucy/trunk/perl/t/core/234-field_type.t (added)
+++ incubator/lucy/trunk/perl/t/core/234-field_type.t Thu Mar 24 19:35:31 2011
@@ -0,0 +1,21 @@
+# 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;
+Lucy::Test::run_tests("TestFieldType");
+