void testGroup_isLink(CuTest *testCase) { cactusGroupTestSetup(); CuAssertTrue(testCase, !group_isLink(group2)); Chain *chain = setupChain(); CuAssertTrue(testCase, group_isLink(group2)); chain_destruct(chain); CuAssertTrue(testCase, !group_isLink(group2)); cactusGroupTestTeardown(); }
bool flower_removeIfRedundant(Flower *flower) { if (!flower_isLeaf(flower) && flower_getParentGroup(flower) != NULL && flower_getBlockNumber(flower) == 0) { //We will remove this flower.. Group *parentGroup = flower_getParentGroup(flower); //This group will be destructed //Deal with any parent chain.. if (group_isLink(parentGroup)) { link_split(group_getLink(parentGroup)); } Flower *parentFlower = group_getFlower(parentGroup); //We will add the groups in the flower to the parent /* * For each group in the flower we take its nested flower and attach it to the parent. */ Group *group; Flower_GroupIterator *groupIt = flower_getGroupIterator(flower); while ((group = flower_getNextGroup(groupIt)) != NULL) { if (!group_isLeaf(group)) { //Copy the group into the parent.. Flower *nestedFlower = group_getNestedFlower(group); assert(nestedFlower != NULL); Group *newParentGroup = group_construct(parentFlower, nestedFlower); flower_setParentGroup(nestedFlower, newParentGroup); group_constructChainForLink(newParentGroup); } else { Group *newParentGroup = group_construct2(parentFlower); End *end; Group_EndIterator *endIt = group_getEndIterator(group); while ((end = group_getNextEnd(endIt)) != NULL) { End *parentEnd = flower_getEnd(parentFlower, end_getName(end)); assert(parentEnd != NULL); end_setGroup(parentEnd, newParentGroup); } group_destructEndIterator(endIt); group_constructChainForLink(newParentGroup); } } flower_destructGroupIterator(groupIt); //The group attached to the flower should now be empty assert(group_getEndNumber(parentGroup) == 0); group_destruct(parentGroup); //Now wipe the flower out.. cactusDisk_deleteFlowerFromDisk(flower_getCactusDisk(flower), flower); flower_destruct(flower, 0); return 1; } return 0; }
void testGroup_constructChainForLink(CuTest *testCase) { cactusGroupTestSetup(); //Create a link group and test function works! Group *group3 = group_construct2(flower); End *_5End = end_construct2(1, 1, flower); End *_3End = end_construct2(0, 1, flower); End *stubEnd = end_construct2(1, 0, flower); end_setGroup(_5End, group3); end_setGroup(_3End, group3); end_setGroup(stubEnd, group3); CuAssertTrue(testCase, group_isTangle(group3)); CuAssertTrue(testCase, group_getEndNumber(group3) == 3); group_constructChainForLink(group3); CuAssertTrue(testCase, group_isLink(group3)); Link *link = group_getLink(group3); CuAssertTrue(testCase, link_get5End(link) == _5End); CuAssertTrue(testCase, link_get3End(link) == _3End); cactusGroupTestTeardown(); }