void test_mapRemove_given_Ali_and_ali_is_in_the_list_of_3_element_in_the_map_and_should_remove_Ali_and_return_it_to_caller(){ Person *Ali = personNew("Ali",25,70.3); Person *Zorro = personNew("Zorro",60,55.4); Person *Kikuri = personNew("Kikuri",48,46.4); Person *person; List *list = listNew(Ali, NULL); list = listAdd(Zorro,list); list = listAdd(Kikuri,list); Map *map = mapNew(5); map->bucket[3] = list; hash_ExpectAndReturn(Kikuri,3); // listDump(list, personDump); person = mapRemove(map , Kikuri ,comparePerson, hash); // listDump(list, personDump); TEST_ASSERT_NULL(person); TEST_ASSERT_NULL(getPersonFromBucket(map->bucket[3])); TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next)); TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next->next)); TEST_ASSERT_EQUAL_Person(Zorro,getPersonFromBucket(((List *)map->bucket[3])->next)); TEST_ASSERT_EQUAL_Person(Ali,getPersonFromBucket(((List *)map->bucket[3])->next->next)); }
// Unregister a peer using its NodeID. static void peermgtDelete(struct s_peermgt *mgt, const struct s_nodeid *nodeid) { int peerid = peermgtGetID(mgt, nodeid); if(peerid > 0) { // don't allow special ID 0 to be deleted. mapRemove(&mgt->map, nodeid->id); peermgtResetID(mgt, peerid); } }
void test_mapRemove_given_Ali_and_ali_is_not_in_the_Map_should_return_NULL_since_no_Ali_object_in_Map2(){ Person *Ali = personNew("Ali",25,70.3); List *list = listNew(Ali, NULL); Map *map = mapNew(5); Person *person; // map->bucket[3] = list; // no add hash_ExpectAndReturn(Ali,3); comparePerson(Ali,Ali); person = mapRemove(map , Ali ,comparePerson, hash); TEST_ASSERT_NULL(map->bucket[3]); TEST_ASSERT_NULL(person); }
//////////////////// // MAP REMOVE // //////////////////// void test_mapRemove_given_Ali_and_ali_is_in_the_Map_should_return_Ali_object1(){ Person *Ali = personNew("Ali",25,70.3); List *list = listNew(Ali, NULL); Map *map = mapNew(5); Person *person; map->bucket[3] = list; hash_ExpectAndReturn(Ali,3); person = mapRemove(map , Ali ,comparePerson, hash); // listDump(list, personDump); TEST_ASSERT_NULL(person); TEST_ASSERT_NULL(getPersonFromBucket(map->bucket[3])); }
void test_mapRemove_given_Ali_and_ali_is_not_in_the_linkedList_in_the_map_should_return_NULL4(){ Person *Ali = personNew("Ali",25,70.3); Person *Zorro = personNew("Zorro",60,55.4); Person *Kikuri = personNew("Kikuri",50,40.4); Person *person; List *list = listNew(Kikuri, NULL); list = listAdd(Zorro,list); Map *map = mapNew(5); map->bucket[3] = list; hash_ExpectAndReturn(Ali,3); // listDump(list, personDump); person = mapRemove(map , Ali ,comparePerson, hash); // listDump(list, personDump); TEST_ASSERT_NULL(person); TEST_ASSERT_NOT_NULL(getPersonFromBucket(map->bucket[3])); }
void test_mapRemove_given_Ali_and_ali_is_in_the_linkedList_in_the_map_should_return_Ali_object3(){ Person *Ali = personNew("Ali",25,70.3); Person *Zorro = personNew("Zorro",60,55.4); Person *person; List *list = listNew(Ali, NULL); list = listAdd(Zorro,list); Map *map = mapNew(5); map->bucket[3] = list; hash_ExpectAndReturn(Zorro,3); // listDump(list, personDump); person = mapRemove(map , Zorro ,comparePerson, hash); // listDump(list, personDump); TEST_ASSERT_NULL(person); TEST_ASSERT_NULL(getPersonFromBucket(map->bucket[3])); TEST_ASSERT_NOT_NULL(getPersonFromBucket(((List *)map->bucket[3])->next)); TEST_ASSERT_EQUAL_Person(Ali,getPersonFromBucket(((List *)map->bucket[3])->next)); }
static int mapStrNRemove(struct s_map *map, const char *str, const int len) { mapStrNPrepKey(map, str, len); return mapRemove(map, key); }