MCPcopy Create free account
hub / github.com/RedisGraph/RedisGraph / test_array

Function test_array

tests/unit/test_value.c:167–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

165}
166
167void test_array() {
168 SIValue arr = SI_EmptyArray();
169 SIValue arrOther = SI_EmptyArray();
170
171 // Test for empty arrays.
172 uint64_t origHashCode = SIValue_HashCode(arr);
173 uint64_t otherHashCode = SIValue_HashCode(arrOther);
174 TEST_ASSERT(origHashCode == otherHashCode);
175
176 SIArray_Append(&arr, SI_LongVal(1));
177 origHashCode = SIValue_HashCode(arr);
178 TEST_ASSERT(origHashCode != otherHashCode);
179
180 SIArray_Append(&arrOther, SI_LongVal(1));
181 otherHashCode = SIValue_HashCode(arrOther);
182 TEST_ASSERT(origHashCode == otherHashCode);
183
184 SIValue nestedArr = SI_EmptyArray();
185 SIArray_Append(&nestedArr, SI_LongVal(2));
186 SIArray_Append(&nestedArr, SI_DoubleVal(3.14));
187
188 SIArray_Append(&arr, nestedArr);
189 origHashCode = SIValue_HashCode(arr);
190 TEST_ASSERT(origHashCode != otherHashCode);
191
192 SIArray_Append(&arrOther, nestedArr);
193 otherHashCode = SIValue_HashCode(arrOther);
194 TEST_ASSERT(origHashCode == otherHashCode);
195
196 // Test logic for nested type-checking
197 bool contains_double = SIArray_ContainsType(arr, T_DOUBLE);
198 TEST_ASSERT(contains_double);
199
200 bool contains_string = SIArray_ContainsType(arr, T_STRING);
201 TEST_ASSERT(!contains_string);
202
203 // Checking for multiple types should return true if any match is found
204 bool contains = SIArray_ContainsType(arr, (SIType)(T_DOUBLE | T_STRING));
205 TEST_ASSERT(contains);
206
207 SIValue_Free(nestedArr);
208 SIValue_Free(arr);
209 SIValue_Free(arrOther);
210}
211
212// test for difference in hash code for the same binary representation
213// for different types. The value boolean "true" and the integer value "1"

Callers

nothing calls this directly

Calls 7

SI_EmptyArrayFunction · 0.85
SIValue_HashCodeFunction · 0.85
SIArray_AppendFunction · 0.85
SI_LongValFunction · 0.85
SI_DoubleValFunction · 0.85
SIArray_ContainsTypeFunction · 0.85
SIValue_FreeFunction · 0.85

Tested by

no test coverage detected