http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Index/TestTermInfo.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Index/TestTermInfo.c b/test/Lucy/Test/Index/TestTermInfo.c new file mode 100644 index 0000000..fe33c4a --- /dev/null +++ b/test/Lucy/Test/Index/TestTermInfo.c @@ -0,0 +1,68 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTTERMINFO +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Index/TestTermInfo.h" +#include "Lucy/Index/TermInfo.h" + +TestTermInfo* +TestTermInfo_new() { + return (TestTermInfo*)Class_Make_Obj(TESTTERMINFO); +} + +void +test_freqfilepos(TestBatchRunner *runner) { + TermInfo* tinfo = TInfo_new(10); + TInfo_Set_Post_FilePos(tinfo, 20); + TInfo_Set_Skip_FilePos(tinfo, 40); + TInfo_Set_Lex_FilePos(tinfo, 50); + + TermInfo* cloned_tinfo = TInfo_Clone(tinfo); + + TEST_FALSE(runner, LUCY_TInfo_Equals(tinfo, (Obj*)cloned_tinfo),"the clone should be a separate C struct"); + TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 10, "new sets doc_freq correctly" ); + TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 10, "... doc_freq cloned" ); + TEST_INT_EQ(runner, (int)TInfo_Get_Post_FilePos(tinfo), 20, "... post_filepos cloned" ); + TEST_INT_EQ(runner, (int)TInfo_Get_Skip_FilePos(tinfo), 40, "... skip_filepos cloned" ); + TEST_INT_EQ(runner, (int)TInfo_Get_Lex_FilePos(tinfo), 50, "... lex_filepos cloned" ); + + TInfo_Set_Doc_Freq(tinfo, 5); + TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(tinfo), 5, "set/get doc_freq" ); + TEST_INT_EQ(runner, TInfo_Get_Doc_Freq(cloned_tinfo), 10, "setting orig doesn't affect clone" ); + + TInfo_Set_Post_FilePos(tinfo, 15); + TEST_INT_EQ(runner, (int)TInfo_Get_Post_FilePos(tinfo), 15, "set/get post_filepos" ); + + TInfo_Set_Skip_FilePos(tinfo, 35); + TEST_INT_EQ(runner, (int)TInfo_Get_Skip_FilePos(tinfo), 35, "set/get skip_filepos" ); + + TInfo_Set_Lex_FilePos(tinfo, 45); + TEST_INT_EQ(runner, (int)TInfo_Get_Lex_FilePos(tinfo), 45, "set/get lex_filepos" ); + + DECREF(tinfo); + DECREF(cloned_tinfo); +} + +void +TestTermInfo_Run_IMP(TestTermInfo *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 11); + test_freqfilepos(runner); +}
http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Index/TestTermInfo.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Index/TestTermInfo.cfh b/test/Lucy/Test/Index/TestTermInfo.cfh new file mode 100644 index 0000000..4a7d5a3 --- /dev/null +++ b/test/Lucy/Test/Index/TestTermInfo.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::Index::TestTermInfo + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestTermInfo* + new(); + + void + Run(TestTermInfo *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Object/TestBitVector.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Object/TestBitVector.c b/test/Lucy/Test/Object/TestBitVector.c new file mode 100644 index 0000000..03b3c57 --- /dev/null +++ b/test/Lucy/Test/Object/TestBitVector.c @@ -0,0 +1,453 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTBITVECTOR +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Clownfish/TestHarness/TestUtils.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Object/TestBitVector.h" + +#include <stdlib.h> + +TestBitVector* +TestBitVector_new() { + return (TestBitVector*)Class_Make_Obj(TESTBITVECTOR); +} + +static void +test_Set_and_Get(TestBatchRunner *runner) { + const size_t three = 3; + const size_t seventeen = 17; + BitVector *bit_vec = BitVec_new(8); + + BitVec_Set(bit_vec, three); + TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) < seventeen, + "set below cap"); + BitVec_Set(bit_vec, seventeen); + TEST_TRUE(runner, BitVec_Get_Capacity(bit_vec) > seventeen, + "set above cap causes BitVector to grow"); + + size_t i, max; + for (i = 0, max = BitVec_Get_Capacity(bit_vec); i < max; i++) { + if (i == three || i == seventeen) { + TEST_TRUE(runner, BitVec_Get(bit_vec, i), "set/get %u", (unsigned)i); + } + else { + TEST_FALSE(runner, BitVec_Get(bit_vec, i), "get %u", (unsigned)i); + } + } + TEST_FALSE(runner, BitVec_Get(bit_vec, i), "out of range get"); + + DECREF(bit_vec); +} + +static void +test_Flip(TestBatchRunner *runner) { + BitVector *bit_vec = BitVec_new(0); + + unsigned i; + for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } + for (i = 0; i <= 20; i++) { + TEST_TRUE(runner, BitVec_Get(bit_vec, i), "flip on %u", i); + } + TEST_FALSE(runner, BitVec_Get(bit_vec, i), "no flip %u", i); + for (i = 0; i <= 20; i++) { BitVec_Flip(bit_vec, i); } + for (i = 0; i <= 20; i++) { + TEST_FALSE(runner, BitVec_Get(bit_vec, i), "flip off %u", i); + } + TEST_FALSE(runner, BitVec_Get(bit_vec, 21), "still no flip %u", i); + + DECREF(bit_vec); +} + +static void +test_Flip_Block_ascending(TestBatchRunner *runner) { + BitVector *bit_vec = BitVec_new(0); + + for (unsigned i = 0; i <= 20; i++) { + BitVec_Flip_Block(bit_vec, i, 21 - i); + } + + for (unsigned i = 0; i <= 20; i++) { + if (i % 2 == 0) { + TEST_TRUE(runner, BitVec_Get(bit_vec, i), + "Flip_Block ascending %u", i); + } + else { + TEST_FALSE(runner, BitVec_Get(bit_vec, i), + "Flip_Block ascending %u", i); + } + } + + DECREF(bit_vec); +} + +static void +test_Flip_Block_descending(TestBatchRunner *runner) { + BitVector *bit_vec = BitVec_new(0); + + for (int i = 19; i >= 0; i--) { + BitVec_Flip_Block(bit_vec, 1, (size_t)i); + } + + for (unsigned i = 0; i <= 20; i++) { + if (i % 2) { + TEST_TRUE(runner, BitVec_Get(bit_vec, i), + "Flip_Block descending %u", i); + } + else { + TEST_FALSE(runner, BitVec_Get(bit_vec, i), + "Flip_Block descending %u", i); + } + } + + DECREF(bit_vec); +} + +static void +test_Flip_Block_bulk(TestBatchRunner *runner) { + for (unsigned offset = 0; offset <= 17; offset++) { + for (unsigned len = 0; len <= 17; len++) { + int upper = (int)offset + (int)len - 1; + BitVector *bit_vec = BitVec_new(0); + + BitVec_Flip_Block(bit_vec, offset, len); + unsigned i; + for (i = 0; i <= 17; i++) { + if (i >= offset && (int)i <= upper) { + if (!BitVec_Get(bit_vec, i)) { break; } + } + else { + if (BitVec_Get(bit_vec, i)) { break; } + } + } + TEST_UINT_EQ(runner, i, 18, "Flip_Block(%u, %u)", offset, len); + + DECREF(bit_vec); + } + } +} + +static void +test_Mimic(TestBatchRunner *runner) { + for (unsigned foo = 0; foo <= 17; foo++) { + for (unsigned bar = 0; bar <= 17; bar++) { + BitVector *foo_vec = BitVec_new(0); + BitVector *bar_vec = BitVec_new(0); + + BitVec_Set(foo_vec, foo); + BitVec_Set(bar_vec, bar); + BitVec_Mimic(foo_vec, (Obj*)bar_vec); + + unsigned i; + for (i = 0; i <= 17; i++) { + if (BitVec_Get(foo_vec, i) && i != bar) { break; } + } + TEST_UINT_EQ(runner, i, 18, "Mimic(%u, %u)", foo, bar); + + DECREF(foo_vec); + DECREF(bar_vec); + } + } +} + +static BitVector* +S_create_set(int set_num) { + unsigned nums_1[] = { 1, 2, 3, 10, 20, 30, 0 }; + unsigned nums_2[] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 0 + }; + unsigned *nums = set_num == 1 ? nums_1 : nums_2; + BitVector *bit_vec = BitVec_new(31); + for (unsigned i = 0; nums[i] != 0; i++) { + BitVec_Set(bit_vec, nums[i]); + } + return bit_vec; +} + +#define OP_OR 1 +#define OP_XOR 2 +#define OP_AND 3 +#define OP_AND_NOT 4 +static unsigned +S_verify_logical_op(BitVector *bit_vec, BitVector *set_1, BitVector *set_2, + int op) { + unsigned i; + + for (i = 0; i < 50; i++) { + bool wanted; + + switch (op) { + case OP_OR: + wanted = BitVec_Get(set_1, i) || BitVec_Get(set_2, i); + break; + case OP_XOR: + wanted = (!BitVec_Get(set_1, i)) != (!BitVec_Get(set_2, i)); + break; + case OP_AND: + wanted = BitVec_Get(set_1, i) && BitVec_Get(set_2, i); + break; + case OP_AND_NOT: + wanted = BitVec_Get(set_1, i) && (!BitVec_Get(set_2, i)); + break; + default: + wanted = false; + THROW(ERR, "unknown op: %d", op); + } + + if (BitVec_Get(bit_vec, i) != wanted) { break; } + } + + return i; +} + +static void +test_Or(TestBatchRunner *runner) { + BitVector *smaller = S_create_set(1); + BitVector *larger = S_create_set(2); + BitVector *set_1 = S_create_set(1); + BitVector *set_2 = S_create_set(2); + + BitVec_Or(smaller, set_2); + TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_OR), + 50, "OR with self smaller than other"); + BitVec_Or(larger, set_1); + TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_OR), + 50, "OR with other smaller than self"); + + DECREF(smaller); + DECREF(larger); + DECREF(set_1); + DECREF(set_2); +} + +static void +test_Xor(TestBatchRunner *runner) { + BitVector *smaller = S_create_set(1); + BitVector *larger = S_create_set(2); + BitVector *set_1 = S_create_set(1); + BitVector *set_2 = S_create_set(2); + + BitVec_Xor(smaller, set_2); + TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_XOR), + 50, "XOR with self smaller than other"); + BitVec_Xor(larger, set_1); + TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_XOR), + 50, "XOR with other smaller than self"); + + DECREF(smaller); + DECREF(larger); + DECREF(set_1); + DECREF(set_2); +} + +static void +test_And(TestBatchRunner *runner) { + BitVector *smaller = S_create_set(1); + BitVector *larger = S_create_set(2); + BitVector *set_1 = S_create_set(1); + BitVector *set_2 = S_create_set(2); + + BitVec_And(smaller, set_2); + TEST_UINT_EQ(runner, S_verify_logical_op(smaller, set_1, set_2, OP_AND), + 50, "AND with self smaller than other"); + BitVec_And(larger, set_1); + TEST_UINT_EQ(runner, S_verify_logical_op(larger, set_1, set_2, OP_AND), + 50, "AND with other smaller than self"); + + DECREF(smaller); + DECREF(larger); + DECREF(set_1); + DECREF(set_2); +} + +static void +test_And_Not(TestBatchRunner *runner) { + BitVector *smaller = S_create_set(1); + BitVector *larger = S_create_set(2); + BitVector *set_1 = S_create_set(1); + BitVector *set_2 = S_create_set(2); + + BitVec_And_Not(smaller, set_2); + TEST_UINT_EQ(runner, + S_verify_logical_op(smaller, set_1, set_2, OP_AND_NOT), + 50, "AND_NOT with self smaller than other"); + BitVec_And_Not(larger, set_1); + TEST_UINT_EQ(runner, + S_verify_logical_op(larger, set_2, set_1, OP_AND_NOT), + 50, "AND_NOT with other smaller than self"); + + DECREF(smaller); + DECREF(larger); + DECREF(set_1); + DECREF(set_2); +} + +static void +test_Count(TestBatchRunner *runner) { + unsigned shuffled[64]; + BitVector *bit_vec = BitVec_new(64); + + for (unsigned i = 0; i < 64; i++) { shuffled[i] = i; } + for (unsigned i = 0; i < 64; i++) { + unsigned shuffle_pos = (unsigned)rand() % 64; + unsigned temp = shuffled[shuffle_pos]; + shuffled[shuffle_pos] = shuffled[i]; + shuffled[i] = temp; + } + unsigned i; + for (i = 0; i < 64; i++) { + BitVec_Set(bit_vec, shuffled[i]); + if (BitVec_Count(bit_vec) != (uint32_t)(i + 1)) { break; } + } + TEST_UINT_EQ(runner, i, 64, "Count() returns the right number of bits"); + + DECREF(bit_vec); +} + +static void +test_Next_Hit(TestBatchRunner *runner) { + for (int i = 24; i <= 33; i++) { + BitVector *bit_vec = BitVec_new(64); + BitVec_Set(bit_vec, (size_t)i); + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, 0), i, + "Next_Hit for 0 is %d", i); + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, 1), i, + "Next_Hit for 1 is %d", i); + for (int probe = 15; probe <= i; probe++) { + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, (size_t)probe), i, + "Next_Hit for %d is %d", probe, i); + } + for (int probe = i + 1; probe <= i + 9; probe++) { + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, (size_t)probe), -1, + "no Next_Hit for %d when max is %d", probe, i); + } + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, INT32_MAX), -1, + "no Next_Hit for INT32_MAX when max is %d", i); + DECREF(bit_vec); + } +} + +static void +test_Clear_All(TestBatchRunner *runner) { + BitVector *bit_vec = BitVec_new(64); + BitVec_Flip_Block(bit_vec, 0, 63); + BitVec_Clear_All(bit_vec); + TEST_INT_EQ(runner, BitVec_Next_Hit(bit_vec, 0), -1, "Clear_All"); + DECREF(bit_vec); +} + +static void +test_Clone(TestBatchRunner *runner) { + BitVector *self = BitVec_new(30); + BitVector *twin; + + BitVec_Set(self, 2); + BitVec_Set(self, 3); + BitVec_Set(self, 10); + BitVec_Set(self, 20); + + twin = BitVec_Clone(self); + size_t i; + for (i = 0; i < 50; i++) { + if (BitVec_Get(self, i) != BitVec_Get(twin, i)) { break; } + } + TEST_UINT_EQ(runner, i, 50, "Clone"); + TEST_UINT_EQ(runner, BitVec_Count(twin), 4, "clone Count"); + + DECREF(self); + DECREF(twin); +} + +static int +S_compare_u64s(const void *va, const void *vb) { + uint64_t a = *(uint64_t*)va; + uint64_t b = *(uint64_t*)vb; + return a == b ? 0 : a < b ? -1 : 1; +} + +static void +test_To_Array(TestBatchRunner *runner) { + uint64_t *source_ints = TestUtils_random_u64s(NULL, 20, 0, 200); + BitVector *bit_vec = BitVec_new(0); + I32Array *array; + unsigned num_unique = 0; + + // Unique the random ints. + qsort(source_ints, 20, sizeof(uint64_t), S_compare_u64s); + for (unsigned i = 0; i < 19; i++) { + if (source_ints[i] != source_ints[i + 1]) { + source_ints[num_unique] = source_ints[i]; + num_unique++; + } + } + + // Set bits. + for (unsigned i = 0; i < num_unique; i++) { + BitVec_Set(bit_vec, (size_t)source_ints[i]); + } + + // Create the array and compare it to the source. + array = BitVec_To_Array(bit_vec); + unsigned i; + for (i = 0; i < num_unique; i++) { + if (I32Arr_Get(array, (size_t)i) != (int32_t)source_ints[i]) { break; } + } + TEST_UINT_EQ(runner, i, num_unique, "To_Array (%u == %u)", i, + num_unique); + + DECREF(array); + DECREF(bit_vec); + FREEMEM(source_ints); +} + + +// Valgrind only - detect off-by-one error. +static void +test_off_by_one_error() { + for (unsigned cap = 5; cap <= 24; cap++) { + BitVector *bit_vec = BitVec_new(cap); + BitVec_Set(bit_vec, cap - 2); + DECREF(bit_vec); + } +} + +void +TestBitVector_Run_IMP(TestBitVector *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 1039); + test_Set_and_Get(runner); + test_Flip(runner); + test_Flip_Block_ascending(runner); + test_Flip_Block_descending(runner); + test_Flip_Block_bulk(runner); + test_Mimic(runner); + test_Or(runner); + test_Xor(runner); + test_And(runner); + test_And_Not(runner); + test_Count(runner); + test_Next_Hit(runner); + test_Clear_All(runner); + test_Clone(runner); + test_To_Array(runner); + test_off_by_one_error(); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Object/TestBitVector.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Object/TestBitVector.cfh b/test/Lucy/Test/Object/TestBitVector.cfh new file mode 100644 index 0000000..e38c66d --- /dev/null +++ b/test/Lucy/Test/Object/TestBitVector.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::Object::TestBitVector + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestBitVector* + new(); + + void + Run(TestBitVector *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Object/TestI32Array.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Object/TestI32Array.c b/test/Lucy/Test/Object/TestI32Array.c new file mode 100644 index 0000000..7236d7b --- /dev/null +++ b/test/Lucy/Test/Object/TestI32Array.c @@ -0,0 +1,73 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTI32ARRAY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Object/TestI32Array.h" + +static int32_t source_ints[] = { -1, 0, INT32_MIN, INT32_MAX, 1 }; +static size_t num_ints = sizeof(source_ints) / sizeof(int32_t); + +TestI32Array* +TestI32Arr_new() { + return (TestI32Array*)Class_Make_Obj(TESTI32ARRAY); +} + +static void +test_all(TestBatchRunner *runner) { + I32Array *i32_array = I32Arr_new(source_ints, num_ints); + int32_t *ints_copy = (int32_t*)malloc(num_ints * sizeof(int32_t)); + I32Array *stolen = I32Arr_new_steal(ints_copy, num_ints); + size_t num_matched; + + memcpy(ints_copy, source_ints, num_ints * sizeof(int32_t)); + + TEST_TRUE(runner, I32Arr_Get_Size(i32_array) == num_ints, + "Get_Size"); + TEST_TRUE(runner, I32Arr_Get_Size(stolen) == num_ints, + "Get_Size for stolen"); + + for (num_matched = 0; num_matched < num_ints; num_matched++) { + if (source_ints[num_matched] != I32Arr_Get(i32_array, num_matched)) { + break; + } + } + TEST_UINT_EQ(runner, num_matched, num_ints, + "Matched all source ints with Get()"); + + for (num_matched = 0; num_matched < num_ints; num_matched++) { + if (source_ints[num_matched] != I32Arr_Get(stolen, num_matched)) { + break; + } + } + TEST_UINT_EQ(runner, num_matched, num_ints, + "Matched all source ints in stolen I32Array with Get()"); + + DECREF(i32_array); + DECREF(stolen); +} + +void +TestI32Arr_Run_IMP(TestI32Array *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 4); + test_all(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Object/TestI32Array.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Object/TestI32Array.cfh b/test/Lucy/Test/Object/TestI32Array.cfh new file mode 100644 index 0000000..dceba6b --- /dev/null +++ b/test/Lucy/Test/Object/TestI32Array.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::Object::TestI32Array nickname TestI32Arr + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestI32Array* + new(); + + void + Run(TestI32Array *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestArchitecture.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestArchitecture.c b/test/Lucy/Test/Plan/TestArchitecture.c new file mode 100644 index 0000000..138405c --- /dev/null +++ b/test/Lucy/Test/Plan/TestArchitecture.c @@ -0,0 +1,50 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTARCHITECTURE +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestArchitecture.h" +#include "Lucy/Plan/Architecture.h" + +TestArchitecture* +TestArch_new() { + TestArchitecture *self + = (TestArchitecture*)Class_Make_Obj(TESTARCHITECTURE); + return TestArch_init(self); +} + +TestArchitecture* +TestArch_init(TestArchitecture *self) { + Arch_init((Architecture*)self); + return self; +} + +int32_t +TestArch_Index_Interval_IMP(TestArchitecture *self) { + UNUSED_VAR(self); + return 5; +} + +int32_t +TestArch_Skip_Interval_IMP(TestArchitecture *self) { + UNUSED_VAR(self); + return 3; +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestArchitecture.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestArchitecture.cfh b/test/Lucy/Test/Plan/TestArchitecture.cfh new file mode 100644 index 0000000..737519b --- /dev/null +++ b/test/Lucy/Test/Plan/TestArchitecture.cfh @@ -0,0 +1,39 @@ +/* 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; + +/** + * Returns absurdly low values for [](cfish:.Index_Interval) and [](cfish:.Skip_Interval). + */ + +class Lucy::Test::Plan::TestArchitecture nickname TestArch + inherits Lucy::Plan::Architecture { + + inert incremented TestArchitecture* + new(); + + inert TestArchitecture* + init(TestArchitecture *self); + + int32_t + Index_Interval(TestArchitecture *self); + + int32_t + Skip_Interval(TestArchitecture *self); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestBlobType.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestBlobType.c b/test/Lucy/Test/Plan/TestBlobType.c new file mode 100644 index 0000000..a207997 --- /dev/null +++ b/test/Lucy/Test/Plan/TestBlobType.c @@ -0,0 +1,59 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTBLOBTYPE +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestBlobType.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Plan/BlobType.h" +#include "Lucy/Util/Freezer.h" + +TestBlobType* +TestBlobType_new() { + return (TestBlobType*)Class_Make_Obj(TESTBLOBTYPE); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + BlobType *type = BlobType_new(true); + Obj *dump = (Obj*)BlobType_Dump(type); + Obj *clone = Freezer_load(dump); + Obj *another_dump = (Obj*)BlobType_Dump_For_Schema(type); + BlobType *another_clone = BlobType_Load(type, another_dump); + + TEST_TRUE(runner, BlobType_Equals(type, (Obj*)clone), + "Dump => Load round trip"); + TEST_TRUE(runner, BlobType_Equals(type, (Obj*)another_clone), + "Dump_For_Schema => Load round trip"); + + DECREF(type); + DECREF(dump); + DECREF(clone); + DECREF(another_dump); + DECREF(another_clone); +} + +void +TestBlobType_Run_IMP(TestBlobType *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 2); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestBlobType.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestBlobType.cfh b/test/Lucy/Test/Plan/TestBlobType.cfh new file mode 100644 index 0000000..a0ffc79 --- /dev/null +++ b/test/Lucy/Test/Plan/TestBlobType.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::Plan::TestBlobType + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestBlobType* + new(); + + void + Run(TestBlobType *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFieldMisc.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFieldMisc.c b/test/Lucy/Test/Plan/TestFieldMisc.c new file mode 100644 index 0000000..54779f4 --- /dev/null +++ b/test/Lucy/Test/Plan/TestFieldMisc.c @@ -0,0 +1,248 @@ +/* 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. + */ + + +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestFieldMisc.h" + +#include "Lucy/Analysis/EasyAnalyzer.h" +#include "Lucy/Analysis/StandardTokenizer.h" +#include "Lucy/Document/Doc.h" +#include "Lucy/Document/HitDoc.h" +#include "Lucy/Index/Indexer.h" +#include "Lucy/Plan/FullTextType.h" +#include "Lucy/Plan/Schema.h" +#include "Lucy/Plan/StringType.h" +#include "Lucy/Search/Hits.h" +#include "Lucy/Search/IndexSearcher.h" +#include "Lucy/Search/TermQuery.h" +#include "Lucy/Store/RAMFolder.h" + +static String *analyzed_str; +static String *easy_analyzed_str; +static String *state_str; +static String *states_str; +static String *string_str; +static String *unindexed_but_analyzed_str; +static String *unindexed_unanalyzed_str; +static String *united_states_str; + +TestFieldMisc* +TestFieldMisc_new() { + return (TestFieldMisc*)Class_Make_Obj(TESTFIELDMISC); +} + +static void +S_init_strings() { + analyzed_str = Str_newf("analyzed"); + easy_analyzed_str = Str_newf("easy_analyzed"); + state_str = Str_newf("state"); + states_str = Str_newf("States"); + string_str = Str_newf("string"); + unindexed_but_analyzed_str = Str_newf("unindexed_but_analyzed"); + unindexed_unanalyzed_str = Str_newf("unindexed_unanalyzed"); + united_states_str = Str_newf("United States"); +} + +static void +S_destroy_strings() { + DECREF(analyzed_str); + DECREF(easy_analyzed_str); + DECREF(state_str); + DECREF(states_str); + DECREF(string_str); + DECREF(unindexed_but_analyzed_str); + DECREF(unindexed_unanalyzed_str); + DECREF(united_states_str); +} + +static Schema* +S_create_schema() { + Schema *schema = Schema_new(); + + StandardTokenizer *tokenizer = StandardTokenizer_new(); + String *language = Str_newf("en"); + EasyAnalyzer *easy_analyzer = EasyAnalyzer_new(language); + + FullTextType *plain = FullTextType_new((Analyzer*)tokenizer); + FullTextType *easy_analyzed = FullTextType_new((Analyzer*)easy_analyzer); + + StringType *string_spec = StringType_new(); + + FullTextType *unindexed_but_analyzed + = FullTextType_new((Analyzer*)tokenizer); + FullTextType_Set_Indexed(unindexed_but_analyzed, false); + + StringType *unindexed_unanalyzed = StringType_new(); + StringType_Set_Indexed(unindexed_unanalyzed, false); + + Schema_Spec_Field(schema, analyzed_str, (FieldType*)plain); + Schema_Spec_Field(schema, easy_analyzed_str, (FieldType*)easy_analyzed); + Schema_Spec_Field(schema, string_str, (FieldType*)string_spec); + Schema_Spec_Field(schema, unindexed_but_analyzed_str, + (FieldType*)unindexed_but_analyzed); + Schema_Spec_Field(schema, unindexed_unanalyzed_str, + (FieldType*)unindexed_unanalyzed); + + DECREF(unindexed_unanalyzed); + DECREF(unindexed_but_analyzed); + DECREF(string_spec); + DECREF(easy_analyzed); + DECREF(plain); + DECREF(easy_analyzer); + DECREF(language); + DECREF(tokenizer); + + return schema; +} + +static void +S_add_doc(Indexer *indexer, String *field_name) { + Doc *doc = Doc_new(NULL, 0); + Doc_Store(doc, field_name, (Obj*)united_states_str); + Indexer_Add_Doc(indexer, doc, 1.0f); + DECREF(doc); +} + +static void +S_check(TestBatchRunner *runner, RAMFolder *folder, String *field, + String *query_text, uint32_t expected_num_hits) { + char *field_str = Str_To_Utf8(field); + TermQuery *query = TermQuery_new(field, (Obj*)query_text); + IndexSearcher *searcher = IxSearcher_new((Obj*)folder); + Hits *hits = IxSearcher_Hits(searcher, (Obj*)query, 0, 10, NULL); + + TEST_TRUE(runner, Hits_Total_Hits(hits) == expected_num_hits, + "%s correct num hits", field_str); + + // Don't check the contents of the hit if there aren't any. + if (expected_num_hits) { + HitDoc *hit = Hits_Next(hits); + String *value = (String*)HitDoc_Extract(hit, field); + TEST_TRUE(runner, Str_Equals(united_states_str, (Obj*)value), + "%s correct doc returned", field_str); + DECREF(value); + DECREF(hit); + } + + DECREF(hits); + DECREF(searcher); + DECREF(query); + free(field_str); +} + +static void +test_spec_field(TestBatchRunner *runner) { + RAMFolder *folder = RAMFolder_new(NULL); + Schema *schema = S_create_schema(); + Indexer *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0); + + S_add_doc(indexer, analyzed_str); + S_add_doc(indexer, easy_analyzed_str); + S_add_doc(indexer, string_str); + S_add_doc(indexer, unindexed_but_analyzed_str); + S_add_doc(indexer, unindexed_unanalyzed_str); + + Indexer_Commit(indexer); + + S_check(runner, folder, analyzed_str, states_str, 1); + S_check(runner, folder, easy_analyzed_str, state_str, 1); + S_check(runner, folder, string_str, united_states_str, 1); + S_check(runner, folder, unindexed_but_analyzed_str, state_str, 0); + S_check(runner, folder, unindexed_but_analyzed_str, united_states_str, 0); + S_check(runner, folder, unindexed_unanalyzed_str, state_str, 0); + S_check(runner, folder, unindexed_unanalyzed_str, united_states_str, 0); + + DECREF(indexer); + DECREF(schema); + DECREF(folder); +} + +static void +S_add_many_fields_doc(Indexer *indexer, String *content, int num_fields) { + Doc *doc = Doc_new(NULL, 0); + for (int32_t i = 1; i <= num_fields; ++i) { + String *field = Str_newf("field%i32", i); + Doc_Store(doc, field, (Obj*)content); + DECREF(field); + } + Indexer_Add_Doc(indexer, doc, 1.0f); + DECREF(doc); +} + +static void +test_many_fields(TestBatchRunner *runner) { + Schema *schema = Schema_new(); + StandardTokenizer *tokenizer = StandardTokenizer_new(); + FullTextType *type = FullTextType_new((Analyzer*)tokenizer); + String *query = Str_newf("x"); + + for (int32_t num_fields = 1; num_fields <= 10; ++num_fields) { + // Build an index with num_fields fields, and the same content in each. + String *field = Str_newf("field%i32", num_fields); + Schema_Spec_Field(schema, field, (FieldType*)type); + + RAMFolder *folder = RAMFolder_new(NULL); + Indexer *indexer = Indexer_new(schema, (Obj*)folder, NULL, 0); + + String *content; + + for (int c = 'a'; c <= 'z'; ++c) { + content = Str_new_from_char(c); + S_add_many_fields_doc(indexer, content, num_fields); + DECREF(content); + } + + content = Str_newf("x x y"); + S_add_many_fields_doc(indexer, content, num_fields); + DECREF(content); + + Indexer_Commit(indexer); + + // See if our search results match as expected. + IndexSearcher *searcher = IxSearcher_new((Obj*)folder); + Hits *hits = IxSearcher_Hits(searcher, (Obj*)query, 0, 100, NULL); + TEST_TRUE(runner, Hits_Total_Hits(hits) == 2, + "correct number of hits for %d fields", num_fields); + HitDoc *top_hit = Hits_Next(hits); + + DECREF(top_hit); + DECREF(hits); + DECREF(searcher); + DECREF(indexer); + DECREF(folder); + DECREF(field); + } + + DECREF(query); + DECREF(type); + DECREF(tokenizer); + DECREF(schema); +} + +void +TestFieldMisc_Run_IMP(TestFieldMisc *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 20); + S_init_strings(); + test_spec_field(runner); + test_many_fields(runner); + S_destroy_strings(); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFieldMisc.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFieldMisc.cfh b/test/Lucy/Test/Plan/TestFieldMisc.cfh new file mode 100644 index 0000000..f3f686a --- /dev/null +++ b/test/Lucy/Test/Plan/TestFieldMisc.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::Plan::TestFieldMisc + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestFieldMisc* + new(); + + void + Run(TestFieldMisc *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFieldType.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFieldType.c b/test/Lucy/Test/Plan/TestFieldType.c new file mode 100644 index 0000000..b81fce5 --- /dev/null +++ b/test/Lucy/Test/Plan/TestFieldType.c @@ -0,0 +1,107 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTFIELDTYPE +#define C_LUCY_DUMMYFIELDTYPE +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestFieldType.h" +#include "Lucy/Test/TestUtils.h" + +TestFieldType* +TestFType_new() { + return (TestFieldType*)Class_Make_Obj(TESTFIELDTYPE); +} + +DummyFieldType* +DummyFieldType_new() { + DummyFieldType *self = (DummyFieldType*)Class_Make_Obj(DUMMYFIELDTYPE); + return (DummyFieldType*)FType_init((FieldType*)self); +} + +static FieldType* +S_alt_field_type() { + String *name = SSTR_WRAP_C("DummyFieldType2"); + Class *klass = Class_singleton(name, DUMMYFIELDTYPE); + FieldType *self = (FieldType*)Class_Make_Obj(klass); + return FType_init(self); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + FieldType *type = (FieldType*)DummyFieldType_new(); + FieldType *other = (FieldType*)DummyFieldType_new(); + FieldType *class_differs = S_alt_field_type(); + 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(runner, FType_Equals(type, (Obj*)other), + "Equals() true with identical stats"); + TEST_FALSE(runner, FType_Equals(type, (Obj*)class_differs), + "Equals() false with subclass"); + TEST_FALSE(runner, FType_Equals(type, (Obj*)class_differs), + "Equals() false with super class"); + TEST_FALSE(runner, FType_Equals(type, (Obj*)boost_differs), + "Equals() false with different boost"); + TEST_FALSE(runner, FType_Equals(type, (Obj*)indexed), + "Equals() false with indexed => true"); + TEST_FALSE(runner, FType_Equals(type, (Obj*)stored), + "Equals() false with stored => true"); + + DECREF(stored); + DECREF(indexed); + DECREF(boost_differs); + DECREF(class_differs); + DECREF(other); + DECREF(type); +} + +static void +test_Compare_Values(TestBatchRunner *runner) { + FieldType *type = (FieldType*)DummyFieldType_new(); + Obj *a = (Obj*)SSTR_WRAP_C("a"); + Obj *b = (Obj*)SSTR_WRAP_C("b"); + + TEST_TRUE(runner, FType_Compare_Values(type, a, b) < 0, + "a less than b"); + TEST_TRUE(runner, FType_Compare_Values(type, b, a) > 0, + "b greater than a"); + TEST_TRUE(runner, FType_Compare_Values(type, b, b) == 0, + "b equals b"); + + DECREF(type); +} + +void +TestFType_Run_IMP(TestFieldType *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 9); + test_Dump_Load_and_Equals(runner); + test_Compare_Values(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFieldType.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFieldType.cfh b/test/Lucy/Test/Plan/TestFieldType.cfh new file mode 100644 index 0000000..a82c640 --- /dev/null +++ b/test/Lucy/Test/Plan/TestFieldType.cfh @@ -0,0 +1,33 @@ +/* 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::Plan::TestFieldType nickname TestFType + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestFieldType* + new(); + + void + Run(TestFieldType *self, TestBatchRunner *runner); +} + +class Lucy::Test::Plan::DummyFieldType inherits Lucy::Plan::FieldType { + inert incremented DummyFieldType* + new(); +} + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFullTextType.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFullTextType.c b/test/Lucy/Test/Plan/TestFullTextType.c new file mode 100644 index 0000000..709b1c2 --- /dev/null +++ b/test/Lucy/Test/Plan/TestFullTextType.c @@ -0,0 +1,112 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTFULLTEXTTYPE +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestFullTextType.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Plan/FullTextType.h" +#include "Lucy/Analysis/Normalizer.h" +#include "Lucy/Analysis/StandardTokenizer.h" +#include "Lucy/Util/Freezer.h" + +TestFullTextType* +TestFullTextType_new() { + return (TestFullTextType*)Class_Make_Obj(TESTFULLTEXTTYPE); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + StandardTokenizer *tokenizer = StandardTokenizer_new(); + Normalizer *normalizer = Normalizer_new(NULL, true, false); + FullTextType *type = FullTextType_new((Analyzer*)tokenizer); + FullTextType *other = FullTextType_new((Analyzer*)normalizer); + 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 = Freezer_load(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_Utf8((Hash*)another_dump, "analyzer", 8, INCREF(tokenizer)); + FullTextType *another_clone = FullTextType_Load(type, another_dump); + + TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)boost_differs), + "Equals() false with different boost"); + TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)other), + "Equals() false with different Analyzer"); + TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)not_indexed), + "Equals() false with indexed => false"); + TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)not_stored), + "Equals() false with stored => false"); + TEST_FALSE(runner, FullTextType_Equals(type, (Obj*)highlightable), + "Equals() false with highlightable => true"); + TEST_TRUE(runner, FullTextType_Equals(type, (Obj*)clone), + "Dump => Load round trip"); + TEST_TRUE(runner, 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); + DECREF(boost_differs); + DECREF(other); + DECREF(type); + DECREF(normalizer); + DECREF(tokenizer); +} + +static void +test_Compare_Values(TestBatchRunner *runner) { + StandardTokenizer *tokenizer = StandardTokenizer_new(); + FullTextType *type = FullTextType_new((Analyzer*)tokenizer); + Obj *a = (Obj*)SSTR_WRAP_C("a"); + Obj *b = (Obj*)SSTR_WRAP_C("b"); + + TEST_TRUE(runner, FullTextType_Compare_Values(type, a, b) < 0, + "a less than b"); + TEST_TRUE(runner, FullTextType_Compare_Values(type, b, a) > 0, + "b greater than a"); + TEST_TRUE(runner, FullTextType_Compare_Values(type, b, b) == 0, + "b equals b"); + + DECREF(type); + DECREF(tokenizer); +} + +void +TestFullTextType_Run_IMP(TestFullTextType *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 10); + test_Dump_Load_and_Equals(runner); + test_Compare_Values(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestFullTextType.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestFullTextType.cfh b/test/Lucy/Test/Plan/TestFullTextType.cfh new file mode 100644 index 0000000..cfdbf7c --- /dev/null +++ b/test/Lucy/Test/Plan/TestFullTextType.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::Plan::TestFullTextType + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestFullTextType* + new(); + + void + Run(TestFullTextType *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestNumericType.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestNumericType.c b/test/Lucy/Test/Plan/TestNumericType.c new file mode 100644 index 0000000..b36af4c --- /dev/null +++ b/test/Lucy/Test/Plan/TestNumericType.c @@ -0,0 +1,109 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTNUMERICTYPE +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Plan/TestNumericType.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Plan/BlobType.h" +#include "Lucy/Plan/NumericType.h" +#include "Lucy/Util/Freezer.h" + +TestNumericType* +TestNumericType_new() { + return (TestNumericType*)Class_Make_Obj(TESTNUMERICTYPE); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + Int32Type *i32 = Int32Type_new(); + Int64Type *i64 = Int64Type_new(); + Float32Type *f32 = Float32Type_new(); + Float64Type *f64 = Float64Type_new(); + + TEST_FALSE(runner, Int32Type_Equals(i32, (Obj*)i64), + "Int32Type_Equals() false for different type"); + TEST_FALSE(runner, Int32Type_Equals(i32, NULL), + "Int32Type_Equals() false for NULL"); + + TEST_FALSE(runner, Int64Type_Equals(i64, (Obj*)i32), + "Int64Type_Equals() false for different type"); + TEST_FALSE(runner, Int64Type_Equals(i64, NULL), + "Int64Type_Equals() false for NULL"); + + TEST_FALSE(runner, Float32Type_Equals(f32, (Obj*)f64), + "Float32Type_Equals() false for different type"); + TEST_FALSE(runner, Float32Type_Equals(f32, NULL), + "Float32Type_Equals() false for NULL"); + + TEST_FALSE(runner, Float64Type_Equals(f64, (Obj*)f32), + "Float64Type_Equals() false for different type"); + TEST_FALSE(runner, Float64Type_Equals(f64, NULL), + "Float64Type_Equals() false for NULL"); + + { + Obj *dump = (Obj*)Int32Type_Dump(i32); + Obj *other = Freezer_load(dump); + TEST_TRUE(runner, Int32Type_Equals(i32, other), + "Dump => Load round trip for Int32Type"); + DECREF(dump); + DECREF(other); + } + + { + Obj *dump = (Obj*)Int64Type_Dump(i64); + Obj *other = Freezer_load(dump); + TEST_TRUE(runner, Int64Type_Equals(i64, other), + "Dump => Load round trip for Int64Type"); + DECREF(dump); + DECREF(other); + } + + { + Obj *dump = (Obj*)Float32Type_Dump(f32); + Obj *other = Freezer_load(dump); + TEST_TRUE(runner, Float32Type_Equals(f32, other), + "Dump => Load round trip for Float32Type"); + DECREF(dump); + DECREF(other); + } + + { + Obj *dump = (Obj*)Float64Type_Dump(f64); + Obj *other = Freezer_load(dump); + TEST_TRUE(runner, Float64Type_Equals(f64, other), + "Dump => Load round trip for Float64Type"); + DECREF(dump); + DECREF(other); + } + + DECREF(i32); + DECREF(i64); + DECREF(f32); + DECREF(f64); +} + +void +TestNumericType_Run_IMP(TestNumericType *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 12); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Plan/TestNumericType.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Plan/TestNumericType.cfh b/test/Lucy/Test/Plan/TestNumericType.cfh new file mode 100644 index 0000000..e3d952e --- /dev/null +++ b/test/Lucy/Test/Plan/TestNumericType.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::Plan::TestNumericType + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestNumericType* + new(); + + void + Run(TestNumericType *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestLeafQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestLeafQuery.c b/test/Lucy/Test/Search/TestLeafQuery.c new file mode 100644 index 0000000..f6e013f --- /dev/null +++ b/test/Lucy/Test/Search/TestLeafQuery.c @@ -0,0 +1,70 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTLEAFQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/Search/TestLeafQuery.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Search/LeafQuery.h" + +TestLeafQuery* +TestLeafQuery_new() { + return (TestLeafQuery*)Class_Make_Obj(TESTLEAFQUERY); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + LeafQuery *query = TestUtils_make_leaf_query("content", "foo"); + LeafQuery *field_differs = TestUtils_make_leaf_query("stuff", "foo"); + LeafQuery *null_field = TestUtils_make_leaf_query(NULL, "foo"); + LeafQuery *term_differs = TestUtils_make_leaf_query("content", "bar"); + LeafQuery *boost_differs = TestUtils_make_leaf_query("content", "foo"); + Obj *dump = (Obj*)LeafQuery_Dump(query); + LeafQuery *clone = (LeafQuery*)LeafQuery_Load(term_differs, dump); + + TEST_FALSE(runner, LeafQuery_Equals(query, (Obj*)field_differs), + "Equals() false with different field"); + TEST_FALSE(runner, LeafQuery_Equals(query, (Obj*)null_field), + "Equals() false with null field"); + TEST_FALSE(runner, LeafQuery_Equals(query, (Obj*)term_differs), + "Equals() false with different term"); + LeafQuery_Set_Boost(boost_differs, 0.5); + TEST_FALSE(runner, LeafQuery_Equals(query, (Obj*)boost_differs), + "Equals() false with different boost"); + TEST_TRUE(runner, LeafQuery_Equals(query, (Obj*)clone), + "Dump => Load round trip"); + + DECREF(query); + DECREF(term_differs); + DECREF(field_differs); + DECREF(null_field); + DECREF(boost_differs); + DECREF(dump); + DECREF(clone); +} + +void +TestLeafQuery_Run_IMP(TestLeafQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 5); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestLeafQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestLeafQuery.cfh b/test/Lucy/Test/Search/TestLeafQuery.cfh new file mode 100644 index 0000000..3750b6e --- /dev/null +++ b/test/Lucy/Test/Search/TestLeafQuery.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::Search::TestLeafQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestLeafQuery* + new(); + + void + Run(TestLeafQuery *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestMatchAllQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestMatchAllQuery.c b/test/Lucy/Test/Search/TestMatchAllQuery.c new file mode 100644 index 0000000..524d25d --- /dev/null +++ b/test/Lucy/Test/Search/TestMatchAllQuery.c @@ -0,0 +1,57 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTMATCHALLQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/Boolean.h" +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Search/TestMatchAllQuery.h" +#include "Lucy/Search/MatchAllQuery.h" + +TestMatchAllQuery* +TestMatchAllQuery_new() { + return (TestMatchAllQuery*)Class_Make_Obj(TESTMATCHALLQUERY); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + MatchAllQuery *query = MatchAllQuery_new(); + Obj *dump = (Obj*)MatchAllQuery_Dump(query); + MatchAllQuery *clone = (MatchAllQuery*)MatchAllQuery_Load(query, dump); + + TEST_TRUE(runner, MatchAllQuery_Equals(query, (Obj*)clone), + "Dump => Load round trip"); + TEST_FALSE(runner, MatchAllQuery_Equals(query, (Obj*)CFISH_TRUE), + "Equals"); + + DECREF(query); + DECREF(dump); + DECREF(clone); +} + + +void +TestMatchAllQuery_Run_IMP(TestMatchAllQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 2); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestMatchAllQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestMatchAllQuery.cfh b/test/Lucy/Test/Search/TestMatchAllQuery.cfh new file mode 100644 index 0000000..c4232ff --- /dev/null +++ b/test/Lucy/Test/Search/TestMatchAllQuery.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::Search::TestMatchAllQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestMatchAllQuery* + new(); + + void + Run(TestMatchAllQuery *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestNOTQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestNOTQuery.c b/test/Lucy/Test/Search/TestNOTQuery.c new file mode 100644 index 0000000..eee7657 --- /dev/null +++ b/test/Lucy/Test/Search/TestNOTQuery.c @@ -0,0 +1,70 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTNOTQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Search/TestNOTQuery.h" +#include "Lucy/Search/NOTQuery.h" +#include "Lucy/Search/LeafQuery.h" +#include "Lucy/Util/Freezer.h" + +TestNOTQuery* +TestNOTQuery_new() { + return (TestNOTQuery*)Class_Make_Obj(TESTNOTQUERY); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + Query *a_leaf = (Query*)TestUtils_make_leaf_query(NULL, "a"); + Query *b_leaf = (Query*)TestUtils_make_leaf_query(NULL, "b"); + NOTQuery *query = NOTQuery_new(a_leaf); + NOTQuery *kids_differ = NOTQuery_new(b_leaf); + NOTQuery *boost_differs = NOTQuery_new(a_leaf); + Obj *dump = (Obj*)NOTQuery_Dump(query); + NOTQuery *clone = (NOTQuery*)Freezer_load(dump); + + TEST_FALSE(runner, NOTQuery_Equals(query, (Obj*)kids_differ), + "Different kids spoil Equals"); + TEST_TRUE(runner, NOTQuery_Equals(query, (Obj*)boost_differs), + "Equals with identical boosts"); + NOTQuery_Set_Boost(boost_differs, 1.5); + TEST_FALSE(runner, NOTQuery_Equals(query, (Obj*)boost_differs), + "Different boost spoils Equals"); + TEST_TRUE(runner, NOTQuery_Equals(query, (Obj*)clone), + "Dump => Load round trip"); + + DECREF(a_leaf); + DECREF(b_leaf); + DECREF(query); + DECREF(kids_differ); + DECREF(boost_differs); + DECREF(dump); + DECREF(clone); +} + +void +TestNOTQuery_Run_IMP(TestNOTQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 4); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestNOTQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestNOTQuery.cfh b/test/Lucy/Test/Search/TestNOTQuery.cfh new file mode 100644 index 0000000..bc432ff --- /dev/null +++ b/test/Lucy/Test/Search/TestNOTQuery.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::Search::TestNOTQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestNOTQuery* + new(); + + void + Run(TestNOTQuery *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestNoMatchQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestNoMatchQuery.c b/test/Lucy/Test/Search/TestNoMatchQuery.c new file mode 100644 index 0000000..bac28b9 --- /dev/null +++ b/test/Lucy/Test/Search/TestNoMatchQuery.c @@ -0,0 +1,57 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTNOMATCHQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/Boolean.h" +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Search/TestNoMatchQuery.h" +#include "Lucy/Search/NoMatchQuery.h" + +TestNoMatchQuery* +TestNoMatchQuery_new() { + return (TestNoMatchQuery*)Class_Make_Obj(TESTNOMATCHQUERY); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner) { + NoMatchQuery *query = NoMatchQuery_new(); + Obj *dump = (Obj*)NoMatchQuery_Dump(query); + NoMatchQuery *clone = (NoMatchQuery*)NoMatchQuery_Load(query, dump); + + TEST_TRUE(runner, NoMatchQuery_Equals(query, (Obj*)clone), + "Dump => Load round trip"); + TEST_FALSE(runner, NoMatchQuery_Equals(query, (Obj*)CFISH_TRUE), + "Equals"); + + DECREF(query); + DECREF(dump); + DECREF(clone); +} + + +void +TestNoMatchQuery_Run_IMP(TestNoMatchQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 2); + test_Dump_Load_and_Equals(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestNoMatchQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestNoMatchQuery.cfh b/test/Lucy/Test/Search/TestNoMatchQuery.cfh new file mode 100644 index 0000000..cb3420e --- /dev/null +++ b/test/Lucy/Test/Search/TestNoMatchQuery.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::Search::TestNoMatchQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestNoMatchQuery* + new(); + + void + Run(TestNoMatchQuery *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestPhraseQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestPhraseQuery.c b/test/Lucy/Test/Search/TestPhraseQuery.c new file mode 100644 index 0000000..c0ed6da --- /dev/null +++ b/test/Lucy/Test/Search/TestPhraseQuery.c @@ -0,0 +1,53 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTPHRASEQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Search/TestPhraseQuery.h" +#include "Lucy/Search/PhraseQuery.h" +#include "Lucy/Util/Freezer.h" + +TestPhraseQuery* +TestPhraseQuery_new() { + return (TestPhraseQuery*)Class_Make_Obj(TESTPHRASEQUERY); +} + +static void +test_Dump_And_Load(TestBatchRunner *runner) { + PhraseQuery *query + = TestUtils_make_phrase_query("content", "a", "b", "c", NULL); + Obj *dump = (Obj*)PhraseQuery_Dump(query); + PhraseQuery *twin = (PhraseQuery*)Freezer_load(dump); + TEST_TRUE(runner, PhraseQuery_Equals(query, (Obj*)twin), + "Dump => Load round trip"); + DECREF(query); + DECREF(dump); + DECREF(twin); +} + +void +TestPhraseQuery_Run_IMP(TestPhraseQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 1); + test_Dump_And_Load(runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestPhraseQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestPhraseQuery.cfh b/test/Lucy/Test/Search/TestPhraseQuery.cfh new file mode 100644 index 0000000..78969dc --- /dev/null +++ b/test/Lucy/Test/Search/TestPhraseQuery.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::Search::TestPhraseQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestPhraseQuery* + new(); + + void + Run(TestPhraseQuery *self, TestBatchRunner *runner); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestPolyQuery.c ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestPolyQuery.c b/test/Lucy/Test/Search/TestPolyQuery.c new file mode 100644 index 0000000..67fe6fa --- /dev/null +++ b/test/Lucy/Test/Search/TestPolyQuery.c @@ -0,0 +1,93 @@ +/* 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. + */ + +#define C_TESTLUCY_TESTPOLYQUERY +#define TESTLUCY_USE_SHORT_NAMES +#include "Lucy/Util/ToolSet.h" +#include <math.h> + +#include "Clownfish/TestHarness/TestBatchRunner.h" +#include "Lucy/Test.h" +#include "Lucy/Test/TestUtils.h" +#include "Lucy/Test/Search/TestPolyQuery.h" +#include "Lucy/Search/ANDQuery.h" +#include "Lucy/Search/ORQuery.h" +#include "Lucy/Search/PolyQuery.h" +#include "Lucy/Search/LeafQuery.h" +#include "Lucy/Util/Freezer.h" + +TestANDQuery* +TestANDQuery_new() { + return (TestANDQuery*)Class_Make_Obj(TESTANDQUERY); +} + +TestORQuery* +TestORQuery_new() { + return (TestORQuery*)Class_Make_Obj(TESTORQUERY); +} + +static void +test_Dump_Load_and_Equals(TestBatchRunner *runner, uint32_t boolop) { + LeafQuery *a_leaf = TestUtils_make_leaf_query(NULL, "a"); + LeafQuery *b_leaf = TestUtils_make_leaf_query(NULL, "b"); + LeafQuery *c_leaf = TestUtils_make_leaf_query(NULL, "c"); + PolyQuery *query + = (PolyQuery*)TestUtils_make_poly_query(boolop, INCREF(a_leaf), + INCREF(b_leaf), NULL); + PolyQuery *kids_differ + = (PolyQuery*)TestUtils_make_poly_query(boolop, INCREF(a_leaf), + INCREF(b_leaf), + INCREF(c_leaf), + NULL); + PolyQuery *boost_differs + = (PolyQuery*)TestUtils_make_poly_query(boolop, INCREF(a_leaf), + INCREF(b_leaf), NULL); + Obj *dump = (Obj*)PolyQuery_Dump(query); + PolyQuery *clone = (PolyQuery*)Freezer_load(dump); + + TEST_FALSE(runner, PolyQuery_Equals(query, (Obj*)kids_differ), + "Different kids spoil Equals"); + TEST_TRUE(runner, PolyQuery_Equals(query, (Obj*)boost_differs), + "Equals with identical boosts"); + PolyQuery_Set_Boost(boost_differs, 1.5); + TEST_FALSE(runner, PolyQuery_Equals(query, (Obj*)boost_differs), + "Different boost spoils Equals"); + TEST_TRUE(runner, PolyQuery_Equals(query, (Obj*)clone), + "Dump => Load round trip"); + + DECREF(a_leaf); + DECREF(b_leaf); + DECREF(c_leaf); + DECREF(query); + DECREF(kids_differ); + DECREF(boost_differs); + DECREF(dump); + DECREF(clone); +} + +void +TestANDQuery_Run_IMP(TestANDQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 4); + test_Dump_Load_and_Equals(runner, BOOLOP_AND); +} + +void +TestORQuery_Run_IMP(TestORQuery *self, TestBatchRunner *runner) { + TestBatchRunner_Plan(runner, (TestBatch*)self, 4); + test_Dump_Load_and_Equals(runner, BOOLOP_OR); +} + + http://git-wip-us.apache.org/repos/asf/lucy/blob/572d3564/test/Lucy/Test/Search/TestPolyQuery.cfh ---------------------------------------------------------------------- diff --git a/test/Lucy/Test/Search/TestPolyQuery.cfh b/test/Lucy/Test/Search/TestPolyQuery.cfh new file mode 100644 index 0000000..3e4a42d --- /dev/null +++ b/test/Lucy/Test/Search/TestPolyQuery.cfh @@ -0,0 +1,39 @@ +/* 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::Search::TestANDQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestANDQuery* + new(); + + void + Run(TestANDQuery *self, TestBatchRunner *runner); +} + +class Lucy::Test::Search::TestORQuery + inherits Clownfish::TestHarness::TestBatch { + + inert incremented TestORQuery* + new(); + + void + Run(TestORQuery *self, TestBatchRunner *runner); +} + +