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

Function test_set

tests/unit/test_value.c:256–342  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

254}
255
256void test_set() {
257 set *set = Set_New();
258
259 // Set should be empty.
260 TEST_ASSERT(Set_Size(set) == 0);
261
262 // Populate set.
263 Node n;
264 Edge e;
265 AttributeSet attr;
266 n.id = 0;
267 n.attributes = &attr;
268 e.id = 0;
269 e.attributes = &attr;
270 SIValue arr = SI_Array(2);
271
272 Set_Add(set, arr);
273 Set_Add(set, SI_Node(&n));
274 Set_Add(set, SI_Edge(&e));
275 Set_Add(set, SI_NullVal());
276 Set_Add(set, SI_LongVal(0));
277 Set_Add(set, SI_DoubleVal(1));
278 Set_Add(set, SI_BoolVal(true));
279
280 TEST_ASSERT(Set_Size(set) == 7);
281
282 // Make sure all items are in set.
283 TEST_ASSERT(Set_Contains(set, arr));
284 TEST_ASSERT(Set_Contains(set, SI_Node(&n)));
285 TEST_ASSERT(Set_Contains(set, SI_Edge(&e)));
286 TEST_ASSERT(Set_Contains(set, SI_NullVal()));
287 TEST_ASSERT(Set_Contains(set, SI_LongVal(0)));
288 TEST_ASSERT(Set_Contains(set, SI_DoubleVal(1)));
289 TEST_ASSERT(Set_Contains(set, SI_BoolVal(true)));
290
291 // Test for none existing items.
292 TEST_ASSERT(!Set_Contains(set, SI_BoolVal(false)));
293 TEST_ASSERT(!Set_Contains(set, SI_LongVal(2)));
294 TEST_ASSERT(!Set_Contains(set, SI_DoubleVal(3)));
295
296 // Try to introduce duplicates.
297 Set_Add(set, arr);
298 Set_Add(set, SI_Node(&n));
299 Set_Add(set, SI_Edge(&e));
300 Set_Add(set, SI_NullVal());
301 Set_Add(set, SI_LongVal(0));
302 Set_Add(set, SI_DoubleVal(1));
303 Set_Add(set, SI_BoolVal(true));
304
305 // Set item count shouldn't change.
306 uint64_t set_size = Set_Size(set);
307 TEST_ASSERT(set_size == 7);
308
309 // Remove items from set.
310 Set_Remove(set, arr);
311 TEST_ASSERT(!Set_Contains(set, arr));
312 TEST_ASSERT(Set_Size(set) == --set_size);
313

Callers

nothing calls this directly

Calls 14

Set_NewFunction · 0.85
Set_SizeFunction · 0.85
SI_ArrayFunction · 0.85
Set_AddFunction · 0.85
SI_NodeFunction · 0.85
SI_EdgeFunction · 0.85
SI_NullValFunction · 0.85
SI_LongValFunction · 0.85
SI_DoubleValFunction · 0.85
SI_BoolValFunction · 0.85
Set_ContainsFunction · 0.85
Set_RemoveFunction · 0.85

Tested by

no test coverage detected