void flower_check(Flower *flower) { eventTree_check(flower_getEventTree(flower)); Flower_GroupIterator *groupIterator = flower_getGroupIterator(flower); Group *group; while ((group = flower_getNextGroup(groupIterator)) != NULL) { group_check(group); } flower_destructGroupIterator(groupIterator); Flower_ChainIterator *chainIterator = flower_getChainIterator(flower); Chain *chain; while ((chain = flower_getNextChain(chainIterator)) != NULL) { chain_check(chain); } flower_destructCapIterator(chainIterator); //We check built trees in here. Flower_EndIterator *endIterator = flower_getEndIterator(flower); End *end; while ((end = flower_getNextEnd(endIterator)) != NULL) { end_check(end); end_check(end_getReverse(end)); //We will test everything backwards also. } flower_destructEndIterator(endIterator); if (flower_builtFaces(flower)) { Flower_FaceIterator *faceIterator = flower_getFaceIterator(flower); Face *face; while ((face = flower_getNextFace(faceIterator)) != NULL) { face_check(face); } flower_destructFaceIterator(faceIterator); face_checkFaces(flower); } else { cactusCheck(flower_getFaceNumber(flower) == 0); } if (flower_builtBlocks(flower)) { //Note that a flower for which the blocks are not yet built must be a leaf. Flower_BlockIterator *blockIterator = flower_getBlockIterator(flower); Block *block; while ((block = flower_getNextBlock(blockIterator)) != NULL) { block_check(block); block_check(block_getReverse(block)); //We will test everything backwards also. } flower_destructBlockIterator(blockIterator); } else { cactusCheck(flower_isLeaf(flower)); //Defensive cactusCheck(flower_isTerminal(flower)); //Checks that a flower without built blocks is a leaf and does not //contain any blocks. } Flower_SequenceIterator *sequenceIterator = flower_getSequenceIterator(flower); Sequence *sequence; while ((sequence = flower_getNextSequence(sequenceIterator)) != NULL) { sequence_check(sequence); } flower_destructSequenceIterator(sequenceIterator); }
void sequence_check(Sequence *sequence) { Flower *flower = sequence_getFlower(sequence); cactusCheck(flower_getSequence(flower, sequence_getName(sequence)) == sequence); //properly connected to the flower.. Group *parentGroup = flower_getParentGroup(flower); if(parentGroup != NULL) { Flower *parentFlower = group_getFlower(parentGroup); Sequence *parentSequence = flower_getSequence(parentFlower, sequence_getName(sequence)); if(parentSequence != NULL) { cactusCheck(event_getName(sequence_getEvent(sequence)) == event_getName(sequence_getEvent(parentSequence))); } } }
void event_check(Event *event) { EventTree *eventTree = event_getEventTree(event); Event *ancestorEvent = event_getParent(event); //Check event and eventree properly linked cactusCheck(eventTree_getEvent(event_getEventTree(event), event_getName(event)) == event); //Event has parent, unless it is root. if (eventTree_getRootEvent(eventTree) == event) { cactusCheck(ancestorEvent == NULL); } else { //not root, so must have ancestor. cactusCheck(ancestorEvent != NULL); } //Each child event has event as parent. int64_t i = 0; for (i = 0; i < event_getChildNumber(event); i++) { Event *childEvent = event_getChild(event, i); cactusCheck(event_getParent(childEvent) == event); } //Ancestor-event --> event edge is consistent with any event tree that is in the parent of the containing flower. Group *parentGroup = flower_getParentGroup(eventTree_getFlower( event_getEventTree(event))); if (parentGroup != NULL) { EventTree *parentEventTree = flower_getEventTree(group_getFlower( parentGroup)); Event *parentEvent = eventTree_getEvent(parentEventTree, event_getName( event)); if (parentEvent != NULL) { if (ancestorEvent == NULL) { //the case where they are both root. cactusCheck(eventTree_getRootEvent(parentEventTree) == parentEvent); } else { //Check edge ancestorEvent --> event is in parent event tree. while (1) { Event *parentAncestorEvent = eventTree_getEvent( parentEventTree, event_getName(ancestorEvent)); if (parentAncestorEvent != NULL) { cactusCheck(event_isAncestor(parentEvent, parentAncestorEvent)); break; } ancestorEvent = event_getParent(ancestorEvent); cactusCheck(ancestorEvent != NULL); } } } } }
void block_check(Block *block) { //Check is connected to flower properly cactusCheck(flower_getBlock(block_getFlower(block), block_getName(block)) == block_getPositiveOrientation(block)); //Check we have actually set built blocks for the flower.. cactusCheck(flower_builtBlocks(block_getFlower(block))); //Checks the two ends are block ends. End *_5End = block_get5End(block); End *_3End = block_get3End(block); cactusCheck(end_isBlockEnd(_5End)); cactusCheck(end_isBlockEnd(_3End)); cactusCheck(end_getOrientation(_5End) == block_getOrientation(block)); cactusCheck(end_getOrientation(_3End) == block_getOrientation(block)); cactusCheck(end_getBlock(_5End) == block); cactusCheck(end_getBlock(_3End) == block); cactusCheck(end_getSide(_5End)); //Check the sides of the ends are consistent. cactusCheck(!end_getSide(_3End)); cactusCheck(block_getLength(block) > 0); //check block has non-zero length //Check reverse Block *rBlock = block_getReverse(block); cactusCheck(rBlock != NULL); cactusCheck(block_getReverse(block) == rBlock); cactusCheck(block_getOrientation(block) == !block_getOrientation(rBlock)); cactusCheck(block_getLength(block) == block_getLength(rBlock)); cactusCheck(block_get5End(block) == end_getReverse(block_get3End(rBlock))); cactusCheck(block_get3End(block) == end_getReverse(block_get5End(rBlock))); cactusCheck(block_getInstanceNumber(block) == block_getInstanceNumber(rBlock)); if(block_getInstanceNumber(block) > 0) { cactusCheck(block_getFirst(block) == segment_getReverse(block_getFirst(rBlock))); if(block_getRootInstance(block) == NULL) { cactusCheck(block_getRootInstance(rBlock) == NULL); } else { cactusCheck(block_getRootInstance(block) == segment_getReverse(block_getRootInstance(rBlock))); } } //For each segment calls segment_check. Block_InstanceIterator *iterator = block_getInstanceIterator(block); Segment *segment; while((segment = block_getNext(iterator)) != NULL) { segment_check(segment); } block_destructInstanceIterator(iterator); }